Frans Bergman пре 4 година
родитељ
комит
c12f68dcb3
2 измењених фајлова са 134 додато и 0 уклоњено
  1. 100 0
      10.input
  2. 34 0
      10.py

+ 100 - 0
10.input

@@ -0,0 +1,100 @@
+44
+41
+48
+17
+35
+146
+73
+3
+16
+159
+11
+29
+32
+63
+65
+62
+126
+151
+6
+124
+87
+115
+122
+43
+12
+85
+2
+98
+59
+156
+149
+66
+10
+82
+26
+79
+56
+22
+74
+49
+25
+69
+54
+19
+108
+18
+55
+131
+140
+15
+125
+37
+129
+91
+51
+158
+117
+136
+142
+109
+64
+36
+160
+150
+42
+118
+101
+78
+28
+105
+110
+40
+157
+70
+97
+139
+152
+47
+104
+81
+27
+116
+132
+143
+1
+80
+75
+141
+133
+9
+50
+153
+123
+111
+119
+130
+112
+94
+90
+86

+ 34 - 0
10.py

@@ -0,0 +1,34 @@
+# Read lines
+lines = []
+
+with open("10.input") as f:
+    for line in f.readlines():
+        lines.append(int(line.strip()))
+
+lines.sort()
+
+current = 0
+
+diffs = [0, 0, 0, 0]
+
+for next in lines:
+    diffs[next - current] += 1
+    current = next
+
+diffs[3] += 1 # Device joltage
+
+print("Answer 1: " + str(diffs[1] * diffs[3]))
+
+count_from = {}
+count_from[max(lines)] = 1
+
+
+lines.reverse()
+lines.pop(0)
+
+for current in lines + [0]:
+    count_from[current] = 0
+    for i in range(1, 4):
+        count_from[current] += count_from.get(current + i, 0)
+
+print("Answer 2: " + str(count_from[0]))