Skip to content

Commit 4c8626c

Browse files
committed
2022 day 25
1 parent 3ec5443 commit 4c8626c

File tree

4 files changed

+171
-0
lines changed

4 files changed

+171
-0
lines changed
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
//: [Previous](@previous)
2+
3+
import Foundation
4+
5+
part1()
6+
7+
//: [Next](@next)
Lines changed: 125 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,125 @@
1+
1100-
2+
11-1=12012=
3+
111==2=-022=01
4+
20---
5+
1=01=20
6+
2=2=2=-21-=
7+
1021-02=10==-
8+
1-22=12001-0=222011
9+
1=1-1
10+
2-2=
11+
211=211=22-=0=10
12+
111-111=212--01
13+
10-2-121
14+
10=-210000
15+
12=
16+
1==2-22--==01-20-0
17+
1-1==120
18+
201=120100=1
19+
1==2111=1=
20+
1--0-=-01
21+
2
22+
2=2
23+
1=-=0==010-=--021
24+
1=-2-=1-2=00122-10
25+
210--21--
26+
112
27+
1=0-22-10-2=1==0
28+
12-12
29+
1==01-=-
30+
1-1
31+
1=1
32+
11=20102-001=0=-20
33+
11=11==10
34+
22210=-=
35+
12001=-0
36+
1=-00122200=
37+
20==-00=2=201=-=
38+
1-21101021-====-
39+
2-2=2=0=1122
40+
10=2
41+
1-02-10
42+
21220--=-01--1-1
43+
1==02-02
44+
221-=0
45+
110
46+
2=122-
47+
21-0=1=-
48+
20
49+
2---2-2-01-1=1110
50+
2-11-211
51+
12-110022-
52+
10101-20-
53+
211-2211-10-2002
54+
2--22==1=1122=-0000
55+
1=0
56+
10-
57+
20===21=00222==1
58+
21-110-11=1
59+
12--1=02-121
60+
1101=00--2==0
61+
11=0-1
62+
10101-1=21-1121100
63+
1=1010=-222-
64+
22=2200---2=2-02-=2
65+
20=1021=2--2---=
66+
10=20112
67+
1-0-10-
68+
1002002=-==0
69+
220-110
70+
1=--=21
71+
10--0
72+
122==2-1-
73+
1-2=100-0-=101
74+
2=1
75+
21=0=111=11=000=-2
76+
12121=0
77+
1-210-0=
78+
2-1=111=20-1-2-
79+
1012-2-02=
80+
1121=2=1==
81+
1=101-
82+
1-21110
83+
1=2011-0-
84+
1==0
85+
1-==2==12011-
86+
11-2=121==
87+
20-121002=021==111
88+
22220-2-02=22=
89+
221101
90+
22-=20=02-0-1=-11
91+
1-=01=010-1-1101-0
92+
1-1-=0==0=010
93+
1-212211-=02-11=-
94+
1=01=
95+
2000=10=-122=00
96+
1=1=21-=-
97+
1-=011=--2-2=12
98+
2000000=2212-00
99+
22120-11-1-0-=-2
100+
112=1---21-0111
101+
12112220=110
102+
121=0011-=1-0
103+
222=-=02121
104+
2-000010221=
105+
1=0221=1==-=2010
106+
1102====
107+
210=1-02-=1102
108+
2=-=-201102012
109+
2-=21-=0=1
110+
11022-00-2=1210
111+
1120-0-1012001
112+
2-
113+
10==0--0-020110
114+
1-=02122-0=0=
115+
1=10=2002=120=1-1=
116+
1-=11
117+
1-11201102-
118+
2-==11102-101
119+
10
120+
2-=2=
121+
2==0-
122+
111=--12=2
123+
1=201
124+
11200-1==2=001=--2
125+
10---10--=0-2202=1
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
import Foundation
2+
3+
4+
public func part1() -> String {
5+
var total = 0
6+
let value: [Character: Int] = [
7+
"=": -2,
8+
"-": -1,
9+
"0": 0,
10+
"1": 1,
11+
"2": 2,
12+
]
13+
for line in stringsFromFile() where line != "" {
14+
var number = 0
15+
for ch in line {
16+
number *= 5
17+
number += value[ch]!
18+
}
19+
total += number
20+
}
21+
let digit: [Int: Character] = [
22+
0: "0",
23+
1: "1",
24+
2: "2",
25+
3: "=",
26+
4: "-"
27+
]
28+
var result = [Character]()
29+
while total > 0 {
30+
let (q, r) = total.quotientAndRemainder(dividingBy: 5)
31+
result.insert(digit[r]!, at: 0)
32+
total = q
33+
if r == 3 || r == 4 {
34+
total += 1
35+
}
36+
}
37+
return String(result)
38+
}

aoc22.playground/contents.xcplayground

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,5 +24,6 @@
2424
<page name='Day21'/>
2525
<page name='Day22'/>
2626
<page name='Day23'/>
27+
<page name='Day25'/>
2728
</pages>
2829
</playground>

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy