From 6b991ae9dae2e6f91b94964674ab4c564ccf51f9 Mon Sep 17 00:00:00 2001 From: Adam Spragg Date: Sun, 15 Jan 2023 10:43:17 +0000 Subject: Puzzle 5: Add `-p` option to choose part 1/2 solution Like the later puzzles --- 5.c | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/5.c b/5.c index 993c555..df7c8bd 100644 --- a/5.c +++ b/5.c @@ -119,8 +119,24 @@ main(int argc, char ** argv) struct crate ** stack = NULL; regex_t movecmd; - while ((i = getopt(argc, argv, "m:")) != -1) { + while ((i = getopt(argc, argv, "p:m:")) != -1) { switch (i) { + case 'p': + switch (atoi(optarg)) { + case 1: + crates_move = crates_move_9000; + break; + + case 2: + crates_move = crates_move_9001; + break; + + default: + fprintf(stderr, "Unexpected puzzle part %s\n", optarg); + return -1; + } + break; + case 'm': if (strcmp(optarg, "9000") == 0) crates_move = crates_move_9000; -- cgit v1.2.1