diff options
author | Adam Spragg <adam@spra.gg> | 2023-01-14 17:57:58 +0000 |
---|---|---|
committer | Adam Spragg <adam@spra.gg> | 2023-01-14 17:57:58 +0000 |
commit | 2b922997fb893a5bc14f157ad5db27ae77cec6a6 (patch) | |
tree | dc40826bd32e807ea1a04cd376c6067ec41b94a7 /2a.c | |
parent | a09348694b0525513d812647a69dac3a36782f88 (diff) |
Puzzle 2: Consolidate 2a/2b programs into `2` with `-p` option
Like the later puzzles
Diffstat (limited to '2a.c')
-rw-r--r-- | 2a.c | 78 |
1 files changed, 0 insertions, 78 deletions
@@ -1,78 +0,0 @@ - -#include <stdio.h> -#include <string.h> - - -enum RPS { - ROCK, - PAPR, - SCRS, -}; - - -enum RPS -rps_beats(enum RPS rps) -{ - switch (rps) { - case ROCK: return SCRS; - case PAPR: return ROCK; - case SCRS: return PAPR; - } - return -1; -} - - -int -rps_pickscore(enum RPS rps) -{ - switch (rps) { - case ROCK: return 1; - case PAPR: return 2; - case SCRS: return 3; - } - return 0; -} - - -int -rps_gamescore_b(enum RPS a, enum RPS b) -{ - if (b == a) - return 3; - if (rps_beats(b) == a) - return 6; - return 0; -} - - -int -main() -{ - char buf[BUFSIZ]; - int score = 0; - - while (fgets(buf, sizeof(buf), stdin)) { - enum RPS a, b; - - if (strlen(buf) != 4) - break; - switch (buf[0]) { - case 'A': a = ROCK; break; - case 'B': a = PAPR; break; - case 'C': a = SCRS; break; - default: return 1; - } - switch (buf[2]) { - case 'X': b = ROCK; break; - case 'Y': b = PAPR; break; - case 'Z': b = SCRS; break; - default: return 1; - } - score += rps_pickscore(b) + rps_gamescore_b(a, b); - } - - printf("Score: %d\n", score); - - return 0; -} - |