diff --git a/day10/input b/day10/input new file mode 100644 index 0000000..6260eb7 --- /dev/null +++ b/day10/input @@ -0,0 +1,138 @@ +addx 1 +addx 5 +noop +addx -1 +noop +addx 3 +addx 29 +addx -1 +addx -21 +addx 5 +noop +addx -20 +addx 21 +addx 2 +addx 8 +addx -1 +noop +noop +noop +noop +addx 6 +addx -1 +addx -37 +addx 40 +addx -10 +addx -25 +addx 5 +addx 2 +addx 5 +noop +noop +noop +addx 21 +addx -20 +addx 2 +noop +addx 3 +addx 2 +addx -5 +addx 12 +addx 3 +noop +addx 2 +addx 3 +addx -2 +addx -37 +addx 1 +addx 5 +addx 3 +addx -2 +addx 2 +addx 29 +addx -22 +addx 13 +noop +addx -8 +addx -6 +addx 7 +addx 2 +noop +addx 7 +addx -2 +addx 5 +addx 2 +addx -26 +addx -11 +noop +noop +addx 6 +addx 1 +addx 1 +noop +addx 4 +addx 5 +noop +noop +addx -2 +addx 3 +noop +addx 2 +addx 5 +addx 2 +addx -22 +addx 27 +addx -1 +addx 1 +addx 5 +addx 2 +noop +addx -39 +addx 22 +noop +addx -15 +addx 3 +addx -2 +addx 2 +addx -2 +addx 9 +addx 3 +noop +addx 2 +addx 3 +addx -2 +addx 2 +noop +noop +noop +addx 5 +addx -17 +addx 24 +addx -7 +addx 8 +addx -36 +addx 2 +addx 3 +addx 33 +addx -32 +addx 4 +addx 1 +noop +addx 5 +noop +noop +addx 20 +addx -15 +addx 4 +noop +addx 1 +noop +addx 4 +addx 6 +addx -30 +addx 30 +noop +noop +noop +noop +noop diff --git a/day10/sample b/day10/sample new file mode 100644 index 0000000..37ee8ee --- /dev/null +++ b/day10/sample @@ -0,0 +1,146 @@ +addx 15 +addx -11 +addx 6 +addx -3 +addx 5 +addx -1 +addx -8 +addx 13 +addx 4 +noop +addx -1 +addx 5 +addx -1 +addx 5 +addx -1 +addx 5 +addx -1 +addx 5 +addx -1 +addx -35 +addx 1 +addx 24 +addx -19 +addx 1 +addx 16 +addx -11 +noop +noop +addx 21 +addx -15 +noop +noop +addx -3 +addx 9 +addx 1 +addx -3 +addx 8 +addx 1 +addx 5 +noop +noop +noop +noop +noop +addx -36 +noop +addx 1 +addx 7 +noop +noop +noop +addx 2 +addx 6 +noop +noop +noop +noop +noop +addx 1 +noop +noop +addx 7 +addx 1 +noop +addx -13 +addx 13 +addx 7 +noop +addx 1 +addx -33 +noop +noop +noop +addx 2 +noop +noop +noop +addx 8 +noop +addx -1 +addx 2 +addx 1 +noop +addx 17 +addx -9 +addx 1 +addx 1 +addx -3 +addx 11 +noop +noop +addx 1 +noop +addx 1 +noop +noop +addx -13 +addx -19 +addx 1 +addx 3 +addx 26 +addx -30 +addx 12 +addx -1 +addx 3 +addx 1 +noop +noop +noop +addx -9 +addx 18 +addx 1 +addx 2 +noop +noop +addx 9 +noop +noop +noop +addx -1 +addx 2 +addx -37 +addx 1 +addx 3 +noop +addx 15 +addx -21 +addx 22 +addx -6 +addx 1 +noop +addx 2 +addx 1 +noop +addx -10 +noop +noop +addx 20 +addx 1 +addx 2 +addx 2 +addx -6 +addx -11 +noop +noop +noop diff --git a/day10/sol.py b/day10/sol.py new file mode 100644 index 0000000..21636a8 --- /dev/null +++ b/day10/sol.py @@ -0,0 +1,35 @@ + +cycle = 0 +X = 1 +T = 0 +def step(): + global T + global cycle + cycle += 1 + if cycle in (20, 60, 100, 140, 180, 220): + ss = cycle * X + T += ss + + px = (cycle-1) % 40 + if abs(X - px) <= 1: + # sprite is visible + img.append('#') + else: + img.append(' ') + + +img = [] + +for line in open("input"): + ins = line.strip() + if ins == "noop": + step() + else: + step() + step() + X += int(line.split()[1]) + +print (T) + +for i in range(0, len(img), 40): + print(''.join(img[i:i+40]))