Last active
December 1, 2017 21:11
-
-
Save lytedev/26395149c108d64e8d674ae0389de4f4 to your computer and use it in GitHub Desktop.
Advent of Code - 2017 Day 1 Solution
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
#!/usr/bin/env python3 | |
import sys | |
def digits(digitString): | |
index = 0 | |
final = 0 | |
while index < len(digitString): | |
ds1 = digitString[index] | |
ds2 = "-1" | |
if index == len(digitString) - 1: | |
ds2 = digitString[0] | |
else: | |
ds2 = digitString[index + 1] | |
if ds1 == ds2: | |
final += int(digitString[index]) | |
print("DS[{}]: {}".format(index, digitString[index])) | |
index += 1 | |
print("Answer: {}".format(final)) | |
if __name__ == "__main__": | |
if len(sys.argv) < 2: | |
print("Please provide an argument with your string of digits.") | |
else: | |
digits(sys.argv[1]) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment