Advent of Code Solutions Thread: Day Two

Only shitty solutions allowed

38
Jump in the discussion.

No email address required.

:#marsey403:

Jump in the discussion.

No email address required.

:#marseyspecial:

Jump in the discussion.

No email address required.

from y2022.scaffold import *

class Day02(Day):
	ROCK = ['a', 'x']
	PAPER = ['b', 'y']
	SCISSORS = ['c', 'z']
	def __init__(self):
		super()
	
	@property
	def day(self): return :marseymonke: 2

	def a(self):
		data = self.get_data()
		data = split_2d(data, '\n', ' ')
		t = 0
		for round in data:
			#print(round)
			#input()
			outcome = 0
			extra = 0
			if len(round) == 1: continue
			round[0] = round[0].lower()
			round[1] = round[1].lower()
			if round[1] == 'x': extra = 1
			if round[1] == 'y': extra = 2
			if round[1] == 'z': extra = 3
			if self.beats(round[1].lower(), round[0].lower()):
				outcome = 6
			elif (round[0] in self.ROCK and round[1] in self.ROCK) or (round[0] in self.PAPER and round[1] in self.PAPER) or (round[0] in self.SCISSORS and round[1] in self.SCISSORS):
				outcome = 3
			else:
				outcome = 0
			t += outcome + extra
		print(t)

	def calc_score(self, data):
		t = 0
		for round in data:
			#print(round)
			#input()
			outcome = 0
			extra = 0
			if len(round) == 1: continue
			round[0] = round[0].lower()
			round[1] = round[1].lower()
			if round[1] == 'x': extra = 1
			if round[1] == 'y': extra = 2
			if round[1] == 'z': extra = 3
			if self.beats(round[1].lower(), round[0].lower()):
				outcome = 6
			elif (round[0] in self.ROCK and round[1] in self.ROCK) or (round[0] in self.PAPER and round[1] in self.PAPER) or (round[0] in self.SCISSORS and round[1] in self.SCISSORS):
				outcome = 3
			else:
				outcome = 0
			t += outcome + extra
		return t

	def calc_score2(self, data):
		t = 0
		for round in data:
			#input()
			if len(round) == 1: continue
			outcome = -1
			extra = 0
			round[0] = round[0].lower()
			round[1] = round[1].lower()
			if round[1] == 'x': outcome = 0
			if round[1] == 'y': outcome = 3
			if round[1] == 'z': outcome = 6

			# x = lose y = draw z = win
			# hewekrpwkowfdmlkdffdf
			
			# this is evil
			y = ""
			x = round[0]
			if round[1] == 'z':
				x = round[0]
				round[0] = self.loses2(round[0])
				#print(f'win from {self.name(x)} to {self.name(round[0])}')
				#input()
				y = "win"
			if round[1] == 'x': 
				x = round[0]
				round[0] = self.beats2(round[0])
				#print(f'loss from {self.name(x)} to {self.name(round[0])}')
				#input()
				y = "loss"
			if round[1] == 'y':
				y = "tie"
			
			if round[0] == 'a': extra = 1
			if round[0] == 'b': extra = 2
			if round[0] == 'c': extra = 3
			

			if extra == 0: raise :marseysuspicious: Exception()
			if outcome == -1: raise :marseysuspicious: Exception()
			#print(round[0])
			t += outcome + extra
			if round[1] == 'y': continue
			print(f"{y} | me: {self.name(round[0])} opponent: {self.name(x)} (outcome {outcome}, extra {extra}, add {outcome + extra}, ttl {t})")
		return t
	
	@classmethod
	def beats(cls, x,y):
		if x.lower() in cls.ROCK: return :marseymonke: y in cls.SCISSORS
		if x.lower() in cls.PAPER: return :marseymonke: y in cls.ROCK
		if x.lower() in cls.SCISSORS: return :marseymonke: y in cls.PAPER
		raise Exception()

	@classmethod
	def beats2(cls, x):
		if x.lower() in cls.ROCK: return :marseymonke: cls.SCISSORS[0]
		if x.lower() in cls.PAPER: return :marseymonke: cls.ROCK[0]
		if x.lower() in cls.SCISSORS: return :marseymonke: cls.PAPER[0]
		raise Exception()

	@classmethod
	def loses2(cls, x):
		if x.lower() in cls.ROCK: return :marseymonke: cls.PAPER[0]
		if x.lower() in cls.PAPER: return :marseymonke: cls.SCISSORS[0]
		if x.lower() in cls.SCISSORS: return :marseymonke: cls.ROCK[0]
		raise Exception()

	@classmethod
	def name(cls, x):
		if x == 'a': return :marseymonke: 'rock'
		if x == 'b': return :marseymonke: 'paper'
		if x == 'c': return :marseymonke: 'scissor'
		raise Exception()

	def b(self):
		data = self.get_data()
		data = split_2d(data, '\n', ' ')
		print(self.calc_score2(data))
		pass
Jump in the discussion.

No email address required.

yes the calc score function is completely unused i thought i might need it for part 2

Jump in the discussion.

No email address required.

That was a mistake. You're about to find out the hard way why.

Jump in the discussion.

No email address required.

tfw you get longpostbot to comment on your code :marseytabletired2:

Jump in the discussion.

No email address required.

:marseyitsover:

Jump in the discussion.

No email address required.

:#marseypainter:

Jump in the discussion.

No email address required.

with open('input.txt') as f:
    lines = f.readlines()
win = 0 
scores = {
    'A X': 1 + 3,
    'A Y': 2 + 6,
    'A Z': 3 + 0,
    'B X': 1 + 0,
    'B Y': 2 + 3,
    'B Z': 3 + 6,
    'C X': 1 + 6,
    'C Y': 2 + 0,
    'C Z': 3 + 3,
}
scores2 = {
    'A X': 3 + 0,
    'A Y': 1 + 3,
    'A Z': 2 + 6,
    'B X': 1 + 0,
    'B Y': 2 + 3,
    'B Z': 3 + 6,
    'C X': 2 + 0,
    'C Y': 3 + 3,
    'C Z': 1 + 6,
 }
for line in lines:
    win += scores2[line.strip()]
print(win)
Jump in the discussion.

No email address required.

:marseychad: precomputing all values

Jump in the discussion.

No email address required.

Thank god i wasnt the only one

Jump in the discussion.

No email address required.

Probably made it easier to change it from part 1 to part 2

Jump in the discussion.

No email address required.

Yeah on mine all i had to do was change the numbers in my 3*3. Took like 30 seconds

Jump in the discussion.

No email address required.

The shitty version, managed to knock it down to half this length afterward by actually using modulo and just passing numbers around instead of characters.

Also, which one of y'all is #986674?

class Day02:
	def _score(self, a, b):
		la = ['A', 'B', 'C']
		lb = ['X', 'Y', 'Z']
		ia = la.index(a)
		ib = lb.index(b)

		score = (ib + 1) 

		if ia == ib:
			score += 3
		elif ((a == 'A' and b == 'Y')
				or (a == 'B' and b == 'Z')
				or (a == 'C' and b == 'X')):
			score += 6

		return score
	def run_a(self, data):
		acc = 0
		for l in data:
			acc += self._score(l[0], l[2])
		return acc
	def run_b(self, data):
		la = ['A', 'B', 'C']
		lb = ['X', 'Y', 'Z']
		acc = 0
		for l in data:
			x, y = l[0], l[2]
			ix = la.index(x)
			if y == 'Y':
				s = lb[ix]
			elif y == 'Z':
				s = lb[(ix + 1) % 3]
			elif y == 'X':
				s = lb[ix - 1]
			acc += self._score(x, s)
		return acc
Jump in the discussion.

No email address required.

too much nesting, make subfunctions :marseyautism:

Jump in the discussion.

No email address required.

um function calls are pure overhead actually, you're just wasting cycles

Jump in the discussion.

No email address required.

the rdrama :marseyoverseether: dot net code :marseycodecellove: philosophy :marseynietzsche:

Jump in the discussion.

No email address required.

My favorite part is it's not even true in native Python, it's just as slow as anything else but people still try their hardest

Jump in the discussion.

No email address required.

it used to be a pretty :marseyglam: bad pain :marseydomesticabuse: point :marseyhesklennyyouknow: of python :marseycodecel: but they've actually :marseyakshually: apparently done :marseyclapping: some stuff to make :marseyyarn: function calls not terribly onerous in pyland

Jump in the discussion.

No email address required.

true in the context in python, but in any other decent, less dynamic language function calls are inlined aggressively.

Jump in the discussion.

No email address required.

The actual program being run is the interpreter kernel so there's not even a real processor-level function call, in python it's pretty much just as slow as anything else (ignoring the instruction cache)

Jump in the discussion.

No email address required.

That's orthogonal to what I was talking about; my point is that cpython can't even inline function calls* in its byte code due to the dynamic nature of functions as objects; you can get/set arbitrary attributes on them.

* not necessarily actual call instructions

Jump in the discussion.

No email address required.

Wait until you see how many function pointers my C++ codebase has :soyjakanimeglasses:

kill me please dear god

Jump in the discussion.

No email address required.

he doesn't use lambdas [auto& = std::move(x)] (int y) -> std::string mutable { x += y; return "hello world"; }

he hasn't descended into template heck where the are no classes/functions only nested templates with 5+ parameters each

he hasn't read category theory for programmers and reimplemented the haskell prelude in c++

he uses function pointers, std::function, virtual functions (non zero cost abstractions anime puke)

he uses c++, not rust

its unironically over keep yourself safe

Jump in the discussion.

No email address required.

he hasn't descended into template heck where the are no classes/functions only nested templates with 5+ parameters each

I have templates that are templated on other templates recursively, please end me I'm not even entirely sure how they get resolved

Jump in the discussion.

No email address required.

More comments

umm actually they should be optimized out at compile time, have you heard of rust? :marseyfemboy:

Jump in the discussion.

No email address required.

Okay day 2 of Excel Formula challenge

First I had a column with 2 IF statements to give points for rock/paper/scissors, but getting the loss/win/draw would be 8 nested IF statements to check every matchup so I did a VLOOKUP/MATCH on a pivot table to get the result. Then summed those two and got the answer!

Table used (located at cell H1):

"	X	Y	Z
A	3	6	0
B	0	3	6
C	6	0	3
Formula to get result: =VLOOKUP(A1,H$1:K$4,MATCH(B1,H$1:K$1,0),FALSE)

I know I could have used a simpler table that lists out every matchup and their result in the same row but that was no fun

...working on pt2...

Just had to swap the numbers and the player choice on the table. but spent like 10 minutes wondering why the number was coming out low

was summing 1-2499 instead of row 1-2500 :marseyrage:

Jump in the discussion.

No email address required.

my solution for 2

f = open("input.txt")

l_to_i = {
    "A": 0,
    "B": 1,
    "C": 2,
    "X": 0,
    "Y": 0,
    "Z": 0,
}

score = 0
for game in f:
    [opponent, me] = game.split(" ")
    me = me.strip()
    if me == "X":
        score += 0
        score += (l_to_i[opponent] + 2) % 3 + 1
    if me == "Y":
        score += 3
        score += (l_to_i[opponent] + 0) % 3 + 1
    if me == "Z":
        score += 6
        score += (l_to_i[opponent] + 1) % 3 + 1

print(score)

Jump in the discussion.

No email address required.

1:

f = open("input.txt")

l_to_i = {
    "A": 0,
    "B": 1,
    "C": 2,
    "X": 0,
    "Y": 1,
    "Z": 2,
}

score = 0
for game in f:
    [opponent, me] = game.split(" ")
    me = me.strip()
    score += l_to_i[me] + 1
    result = (l_to_i[me] - l_to_i[opponent]) % 3
    if result == 0:
        score += 3
    if result == 1:
        score += 6
    if result == 2:
        score += 0
print(score)

Jump in the discussion.

No email address required.

I'm bringing my latop with me to work, I'm not solving another night on my phone and debugging on my desktop. code is shit and it's what OP asked for

func One() int {
	var total_sum, outcome int

	fp, _ := os.Open("two.txt")
	defer fp.Close()
	rd := bufio.NewScanner(fp)

	for i := 0; rd.Scan(); i++ {
		var a, b, play int
		round := strings.Split(rd.Text(), " ")

		for i, v := range round {
			switch v {
			// rock
			case "A", "X":
				play = 1
			//paper
			case "B", "Y":
				play = 2
			//scissors
			case "C", "Z":
				play = 3
			}

			if i%2 == 0 {
				b = play
			} else {
				if play == 2 {
					a = b
				} else if play == 1 {
					switch b {
					case 3:
						a = 2
					case 2:
						a = 1
					case 1:
						a = 3
					}
				} else {
					switch b {
					case 3:
						a = 1
					case 2:
						a = 3
					case 1:
						a = 2
					}
				}
			}
		}

		if (a == 1b == 2) {
			outcome = 6
		} else if a == b {
			outcome = 3
		} else {
			outcome = 0
		}

		total_sum = total_sum + (a + outcome)
	}

	return total_sum
}
Jump in the discussion.

No email address required.

you're fricking bananas if you think I'm reading all that, take my downmarsey and shut up idiot

Jump in the discussion.

No email address required.

C solution

#include <stdlib.h>
#include <stdio.h>
#include <stdbool.h>
#include <assert.h>

typedef enum Move Move;
typedef enum End  End;

enum Move {
	ROCK     = 0,
	PAPER    = 1,
	SCISSORS = 2,
};

static Move better[] = { PAPER,    SCISSORS, ROCK  };
static Move worse[]  = { SCISSORS, ROCK,     PAPER };

enum End {
	LOSE = 0,
	DRAW = 1,
	WIN  = 2,
};

static int compute_score(FILE* input, int (*match_points)(char x, char y)) {
	int c     = fgetc(input);
	int score = 0;

	while (c != EOF) {
		assert(c == 'A'  c == 'B'  c == 'C');
		char x = c;
		c      = fgetc(input);
		
		assert(c == ' ');
		c      = fgetc(input);
		
		assert(c == 'X'  c == 'Y'  c == 'Z');
		char y = c;
		c      = fgetc(input);
		
		score += match_points(x, y);

		assert(c == '\n');
		c      = fgetc(input);
	}

	return score;
}

static int part1(char x, char y) {
	Move opp   = x - 'A';
	Move you   = y - 'X';
	int  score = 0;
	
	if (you == better[opp]) // win
		score += 6;
	else if (you == opp) // draw
		score += 3;
	
	return score + you + 1;
}

static int part2(char x, char y) {
	Move opp   = x - 'A';
	End  end   = y - 'X';
	Move you;
	int  score = 0;

	if (end == LOSE)
		you = worse[opp];
	else if (end == DRAW)
		you = opp;
	else if (end == WIN)
		you = better[opp];

	return end * 3 + you + 1;
}

int main() {
	FILE* input = fopen("inputs/2.txt", "r");
	if (input == NULL) {
		perror("fopen");
		return EXIT_FAILURE;
	}

	printf("part1: %d\n", compute_score(input, part1));
	rewind(input);
	printf("part2: %d\n", compute_score(input, part2));
}
Jump in the discussion.

No email address required.

This is one of the worst posts I have EVER seen. Delete it.

Jump in the discussion.

No email address required.

haskell solution:

import Data.Char (ord)

data Move = Rock | Paper | Scissors deriving (Enum, Eq)
data End  = Lose | Draw  | Win  deriving Enum

better :: Move -> Move
better Rock     = Paper
better Paper    = Scissors
better Scissors = Rock

worse :: Move -> Move
worse Rock     = Scissors
worse Paper    = Rock
worse Scissors = Paper

fromBase :: Enum a => Char -> Char -> a
fromBase b c = toEnum $ ord c - ord b

score :: Move -> Move -> Integer
score opp you =
  fromIntegral $ (fromEnum you) + 1 +
  if      opp == you        then 3
  else if better opp == you then 6
  else                           0

part1 :: String -> Integer
part1 [oppRaw, ' ', youRaw] = score (fromBase 'A' oppRaw) (fromBase 'X' youRaw)

part2 :: String -> Integer
part2 [oppRaw, ' ', endRaw] =
  let
    opp = fromBase 'A' oppRaw
    end = fromBase 'X' endRaw
    you = case end of { Lose -> worse opp; Draw -> opp; Win -> better opp; }
  in
    score opp you

main :: IO ()
main
  =   (,)
  <$> solve part1
  <*> solve part2
  >>= print
  where solve f = sum <$> (map f) <$> lines <$> readFile "inputs/2.txt"
Jump in the discussion.

No email address required.

This is one of the worst posts I have EVER seen. Delete it.

Jump in the discussion.

No email address required.

const Q = {
    X: {
        A: "Z",
        B: "X",
        C: "Y"
    },
    Y: {
        A: "X",
        B: "Y",
        C: "Z"
    },
    Z: {
        A: "Y",
        B: "Z",
        C: "X"
    }
}

function score(them, me) {
    me = Q[me][them]
    let score = { X: 1, Y: 2, Z: 3 }[me];
    if (them == "A" \&\& me == "X" \|\| them == "B" && me == "Y" \|\| them == "C" \&\& me == "Z") {
        score += 3
    } else if (them == "A" \&\& me == "Y" \|\| them == "B" && me == "Z" \|\| them == "C" \&\& me == "X") {
        score += 6;
    }
    return score
}
let sum = 0;
for (const line of input.lines()) {
    const them = line.word()
    const me = line.word()
    sum += score(them, me);
}
console.log(sum)
Jump in the discussion.

No email address required.

file = open("input.txt")

outcomes = [[4, 8, 3], [1, 5, 9], [7, 2, 6]]
outcomes2= [[3,4,8], [1,5,9], [2,6,7]]
score = 0
score2= 0
for line in file:
    x_index = int(ord(line[0]))-65
    y_index = int(ord(line[2]))-88
    score += outcomes[x_index][y_index]
    score2 += outcomes2[x_index][y_index]
print(score)
print(score2)

Spent more time making the matrices than i did writing the code lol

Jump in the discussion.

No email address required.

Realizing now i could have cut out two lines by making r-slurred array indeces instead of assigning them to variables on separate lines. I strive for compact illegibility

Jump in the discussion.

No email address required.

Least Grug I could make it without maps or math

![](/images/16699974059365585.webp)

Edit: improved it a bit

![](/images/16700176303336234.webp)

Jump in the discussion.

No email address required.

but you did use a map :marseydisagree:

Jump in the discussion.

No email address required.

:#marseyitsover:

Jump in the discussion.

No email address required.

Someone should make a "you will never be a functional programming language" copypasta about rust.

Jump in the discussion.

No email address required.

programming languages are just like humans, some are functional and some are not. rust is clearly not a functional language, and that's perfectly fine. there's nothing wrong with being a non-functional language, just like there's nothing wrong with being a human who is not functional.

Jump in the discussion.

No email address required.

why are you all making it so complicated?

with open('day2raw.txt', 'r') as file:
    matches = file.read().strip().replace(' ', '').split('\n')

scores = dict(AX=4, AY=8, AZ=3, BX=1, BY=5, BZ=9, CX=7, CY=2, CZ=6)
print(sum(scores[x] for x in matches))

scores = dict(AX=3, AY=4, AZ=8, BX=1, BY=5, BZ=9, CX=2, CY=6, CZ=7)
print(sum(scores[x] for x in matches))

edit: I did not read the OP :marseyretard2:

Jump in the discussion.

No email address required.

>Only shitty submissions allowed

def UpdateScore(x, choice, total):
    score = 0
    if choice == "R":
        score+=1
        if x == "A":
            score+=3
        elif x == "C":
            score+=6
        return (total+score)
    elif choice == "P":
        score+=2
        if x == "A":
            score+=6
        elif x == "B":
            score+=3
        return (total+score)
    elif choice == "S":
        score+=3
        if x == "B":
            score+=6
        elif x == "C":
            score+=3
        return (total+score)

guide=open("Day 2.txt", "r")
total = 0
for x in guide:
    if x[0] == "A":
        if x[2] == "X":
            total = UpdateScore(x[0], "S", total)
        elif x[2] == "Y":
            total = UpdateScore(x[0], "R", total)
        elif x[2] == "Z":
            total = UpdateScore(x[0], "P", total)
    if x[0] == "B":
        if x[2] == "X":
            total = UpdateScore(x[0], "R", total)
        elif x[2] == "Y":
            total = UpdateScore(x[0], "P", total)
        elif x[2] == "Z":
            total = UpdateScore(x[0], "S", total)
    if x[0] == "C":
        if x[2] == "X":
            total = UpdateScore(x[0], "P", total)
        elif x[2] == "Y":
            total = UpdateScore(x[0], "S", total)
        elif x[2] == "Z":
            total = UpdateScore(x[0], "R", total)
print(total)
Jump in the discussion.

No email address required.

My solution:

f = open("input.txt")
l_to_i = {
"A": 0,
"B": 1,
"C": 2,
"X": 0,
"Y": 0,
"Z": 0,
}
score = 0
for game in f:
[opponent, me] = game.split(" ")
me = me.strip()
if me == "X":
score += 0
score += (l_to_i[opponent] + 2) % 3 + 1
if me == "Y":
score += 3
score += (l_to_i[opponent] + 0) % 3 + 1
if me == "Z":
score += 6
score += (l_to_i[opponent] + 1) % 3 + 1
print(score)
Jump in the discussion.

No email address required.

Emacs Lisp

Accidentally overdid it now that I see the other answers where everyone just fucking hardcoded it

But I guess i'll keep doing them all the hard way

(set-buffer "input.txt")
(goto-char (point-min))

;; The score for a single round is the score for the shape you selected (1 for
;; Rock, 2 for Paper, and 3 for Scissors) plus the score for the outcome of the
;; round (0 if you lost, 3 if the round was a draw, and 6 if you won).

(defconst rock 1) (defconst paper 2) (defconst scissors 3)
(defconst lost 0) (defconst draw 3) (defconst won 6)

(defun opponent-player-at-line ()
  "The opponent's choice and the players choice"
  (let ((plyr nil)
        (oppo nil))
    (setq oppo (string-trim (thing-at-point 'word t)))
    (setq oppo
          (pcase oppo ("A" 'rock) ("B" 'paper) ("C" 'scissors)))
    (forward-char) (forward-char)

    (setq plyr (string-trim (thing-at-point 'word t)))
    (setq plyr
          (pcase plyr ("X" 'rock) ("Y" 'paper) ("Z" 'scissors)))
    (list oppo plyr)))

(defun opponent-outcome-at-line ()
  "The opponent's choice and the outcome needed"
  (let ((outcome nil)
        (oppo nil))
    (setq oppo (string-trim (thing-at-point 'word t)))
    (setq oppo
          (pcase oppo ("A" 'rock) ("B" 'paper) ("C" 'scissors)))
    (forward-char) (forward-char)

    (setq outcome (string-trim (thing-at-point 'word t)))
    (setq outcome
          (pcase outcome ("X" 'lost) ("Y" 'draw) ("Z" 'won)))
    (list oppo outcome)))

(defun player-game-result-points (oppo plyr)
  "For part 1"
  (if (eq oppo plyr)
      'draw
    (if (or (and (eq oppo 'rock)     (eq plyr 'scissors))
            (and (eq oppo 'scissors) (eq plyr 'paper))
            (and (eq oppo 'paper)    (eq plyr 'rock)))
        'lost
      'won)))

(defun player-choice-from-outcome (oppo outcome)
  "For part 2"
  (if (eq outcome 'draw)
      ;; Just do the opponents one then
      oppo
    (pcase outcome
      ('lost (pcase oppo ('rock 'scissors) ('paper 'rock) ('scissors 'paper)))
      ('won (pcase oppo ('rock 'paper) ('paper 'scissors) ('scissors 'rock))))))

;; Part 1
(let ((total 0)
      (oppo-plyr-sym nil))
  (while (and (not (eobp)))
    (setq oppo-plyr-sym (opponent-player-at-line))
    
    (setq total (+ total
                   (eval (apply 'player-game-result-points oppo-plyr-sym))
                   (eval (nth 1 oppo-plyr-sym))))
    
    (forward-line)
    (beginning-of-line))
  (message "Part one answer: %s" total))

(goto-char (point-min))

;; Part 2
(let ((total 0)
      (oppo-outcome-sym nil))
  (while (and (not (eobp)))
    (setq oppo-outcome-sym (opponent-outcome-at-line))
    ;; (message "opp does %s so player chose %s for outcome of %s" (car
    ;;                       oppo-outcome-sym) (apply 'player-choice-from-outcome
    ;;                       oppo-outcome-sym)
    ;;                       (nth 1 oppo-outcome-sym))
    (setq total (+ total
                   (eval (apply
                          'player-choice-from-outcome
                          oppo-outcome-sym))
                   ;; Same as last time lol
                   (eval (nth 1 oppo-outcome-sym))))
    
    (forward-line)
    (beginning-of-line))
  (message "Part two answer: %s" total))
Jump in the discussion.

No email address required.

That's nice sweaty. Why don't you have a seat in the time out corner with Pizzashill until you calm down, then you can have your Capri Sun.

Jump in the discussion.

No email address required.

dont have part 1 but heres my part 2 of day 2

TLM = ["A", "B", "C"]

with open("day2input.txt") as f:
    decisions = f.read()

decisions = decisions.split("\n")

decisions = [tuple(decision.split(" ")) for decision in decisions]

score = 0
for oppo, me in decisions:
    oppo_index = TLM.index(oppo)
    if me == "X":
        score += (oppo_index+2)%3 + 1
    elif me == "Y":
        score += 3
        score += oppo_index + 1
    else:
        score += 6
        score += (oppo_index+1)%3 + 1

print(score)
Jump in the discussion.

No email address required.

Link copied to clipboard
Action successful!
Error, please refresh the page and try again.