-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Andy Herd
authored and
Andy Herd
committed
Dec 26, 2017
0 parents
commit 832bff6
Showing
9 changed files
with
603 additions
and
0 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
--- Day 1: Inverse Captcha --- | ||
|
||
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. | ||
|
||
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. | ||
|
||
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! | ||
|
||
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." | ||
|
||
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. | ||
|
||
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. | ||
|
||
For example: | ||
|
||
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. | ||
1111 produces 4 because each digit (all 1) matches the next. | ||
1234 produces 0 because no digit matches the next. | ||
91212129 produces 9 because the only digit that matches the next one is the last digit, 9. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
import sys | ||
|
||
|
||
def sum_digits_if_identical(digit_one, digit_two): | ||
result = 0 | ||
if digit_one == digit_two: | ||
result = int(digit_one) | ||
return result | ||
|
||
|
||
def get_captcha(input_num): | ||
total_sum = 0 | ||
input_num_as_str = str(input_num) | ||
prev_digit = input_num_as_str[-1] # start with the final digit | ||
for digit in input_num_as_str: | ||
total_sum += sum_digits_if_identical(digit, prev_digit) | ||
prev_digit = digit | ||
return total_sum | ||
|
||
|
||
if __name__ == '__main__': | ||
print('input: ' + sys.argv[1]) | ||
print('output: ' + str(get_captcha(sys.argv[1]))) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
import unittest | ||
from inverse_captcha import get_captcha | ||
|
||
|
||
class TestInverseCaptcha(unittest.TestCase): | ||
def test_1122(self): | ||
start_num = 1122 | ||
expected = 3 | ||
result = get_captcha(start_num) | ||
self.assertEqual(expected, result) | ||
|
||
def test_1111(self): | ||
start_num = 1111 | ||
expected = 4 | ||
result = get_captcha(start_num) | ||
self.assertEqual(expected, result) | ||
|
||
def test_1234(self): | ||
start_num = 1234 | ||
expected = 0 | ||
result = get_captcha(start_num) | ||
self.assertEqual(expected, result) | ||
|
||
def test_91212129(self): | ||
start_num = 91212129 | ||
expected = 9 | ||
result = get_captcha(start_num) | ||
self.assertEqual(expected, result) |