Skip to content

Commit a61dab0

Browse files
committed
1 parent 4bc245f commit a61dab0

23 files changed

+3471
-0
lines changed

day1/input.txt

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
(((())))()((((((((())()(()))(()((((()(()(((()((()((()(()()()()()))(((()(()((((((((((())(()()((())()(((())))()(()(()((()(()))(()()()()((()((()(((()()(((((((()()())()((((()()(((((()(())()(())((())()()))()(((((((())(()())(()(((())(()))((())))(()((()())))()())((((())))(()(((((()(())(((()()((()((()((((((((((())(()())))))()))())()()((((()()()()()()((((((())())(((()())()((()()(((()()()))(((((()))(((()(()()()(()(()(((())()))(()(((()((())()(()())())))((()()()(()()(((()))(((()((((()(((((()()(()())((()())())(()((((((()(()()))((((()))))())((())()()((()(()))))((((((((()))(()()(((())())(())()((()()()()((()((()((()()(((())))(()((())()((((((((()((()(()()(((())())())))(())())))()((((()))))))())))()()))()())((()())()((()()()))(()()(((()(())((((())())((((((((()()()()())))()()()((((()()))))))()((((()(((()))(()()())))((()()(((()))()()())())(((())((()()(())()()()(((())))))()())((()))()))((())()()())()())()()(()))())))())()))(())((()(())))(()(())(()))))(()(())())(()(())(()(()))))((()())()))()((((()()))))())))()()())((())()((()()()))()(((()(()))))(())()()))(((()())))))))))(((())))()))())()))))()()(((())))))))()(()()(()))((()))))((())))((()((())))())))()()(()))())()(()((()())(()(()()())())(()()))()))))(()())()()))()()()()))(()(()(()))))))()(()))()))()()(()((())(()(())))()(((())(())())))))()(()(()))))()))(()()()(())()(()(())))()))))()()(((((())))))())()())())())()())()))))()))))))))())()()()()()()())))()))((())()))())))()((())()))))()))())))))))())()()()))()()(()((((()(((((((()(())((()())((()()))()))))(())))()()()(())((())()())))(())))(())))(((()()))()(())(((()(()))((())))())()))((((()))())()))))))))()(())())))(()))()(()()))())()()(())())))())()()(()())))()((()())(()(())(())))))))))))))(()))))()))))))()()())(()(((((()(()())))())()))(()))()))(()()))()())(()))())()(())((()()))))))())))())()(((())))(()(()))()()))()(()))))))((()())(()))))))()())))()()))))))))((((((((()()()(()))))))()())))())))()()((())()))((())(())))())())))()()()((()((()(())))())()(())))))))))()())))()()()()()()))()))((())())(()(()))))))(()()))()))(())))()))))))))))))(()))))))))()))))()))()())()))()()))))))()))))((()))))(()))())()(())))(()())((((()())))()))))(()))()(()()(())))))())))))()))))))())))())))))())))())())))())(()))))(())()(())))())()))((()()))))))())))((())))))))())))(())))))()()())))))())))))()))))))()))()()()(()(((()())())())(()))())))))((()(())(()))))))))(())))()()()())())(()))))()()()))()))())())())()(())))()(((()((((())))))))()))))))))))))))))))))((())()())(()))))()()))))))(()()(())())))())))((())))((())))))))))))))()))))()(()))))))())))))()))(()()())(()())))))))))()))))))(())))))()()))()())(((())))()))(()))))))))(())())))())))())())())()()))((())()(())()())()))()())(())(()))))()())))(()(((()))))))()(()())()()()))()))))))))()()()(())()())()(((((()))()())())(()))))()()()(())))())))()((()())))(()))())()(()())())(()))()()))((()()))((()()()()())))(())()))(()(())))((()()))))))))())))))))())()()))))))))))))))))(())()(())(())()())())()))()(()))))())())))))()())()(()))()()(())))(())())))))(()))))))))))))))())())(())(())))(((()))()))))())((())(()))())))))))())))))())))()))()))))))))))))())()))))()))))((()))(())))()(())))(())()))()))())))())))))))()(()())())))()()())))(())))))(()))))))))))))(()))()))()))())))(((()()()(())((()())))()())(((()))(())()))((()()()())))())(())(()))))()(((((())))(()))())())))))))((((()()()))())())()(()(()())))))))))()())())))(())))()())(((()(())())()()))())())))))))((()())((()()(()))(()(())))()))()))(()))(()))()()(()(((())((((()))()(()))((())()(()(()())()(()))()())))))(()))()))())()())))())))(())))((())(()())))))()))(())(()))()())()(()()((()(()))))))()(())(()())(())()))(((())()))(()()(()()()))))(()(())))()))))())))))())(()()()()()()(((())))(()()))()((())(((((()()())))(()))(()))()()))(((())())()(((()()()()))))(()))(())())))()())(()()())())))))))()))))((())))()())(()))(()(()))())))))())(())))))()()())())()))()()(())))(()))(())((((((())(()))(()))())()))(()()(())))()))(()()))()))()(())))(())))((()(()))(())()()())())))(((()()())(())()))))))()(((()(((((()()(((())(())))())()((()))))((()())()(())(((())))(((()((()(()(()))(()()))())(()))(())(())))()))))))((((()))()((((()(()))()))()()))))()(()(()))()(()((()(((()(()()(((()))))()(((()(()(()(((()(()())())()()(()(()())())(()((((())(()))()))(((((()()())(())()((()()())))()()(((()()))()((((((((()(())))())((()))))(())))(()))))((()((((()()(())(((((()))(((((((((((((()())))((((()(((()((())())()))((()))()(()()((()()()()(()()(()(()(((())()(()((((((()((()()((())()((((()((()()(()()())((()()()((()((())()(()(((()((())((((())(()))((()(()))(()())()((((((((()(((((((((((()))(()(((()(()()()((((())((())()())()))(())((())(()))(((()((()(())))(()))))((()()))))((((()(()(()())(()(())((((((((()((((()((()(((((()))())()(()))(()()((()(())(((((()(())()(((((()()))))))()(((())()(()()((((())()((())((()(((())(((()))((()()((((()(())))))((()((((()((()((()(((())((()))(((((((()(((()((((((((())()))((((())(((((()((((((((()(((()((()(((()()(((()((((((()()(()((((((((()()(()(()(())((((()())()))))(((()))((((())((((()())((()(())()((()((((((()((((((()(())))()())(((())())())()(())()(()())((()()((((())((((((())(()(((((()((((())()((((()(()(())(()())(((())()((())((((()))()((((((())(()(((()(((()((((((()(((()))(()()())())((()((()())()((((())(((()(()(((((((((())(())))()((()()()()(())((()))(((((((()(((((((((()(()))))(()((((((((()((((()((()()((((((()()(((((((()(()(())()(())((()()()((()(((((()())()(((((()())()()((()(()())(()()()(((()()(((((()((((((()()((()(()()()((((((((((((()((((((((()()(((()())))()(((()()(())())((((()((((()((((()()()(())(())((()(()(((((((((((((((()(())(())))))()()))((()(((()(())((()(((()(()()((((()()(((()(((()(((((()()((()(()(((()))((((((()((((((((()((()((())(((((()(((())(())())((()()))((((())()()((()(((()(((((()()(((()))(((()(()(((((((((((((()))((((((((()(((()))))())((((((((((((())((())((()())(((())((())(()((((((((((()(((())((()()(()((())(((((((((((()))((((((((((((()(()())((()((()((()(()(((()((((((((()()(()((()(()(((()))((()))(((((((((((((()(())((((((())(((()(())(()(()(()((()()))((((()((((()((((())))())((((()((((()))((((((()((((((()((()(((())))((())(()))(()((()((((()((()(((()()))((((()()()(((((((())(((())(()))())((((()())(((()(((((((((((()(()(()((()(((((((((((((((()()((((()((((((((()(((()()((()((((()))(((()(())((((((()((((())()((((()((()))(())()(()(((()((())())((((((()(()(())())(((())(()(()())(((((()((()((())()())(())))(((()(())))))))(((()(((()))()((()(((()()((()())()()))())))(((()))(()(((()(((((((((()(()(((((()()(((()())()()))))()(((()))(((()(()(()(()(()))()(())()))(()(((())))(()))))))))))(())((()((())((()(())()(())((()()((((()()((()()))((())(((()((()(())(())))()(()(((((()((()))())()(((((()()(((()(()((((((())(()))(())()))((()(()()))(())())()))(((())))(()((()(((())(())())))((()()((((((((((((((()((()(()()(()(((()))())()()((()()()(())(()))(()())(((())((())()(())()()(()()(())))((()(((()))))(((()()(()()))())((()((())()))((((()()()())((())))(((()(())(((((()(((((()((()(()((((()()(((()()()(((()())(((()()((((())(()))(((()))(())())((()))(((()((()))(((()()((())((()(((((()((((()()())((()))()((((()((()(()()()(

day1/solution.py

+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
def main():
2+
f = open('input.txt')
3+
content = f.read()
4+
allowed_symbols = {'(': 1,
5+
')': -1}
6+
floor = sum([allowed_symbols.get(symb, 0) for symb in content])
7+
print floor
8+
floor = 0
9+
char = 1
10+
for symb in content:
11+
floor = floor + allowed_symbols.get(symb, 0)
12+
if floor == -1:
13+
print char
14+
break
15+
char += 1
16+
17+
18+
if __name__ == "__main__":
19+
main()

day10/solution.py

+24
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
def main():
2+
input_data = '1113122113'
3+
def look_and_say(look):
4+
prev_digit = look[0]
5+
prev_count = 1
6+
say = ''
7+
for digit in look[1:]:
8+
if digit == prev_digit:
9+
prev_count += 1
10+
else:
11+
say += "%s%s" % (prev_count, prev_digit)
12+
prev_count = 1
13+
prev_digit = digit
14+
say += "%s%s" % (prev_count, prev_digit)
15+
return say
16+
new_input_data = input_data
17+
for _ in xrange(40):
18+
new_input_data = look_and_say(new_input_data)
19+
print len(new_input_data)
20+
for _ in xrange(10):
21+
new_input_data = look_and_say(new_input_data)
22+
print len(new_input_data)
23+
if __name__ == "__main__":
24+
main()

day12/input.txt

+1
Large diffs are not rendered by default.

day12/solution.py

+64
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
def main():
2+
f = open('input.txt')
3+
content = f.read()
4+
numbers = set([str(d) for d in range(10)])
5+
6+
def calculate_total(content):
7+
number = ""
8+
minus_sign = False
9+
total = 0
10+
for symbol in content:
11+
if symbol in numbers:
12+
number += symbol
13+
elif symbol == '-' and not number:
14+
minus_sign = True
15+
elif number:
16+
if minus_sign:
17+
total -= int(number)
18+
else:
19+
total += int(number)
20+
number = ""
21+
minus_sign = False
22+
return total
23+
print calculate_total(content)
24+
25+
# content = '[1,"red",5]{"d":"red","e":[1,2,3,4],"f":5}'
26+
27+
def block_total(char_num):
28+
has_red = False
29+
inside_list = 0
30+
total = 0
31+
number = ""
32+
minus_sign = False
33+
while char_num < len(content):
34+
symb = content[char_num]
35+
if symb == '[':
36+
inside_list += 1
37+
elif symb == ']':
38+
inside_list -= 1
39+
if symb == ':' and 'red' == content[char_num + 2: char_num + 5]:
40+
has_red = True
41+
if symb == '{':
42+
inner_total = block_total(char_num + 1)
43+
total += inner_total[0]
44+
char_num = inner_total[1]
45+
elif symb in numbers:
46+
number += symb
47+
elif symb == '-' and not number:
48+
minus_sign = True
49+
elif number:
50+
if minus_sign:
51+
total -= int(number)
52+
else:
53+
total += int(number)
54+
number = ""
55+
minus_sign = False
56+
if symb == '}':
57+
return (total if not has_red else 0, char_num)
58+
if symb == '}':
59+
return (total if not has_red else 0, char_num)
60+
char_num += 1
61+
return total
62+
print block_total(0)
63+
if __name__ == "__main__":
64+
main()

0 commit comments

Comments
 (0)