File tree Expand file tree Collapse file tree 2 files changed +165
-0
lines changed
kotlin/dev/manka/advent_of_code/days/y2022 Expand file tree Collapse file tree 2 files changed +165
-0
lines changed Original file line number Diff line number Diff line change 1+ package dev.manka.advent_of_code.days.y2022
2+
3+ import dev.manka.advent_of_code.days.Day
4+ import kotlin.math.pow
5+
6+ class Day25 :Day (25 , " Full of Hot Air" , 2022 ) {
7+ override fun partOne (): String {
8+ val sumOfNumbers = inputList.sumOf { toDecimalNumber(it) }
9+ return toSnafu(sumOfNumbers)
10+ }
11+
12+ private fun toDecimalNumber (snafu : String ) : Long {
13+ return snafu.map { when (it){
14+ ' 2' -> 2
15+ ' 1' -> 1
16+ ' -' -> - 1
17+ ' =' -> - 2
18+ else -> 0
19+ } }.reversed()
20+ .foldIndexed(0L ){ index, acc, digit -> acc + (digit * (5.0 .pow(index).toLong())) }
21+ }
22+ private fun toSnafu (number : Long ) : String {
23+ var caryOver= 0
24+ return number.toString(5 ).map{it.digitToInt()}.reversed().fold(" " ) { acc, digit ->
25+ val sum = digit + caryOver
26+ caryOver = sum / 3
27+ when (sum % 5 ) {
28+ 4 -> " -"
29+ 3 -> " ="
30+ 2 -> " 2"
31+ 1 -> " 1"
32+ 0 -> " 0"
33+ else -> throw IllegalStateException (" Should not happen" )
34+ } + acc
35+ }
36+ }
37+
38+ override fun partTwo (): String {
39+ return " Not implemented yet"
40+ }
41+
42+
43+ }
Original file line number Diff line number Diff line change 1+ 1-11=21=22-0=22
2+ 12-0-2022-=1
3+ 11101-0---0=-1
4+ 2-
5+ 20
6+ 1-=2=-021=21211-1-01
7+ 1==0122002210-00
8+ 2=2122011=-=020-=0
9+ 2--0
10+ 1=1--=2
11+ 1-0
12+ 22==020-
13+ 1=1=1
14+ 221-2201=--
15+ 2=
16+ 1=21101=--1=1=-
17+ 112=-1
18+ 1---21-0-00==-=00=0
19+ 1-022-0=1
20+ 2=12=20
21+ 1222-000=-01-02
22+ 222=0
23+ 1010=21-01-20
24+ 1=1=2220210=11-210
25+ 1--2=1=0=00--0=
26+ 2102-1-==2-==-0
27+ 211=-==00
28+ 2=--=-1-=10=-2-21-
29+ 10-2=1-1
30+ 1=22-2=-0-1-101
31+ 102-00=0-1=1=022
32+ 11-=--
33+ 1=222
34+ 1==1--2210-=
35+ 22-01-1=-1010120
36+ 2==2-2=0-2--2
37+ 101
38+ 2-22-=20121
39+ 20-0=22
40+ 1-10020
41+ 1-==01
42+ 1-111-010=
43+ 1-
44+ 1022021=10210
45+ 2=102===1-0112
46+ 1--0-120=21-
47+ 101-2-0102-=10==22
48+ 11011=-12=1
49+ 1=22=-11=-002=1
50+ 1=-0=21102=0-=-
51+ 1=1=2--=2
52+ 21=12112
53+ 1111
54+ 2=2=-10201=-12
55+ 10--1=2-=012010=0
56+ 102=-=-1-
57+ 21
58+ 1-0-=-21221=11
59+ 1=1-=-1112=2
60+ 22
61+ 1=
62+ 1-=212-0
63+ 12-=200--1=11
64+ 10-=100=221=1-10=
65+ 2-2-02--0-0-1-0-02
66+ 10-011--20=0
67+ 1--10211--=
68+ 1--1=-=
69+ 1-2=0012==1=2
70+ 22-20=212
71+ 1=100-
72+ 12=001211
73+ 222012
74+ 2-21-=-01---212
75+ 11=002=-0=2022020
76+ 10==1=-=202
77+ 1====0020=2000001=
78+ 1=1--=0=2=2--2
79+ 222=2-1-002
80+ 2--====-00--2=02=0
81+ 1-==21111-11-
82+ 2211=1==0221
83+ 2=0002--
84+ 200-
85+ 1-1=1=-110==0
86+ 1-0-
87+ 22001=-01=1-
88+ 1--221===2-221212
89+ 1=2-
90+ 1=1
91+ 1=2==-0=10=02211=-
92+ 10=--0-212-
93+ 1-0=
94+ 11-=-=11=22=00=
95+ 11---
96+ 110201110-
97+ 2-0=-
98+ 2=12=12----121-0-
99+ 1==120==012220=-
100+ 1=00-0
101+ 102-=-2
102+ 122
103+ 20020
104+ 1=---1-1==0=1=
105+ 22=1110-=02-
106+ 120=20=020=0-=-11-
107+ 1-2-0
108+ 21=2==0-11==---2--0
109+ 112=
110+ 12222=20-000
111+ 1=110
112+ 2222=10-
113+ 1-2
114+ 111211-=
115+ 2=2=1--2220==2=02
116+ 111022=21100100121
117+ 20--==2-21=1
118+ 1000=-1=2202
119+ 21==--==11-1==0-=
120+ 1=0-2=21-1=2==2
121+ 111
122+ 21-0=11-2-220=-=
You can’t perform that action at this time.
0 commit comments