Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 6b11e5f

Browse files
Year 2022 Day 25
1 parent c1b7129 commit 6b11e5f

File tree

4 files changed

+163
-1
lines changed

4 files changed

+163
-1
lines changed

‎README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# Advent of Code
22

3-
In progress 2022 and complete 2021 to 2015 entries for the annual [Advent of Code](https://adventofcode.com/) challenge, written in concise idiomatic functional Scala.
3+
Complete 2022 to 2015 entries for the annual [Advent of Code](https://adventofcode.com/) challenge, written in concise idiomatic functional Scala.
44

55
The coding style philosophy is [Readability](https://www.lihaoyi.com/post/StrategicScalaStylePrincipleofLeastPower.html) > [Simplicity](https://en.wikipedia.org/wiki/KISS_principle) > [Performance](https://www.laws-of-software.com/laws/knuth/).
66

@@ -55,6 +55,7 @@ The minimal SBT project provides:
5555
| 22 | [Monkey Map](https://adventofcode.com/2022/day/22) | [Source](src/main/scala/AdventOfCode2022/Day22.scala) |
5656
| 23 | [Unstable Diffusion](https://adventofcode.com/2022/day/23) | [Source](src/main/scala/AdventOfCode2022/Day23.scala) |
5757
| 24 | [Blizzard Basin](https://adventofcode.com/2022/day/24) | [Source](src/main/scala/AdventOfCode2022/Day24.scala) |
58+
| 25 | [Full of Hot Air](https://adventofcode.com/2022/day/25) | [Source](src/main/scala/AdventOfCode2022/Day25.scala) |
5859

5960
## 2021
6061

Lines changed: 111 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,111 @@
1+
1=021=20-ひく-ひく-ひく11-ひく1=1
2+
222==-ひく=1-ひく2=-ひく11-ひく11
3+
1010==0=0=1--=1
4+
2
5+
1122=
6+
2222==2222-2--10
7+
100=-2-002=
8+
12221-2-10-=1=
9+
1-=211000=221-1
10+
2=-ひく-ひく12==11221-ひく2-ひく002
11+
1101==-01===01=
12+
220=0=-ひく2-ひく1-ひく0===10=2
13+
2-0-
14+
1=-12=2==
15+
1-=-02==-1
16+
100-0-11--02--0=-
17+
1==0-1220011=-
18+
21
19+
1102-22==
20+
222
21+
1==0=22-0--011-0
22+
1020
23+
2==2-102
24+
1010-02==02=
25+
1=1
26+
2=010==12022=
27+
1=-22001-2=
28+
101=2-201122111
29+
1=-ひく0021211-ひく1-ひく1-ひく1202
30+
2-22-2
31+
1212002==1
32+
2=-0-
33+
1-1==1122110100
34+
1--020-2-=-0-21--
35+
2=22-21220022==1=
36+
1=-ひく00-ひく121-ひく20-ひく2122
37+
1-==-00
38+
20=21=0
39+
20-02-0-=-==-=22
40+
1120==-2
41+
2=-ひく-ひく0-ひく0-ひく000201=101
42+
1---=02=21
43+
1-011
44+
211-2112=20--2
45+
1=-
46+
1=--=021
47+
1-ひく1-ひく122200==1-ひく1111
48+
11001-
49+
200=200
50+
1===21=1-2
51+
1===10
52+
2=22
53+
10-110210=01112-
54+
2121=1=2=-201-
55+
1---2=-0=-
56+
211-120---000=-0-
57+
1-
58+
1-101-2=01020=-0=
59+
112-12--0=12=12--
60+
1-0-=2--=--12=20
61+
1=0=-121
62+
1000122-210--011200
63+
120==-1-=01
64+
1=2=1--
65+
101-1=--2-
66+
2=
67+
2--10
68+
2201020-=2-
69+
1===2001-1=0=
70+
222=-2---2=112
71+
2010=-22=012=202=
72+
111
73+
1-2112=0200=1
74+
2=02211=2
75+
2-121
76+
1----12=-2011
77+
2==0
78+
112
79+
22=0==1-1=
80+
1-20=0-
81+
1=110211-ひく022201222
82+
20
83+
1-111
84+
1=-=022011=2=2=1
85+
1-02122
86+
2-1
87+
1-2-=2-0=0---
88+
1-20
89+
1=1=102
90+
1=1=0--1
91+
11222-==0101-
92+
2122100=0
93+
2011==12-10
94+
210--121-0=
95+
22121=01=0=-=-=-==
96+
10-0-=1-12
97+
2-2=21
98+
1=1-0-0-
99+
10020
100+
10-0-0120=211-2-
101+
1-ひく==10-ひく0-ひく==001201-
102+
1-0
103+
21=00202002-0
104+
1-1=2021
105+
11=1==1=0
106+
1=102-1=-20-0
107+
2=100-12-0=
108+
1=0
109+
1--=
110+
12=212110200-
111+
222002100
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
package AdventOfCode2022
2+
3+
object Day25:
4+
def fromSnafu(s: String): Long = s.foldLeft(0L) { (total, c) =>
5+
val digit = c match
6+
case '0' => 0
7+
case '1' => 1
8+
case '2' => 2
9+
case '=' => -2
10+
case '-' => -1
11+
5 * total + digit
12+
}
13+
14+
def toSnafu(i: Long, s: String = ""): String = if i == 0 then s else
15+
val (digit, prefix) = i % 5 match
16+
case 0 => (0, "0")
17+
case 1 => (1, "1")
18+
case 2 => (2, "2")
19+
case 3 => (-2, "=")
20+
case 4 => (-1, "-")
21+
toSnafu((i - digit) / 5, prefix + s)
22+
23+
def part1(input: Seq[String]): String = toSnafu(input.map(fromSnafu).sum)
24+
25+
def main(args: Array[String]): Unit =
26+
val data = io.Source.fromResource("AdventOfCode2022/Day25.txt").getLines().toSeq
27+
println(part1(data))
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
package AdventOfCode2022
2+
3+
import org.scalatest.funsuite.AnyFunSuite
4+
5+
class Day25Suite extends AnyFunSuite:
6+
val sample = Seq(
7+
"1=-0-2",
8+
"12111",
9+
"2=0=",
10+
"21",
11+
"2=01",
12+
"111",
13+
"20012",
14+
"112",
15+
"1=-1=",
16+
"1-12",
17+
"12",
18+
"1=",
19+
"122")
20+
21+
test("Part 1 should handle sample input correctly") {
22+
assert(Day25.part1(sample) == "2=-1=0")
23+
}

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /