Skip to content

Commit 832bff6

Browse files
Andy HerdAndy Herd
authored andcommitted
day01 inverse ccaptcha
0 parents  commit 832bff6

File tree

9 files changed

+603
-0
lines changed

9 files changed

+603
-0
lines changed

.idea/adventofcode.iml

Lines changed: 14 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/misc.xml

Lines changed: 4 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/modules.xml

Lines changed: 8 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/vcs.xml

Lines changed: 6 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/workspace.xml

Lines changed: 500 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
788 Bytes
Binary file not shown.

day01/day01.md

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
--- Day 1: Inverse Captcha ---
2+
3+
The night before Christmas, one of Santa's Elves calls you in a panic. "The printer's broken! We can't print the Naughty or Nice List!" By the time you make it to sub-basement 17, there are only a few minutes until midnight. "We have a big problem," she says; "there must be almost fifty bugs in this system, but nothing else can print The List. Stand in this square, quick! There's no time to explain; if you can convince them to pay you in stars, you'll be able to--" She pulls a lever and the world goes blurry.
4+
5+
When your eyes can focus again, everything seems a lot more pixelated than before. She must have sent you inside the computer! You check the system clock: 25 milliseconds until midnight. With that much time, you should be able to collect all fifty stars by December 25th.
6+
7+
Collect stars by solving puzzles. Two puzzles will be made available on each day millisecond in the advent calendar; the second puzzle is unlocked when you complete the first. Each puzzle grants one star. Good luck!
8+
9+
You're standing in a room with "digitization quarantine" written in LEDs along one wall. The only door is locked, but it includes a small interface. "Restricted Area - Strictly No Digitized Users Allowed."
10+
11+
It goes on to explain that you may only leave by solving a captcha to prove you're not a human. Apparently, you only get one millisecond to solve the captcha: too fast for a normal human, but it feels like hours to you.
12+
13+
The captcha requires you to review a sequence of digits (your puzzle input) and find the sum of all digits that match the next digit in the list. The list is circular, so the digit after the last digit is the first digit in the list.
14+
15+
For example:
16+
17+
1122 produces a sum of 3 (1 + 2) because the first digit (1) matches the second digit and the third digit (2) matches the fourth digit.
18+
1111 produces 4 because each digit (all 1) matches the next.
19+
1234 produces 0 because no digit matches the next.
20+
91212129 produces 9 because the only digit that matches the next one is the last digit, 9.

day01/inverse_captcha.py

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
import sys
2+
3+
4+
def sum_digits_if_identical(digit_one, digit_two):
5+
result = 0
6+
if digit_one == digit_two:
7+
result = int(digit_one)
8+
return result
9+
10+
11+
def get_captcha(input_num):
12+
total_sum = 0
13+
input_num_as_str = str(input_num)
14+
prev_digit = input_num_as_str[-1] # start with the final digit
15+
for digit in input_num_as_str:
16+
total_sum += sum_digits_if_identical(digit, prev_digit)
17+
prev_digit = digit
18+
return total_sum
19+
20+
21+
if __name__ == '__main__':
22+
print('input: ' + sys.argv[1])
23+
print('output: ' + str(get_captcha(sys.argv[1])))

day01/test_inverse_captcha.py

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
import unittest
2+
from inverse_captcha import get_captcha
3+
4+
5+
class TestInverseCaptcha(unittest.TestCase):
6+
def test_1122(self):
7+
start_num = 1122
8+
expected = 3
9+
result = get_captcha(start_num)
10+
self.assertEqual(expected, result)
11+
12+
def test_1111(self):
13+
start_num = 1111
14+
expected = 4
15+
result = get_captcha(start_num)
16+
self.assertEqual(expected, result)
17+
18+
def test_1234(self):
19+
start_num = 1234
20+
expected = 0
21+
result = get_captcha(start_num)
22+
self.assertEqual(expected, result)
23+
24+
def test_91212129(self):
25+
start_num = 91212129
26+
expected = 9
27+
result = get_captcha(start_num)
28+
self.assertEqual(expected, result)

0 commit comments

Comments
 (0)