diff options
author | Anton Luka Šijanec <anton@sijanec.eu> | 2023-12-02 01:36:42 +0100 |
---|---|---|
committer | Anton Luka Šijanec <anton@sijanec.eu> | 2023-12-02 01:36:42 +0100 |
commit | 47bb6f7e183868d7af8e28db15ce2f2a219b408c (patch) | |
tree | cb8386bbb693753477982acdf4bb8cbcba32ba83 | |
parent | ana1 začetki (diff) | |
download | r-47bb6f7e183868d7af8e28db15ce2f2a219b408c.tar r-47bb6f7e183868d7af8e28db15ce2f2a219b408c.tar.gz r-47bb6f7e183868d7af8e28db15ce2f2a219b408c.tar.bz2 r-47bb6f7e183868d7af8e28db15ce2f2a219b408c.tar.lz r-47bb6f7e183868d7af8e28db15ce2f2a219b408c.tar.xz r-47bb6f7e183868d7af8e28db15ce2f2a219b408c.tar.zst r-47bb6f7e183868d7af8e28db15ce2f2a219b408c.zip |
-rw-r--r-- | prog/aoc/23/1/1.c | 21 | ||||
-rwxr-xr-x | prog/aoc/23/1/2.sh | 13 | ||||
-rw-r--r-- | prog/aoc/23/1/in.txt | 7 |
3 files changed, 41 insertions, 0 deletions
diff --git a/prog/aoc/23/1/1.c b/prog/aoc/23/1/1.c new file mode 100644 index 0000000..ce0f01f --- /dev/null +++ b/prog/aoc/23/1/1.c @@ -0,0 +1,21 @@ +#include <stdio.h> +#include <stdlib.h> +int main (void) { + int c = getchar(); + int prev = -1; + int sum = 0; + while (!ferror(stdin) && !feof(stdin)) { + if (c == '\n') { + sum += prev; + prev = -1; + } + if (c <= '9' && c >= '0') { + if (prev == -1) + sum += 10*(c-'0'); + prev = c-'0'; + } + c = getchar(); + + } + printf("%d\n", sum); +} diff --git a/prog/aoc/23/1/2.sh b/prog/aoc/23/1/2.sh new file mode 100755 index 0000000..f9fd95c --- /dev/null +++ b/prog/aoc/23/1/2.sh @@ -0,0 +1,13 @@ +function s () { + sed -e "s/\($1\)/\1$2\1/g" +} +s zero 0 |\ +s one 1 |\ +s two 2 |\ +s three 3 |\ +s four 4 |\ +s five 5 |\ +s six 6 |\ +s seven 7 |\ +s eight 8 |\ +s nine 9 diff --git a/prog/aoc/23/1/in.txt b/prog/aoc/23/1/in.txt new file mode 100644 index 0000000..41aa89c --- /dev/null +++ b/prog/aoc/23/1/in.txt @@ -0,0 +1,7 @@ +two1nine +eightwothree +abcone2threexyz +xtwone3four +4nineeightseven2 +zoneight234 +7pqrstsixteen |