adventofcode

git clone https://git.ce9e.org/adventofcode.git

commit
5ccb3268ba7900cd9fb4f1151fc494ce69fe232f
parent
216f857e28a885401fd3a7f72b4995efcc4a4e03
Author
Tobias Bengfort <tobias.bengfort@posteo.de>
Date
2022-12-28 10:00
2022-12-25

Diffstat

A 2022/25/input.txt 118 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
A 2022/25/solution.rs 48 ++++++++++++++++++++++++++++++++++++++++++++++++
A 2022/25/test.txt 13 +++++++++++++

3 files changed, 179 insertions, 0 deletions


diff --git a/2022/25/input.txt b/2022/25/input.txt

@@ -0,0 +1,118 @@
   -1     1 121=0=-
   -1     2 1==02020022=
   -1     3 1==2==20--2==
   -1     4 1-11-
   -1     5 1==02=2=02=-1-00-=0
   -1     6 1011=-=--00
   -1     7 22-1-1=0--0=
   -1     8 1-=121-00=
   -1     9 1=1=-=10====10
   -1    10 1=-=-21002-2=--
   -1    11 211-2=2=-
   -1    12 1=-1=10
   -1    13 11221
   -1    14 2-21-20
   -1    15 1-0-
   -1    16 12221=0-0-1=
   -1    17 101-022121111-
   -1    18 11=01-==0211
   -1    19 1-2-00-=--11
   -1    20 1=-12=-=-2=1==02
   -1    21 1=-0111===202
   -1    22 20011
   -1    23 2=22
   -1    24 1=2=12-===-=
   -1    25 202=-2201=-2=
   -1    26 2=-0221
   -1    27 10=20-=2=--
   -1    28 1=01202=
   -1    29 202
   -1    30 12211=222=
   -1    31 2=1=1-0211-=0=
   -1    32 1-10
   -1    33 112=211112
   -1    34 11==-100-
   -1    35 1=21220=-122--2-2-
   -1    36 11-220
   -1    37 122=1110220==1
   -1    38 1=1-2210-21-=120102
   -1    39 1=0202=1=
   -1    40 11=2100==2-21121
   -1    41 2-21-=
   -1    42 2=00210-
   -1    43 1==--2
   -1    44 1-
   -1    45 1==
   -1    46 1220-1=22-=
   -1    47 1=1-==21021-=10
   -1    48 2=02=02000==1-
   -1    49 1--210-0-0
   -1    50 12-200==1=0-2=-0-
   -1    51 12110-020-2-1--
   -1    52 1-2
   -1    53 20=2=--12=120
   -1    54 112=20201
   -1    55 1=021-0-=2---
   -1    56 21202--1=-1=2--
   -1    57 101=
   -1    58 22=0---=-
   -1    59 21
   -1    60 10-1020
   -1    61 12=2-==-0-=12=000=
   -1    62 1-212-
   -1    63 200=1--0120=2==201
   -1    64 200-
   -1    65 2=0
   -1    66 1-1=1110211
   -1    67 1---1==2
   -1    68 1-2122==10--=0=10
   -1    69 1=0-0-2-=01-=220
   -1    70 2-0==00001002-=
   -1    71 1-0--0001-2=0=0-
   -1    72 1-02--01=-1
   -1    73 1=101121=0110021-
   -1    74 22-22===0-2
   -1    75 1=-0-----202=212201
   -1    76 120-00--10-=202=
   -1    77 1=00==
   -1    78 111022--0012=
   -1    79 11-2-0=01-=-02
   -1    80 1-011=-2
   -1    81 2=021-=--1
   -1    82 1--212000-2
   -1    83 1=-000-
   -1    84 1-=-==0
   -1    85 20=0012110
   -1    86 12=21-1-0
   -1    87 1=0021=1010=0=2
   -1    88 11-0-==01002
   -1    89 1102-20=-
   -1    90 102
   -1    91 12122
   -1    92 1-100121=
   -1    93 12=-1==20=20=20222
   -1    94 1-=-00--0--1-
   -1    95 1===-22-2201=01-=-2
   -1    96 1==0-11--==2=21=1-=1
   -1    97 20=0=20-110-1201-=2
   -1    98 112
   -1    99 22=-
   -1   100 2=2-2021
   -1   101 11100=
   -1   102 211-
   -1   103 10000==10-000--0
   -1   104 12
   -1   105 1-1---1=111=
   -1   106 11=-=102===-1-1=-
   -1   107 20210-2-2-==11
   -1   108 1012
   -1   109 1-0=-121==-0
   -1   110 1===0-0=-0=-=210
   -1   111 12--1-2---021=-=
   -1   112 1000
   -1   113 2-2011-
   -1   114 1--201001=002
   -1   115 2--
   -1   116 1---102=2=10110
   -1   117 1=0=2=011-=
   -1   118 12=--2-=1-0

diff --git a/2022/25/solution.rs b/2022/25/solution.rs

@@ -0,0 +1,48 @@
   -1     1 #[path = "../lib.rs"] mod lib;
   -1     2 
   -1     3 fn int_to_snafu(i: u64) -> String {
   -1     4     let mut rest = i;
   -1     5     let mut s = String::new();
   -1     6 
   -1     7     while rest != 0 {
   -1     8         let (c, carry) = match rest % 5 {
   -1     9             2 => ('2', false),
   -1    10             1 => ('1', false),
   -1    11             0 => ('0', false),
   -1    12             4 => ('-', true),
   -1    13             3 => ('=', true),
   -1    14             _ => unreachable!(),
   -1    15         };
   -1    16         if carry {
   -1    17             rest += 5;
   -1    18         }
   -1    19         rest /= 5;
   -1    20         s.insert(0, c);
   -1    21     }
   -1    22 
   -1    23     return s;
   -1    24 }
   -1    25 
   -1    26 fn snafu_to_int(s: String) -> u64 {
   -1    27     let mut i: i64 = 0;
   -1    28     for c in s.chars() {
   -1    29         i *= 5;
   -1    30         i += match c {
   -1    31             '2' => 2,
   -1    32             '1' => 1,
   -1    33             '0' => 0,
   -1    34             '-' => -1,
   -1    35             '=' => -2,
   -1    36             _ => unreachable!(),
   -1    37         }
   -1    38     }
   -1    39     return i as u64;
   -1    40 }
   -1    41 
   -1    42 fn main() {
   -1    43     let sum = lib::iter_input()
   -1    44         .map(|line| snafu_to_int(line.to_string()))
   -1    45         .sum();
   -1    46     println!("part1: {}", sum);
   -1    47     println!("part1: {}", int_to_snafu(sum));
   -1    48 }

diff --git a/2022/25/test.txt b/2022/25/test.txt

@@ -0,0 +1,13 @@
   -1     1 1=-0-2
   -1     2 12111
   -1     3 2=0=
   -1     4 21
   -1     5 2=01
   -1     6 111
   -1     7 20012
   -1     8 112
   -1     9 1=-1=
   -1    10 1-12
   -1    11 12
   -1    12 1=
   -1    13 122