Compare commits
No commits in common. "64c9395de5b25afa2d8b5048c37f5190561d6765" and "5a7bf9b36506aa6305c9a7882d19c352f19bb1fe" have entirely different histories.
64c9395de5
...
5a7bf9b365
2500
day02/input
2500
day02/input
File diff suppressed because it is too large
Load Diff
File diff suppressed because one or more lines are too long
|
@ -1,38 +0,0 @@
|
||||||
) get "input.ivy"
|
|
||||||
|
|
||||||
test = 3 2 rho "AYBXCZ"
|
|
||||||
|
|
||||||
op inc a = 1 + a
|
|
||||||
op dec a = -1 + a
|
|
||||||
|
|
||||||
# returns the outcome for the first player (-1 = lose, 0=draw, +1 = win)
|
|
||||||
# of a round of rps (1-3 = rock, paper, scissors)
|
|
||||||
op a rps b = dec (inc a - b) mod 3
|
|
||||||
|
|
||||||
op tonum a = ("ABC" iota a) + ("XYZ" iota a)
|
|
||||||
|
|
||||||
# converts an outcome into a score
|
|
||||||
op score outcome =
|
|
||||||
3 + 3 * outcome
|
|
||||||
|
|
||||||
# scores a round of rps for the first player
|
|
||||||
op a score b =
|
|
||||||
outcome = a rps b
|
|
||||||
a + score outcome
|
|
||||||
|
|
||||||
op parta x =
|
|
||||||
x = transp tonum x
|
|
||||||
+/ x[2] score x[1]
|
|
||||||
|
|
||||||
op partb x =
|
|
||||||
x = tonum transp x
|
|
||||||
a = x[1]
|
|
||||||
outcome = -2 + x[2]
|
|
||||||
b = inc (dec a + outcome) mod 3
|
|
||||||
+/ b score a
|
|
||||||
|
|
||||||
parta test
|
|
||||||
parta input
|
|
||||||
|
|
||||||
partb test
|
|
||||||
partb input
|
|
32
day02/sol.py
32
day02/sol.py
|
@ -1,32 +0,0 @@
|
||||||
scores = {
|
|
||||||
"A X": 1+3,
|
|
||||||
"B X": 1+0,
|
|
||||||
"C X": 1+6,
|
|
||||||
"A Y": 2+6,
|
|
||||||
"B Y": 2+3,
|
|
||||||
"C Y": 2+0,
|
|
||||||
"A Z": 3+0,
|
|
||||||
"B Z": 3+6,
|
|
||||||
"C Z": 3+3,
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
t = 0
|
|
||||||
with open("input") as f:
|
|
||||||
for game in f:
|
|
||||||
t += scores[game.strip()]
|
|
||||||
|
|
||||||
print(t)
|
|
||||||
|
|
||||||
t2 = 0
|
|
||||||
with open("input") as f:
|
|
||||||
for game in f:
|
|
||||||
you, me = game.split()
|
|
||||||
a="ABC".index(you)
|
|
||||||
b="YZX".index(me)
|
|
||||||
play = 1+(a+b)%3
|
|
||||||
outcome = (b+1)%3
|
|
||||||
t2 += play + outcome*3
|
|
||||||
|
|
||||||
print(t2)
|
|
|
@ -1,3 +0,0 @@
|
||||||
A Y
|
|
||||||
B X
|
|
||||||
C Z
|
|
|
@ -1,9 +0,0 @@
|
||||||
data = []
|
|
||||||
n = 0
|
|
||||||
with open("input") as f:
|
|
||||||
for line in f:
|
|
||||||
for x in line.split():
|
|
||||||
data.append(x)
|
|
||||||
n += 1
|
|
||||||
|
|
||||||
print('input = {} {} rho "{}"'.format(n, 2, ''.join(data)))
|
|
Loading…
Reference in New Issue