Login [Register]
Don't have an account? Register now to chat, post, use our tools, and much more.
It's December again, which means Advent of Code starts again. Advent of Code is "an Advent calendar of small programming puzzles for a variety of skill sets and skill levels that can be solved in any programming language you like.". My teacher thought it would be nice if me and my classmates would solve problems as well, providing it has to be done in C++ (we are even getting points for solving them!). I'm curious whether other Cemetech members are trying these puzzles as well! Smile

Here are my solutions located: https://github.com/PeterTillema/AoE2018
I'll probably not bother when they get more difficult, but at least this first one is easy enough that it's a fun bite-size exercise.
Code:
#!/usr/bin/env python3
import sys
from collections import defaultdict
from itertools import cycle

a = 0
n = 0
hits = defaultdict(int, {0: 1})

for x in cycle(map(int, sys.stdin)):
    n += 1
    a += x
    hits[a] += 1
    if hits[a] == 2:
        print('Found', a, 'twice at index', n)
        break
Day 2 was even easier than Day 1:

Code:
#!/usr/bin/env python3
import sys
from collections import Counter

a = 0
b = 0
for l in sys.stdin:
    a += (2 in Counter(l).values())
    b += (3 in Counter(l).values())

print(a * b)
I'm solving each problem with Jelly for some reason, with the input file supplied on stdin. Solutions are timed with pypy.

Day 1 Part 1 (7 bytes, .4s):
Code:
ƈLпỴVS

Day 1 Part 2 (18 bytes, 8m18s):

Code:
ƈLпỴV©ṪLṙɼṛ/+ƲÐḶṾ

Day 2 Part 1 (16 bytes, .25s):

Code:
ƈLпỴĠẈ2,3e€Ʋ€SP

Day 2 Part 2 (19 bytes, .9s):

Code:
ƈƈ¹Ð¿ỴṖŒcZEƇḢ€Ɗ€LÐṀ

Day 3 Part 1 (55 bytes, 5m15s):

Code:
‘⁹Ѥ¦¶5ñ⁸p6ñ⁸¤ḅȷ¶+3ị⁹Ḷ+ị¶ẋȷ²¤¶ƈƈ¹Ð¿ỴṖ¹⁶eØD$?€Ḳ$€Vñƒ¢>1S

Day 3 Part 2 (46 bytes, [broken?]):

Code:
Ḋs2Ɗ€ZẎ€ṙ2<ɗ/Ạ¶ƈƈ¹Ð¿ỴṖ¹⁶eØD$?€Ḳ¹ƇVƲ€ŒcÇÐḟẎḢ€Æṃ

Day 4 Part 1 (84 bytes, 1.8s):

Code:
15ịñÞ@WŻ60¡ṭɗñƇ@?¶0ị=¶6ịr⁹Ḣ¤‘ṛ¦@⁹Ṫ¤ṭ¶6ị‘;¶ƈƈ¹Ð¿ỴṖṢ¹⁶eØD$?€Ḳ$€VL_20ṠƊŀ@ƒ⁸ṖS$ÐṀḢµṪ×M’$

Day 4 Part 2 (84 bytes, 1.8s):

Code:
15ịñÞ@WŻ60¡ṭɗñƇ@?¶0ị=¶6ịr⁹Ḣ¤‘ṛ¦@⁹Ṫ¤ṭ¶6ị‘;¶ƈƈ¹Ð¿ỴṖṢ¹⁶eØD$?€Ḳ$€VL_20ṠƊŀ@ƒ⁸ṖṀ$ÐṀḢµṪ×M’$

Day 5 Part 1 (11 bytes, 21s):

Code:
ɠṖ;ŒsṪ=ɗ?/L

Day 5 Part 2 (21 bytes, >1d):

Code:
ɠ,`Œtḟ@Ṗ;ŒsṪ=ɗ?/ʋ€`ẈṂ

Day 7 Part 1 (39 bytes, .4s):

Code:
ṖZḟ/Ṃ©ṭṪṭn®Ḣ$Ƈ¶ƈƈ¹Ð¿Ỵf€ØAḊ€µZḟ@/ḢṭÇL’$¿
  
Register to Join the Conversation
Have your own thoughts to add to this or any other topic? Want to ask a question, offer a suggestion, share your own programs and projects, upload a file to the file archives, get help with calculator and computer programming, or simply chat with like-minded coders and tech and calculator enthusiasts via the site-wide AJAX SAX widget? Registration for a free Cemetech account only takes a minute.

» Go to Registration page
Page 1 of 1
» All times are GMT - 5 Hours
 
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum

 

Advertisement