Golden Sun Hacking Community

The Community => Open Discussion => Topic started by: Daddy Poi's Oily Gorillas on 03, December, 2016, 10:36:40 AM

Title: Advent of Code
Post by: Daddy Poi's Oily Gorillas on 03, December, 2016, 10:36:40 AM
So thanks to Luna_blade, we know this started recently... anyone else interested.... ? http://adventofcode.com

[spoiler=My answer (in Python code) to the first part of the Day 1 problem (So don't look until you solve. But the main point is to show that it's short.)]myInput = "R4, R3, L3, L2, L1, R1, L1, R2, R3, L5, L5, R4, L4, R2, R4, L3, R3, L3, R3, R4, R2, L1, R2, L3, L2, L1, R3, R5, L1, L4, R2, L4, R3, R1, R2, L5, R2, L189, R5, L5, R52, R3, L1, R4, R5, R1, R4, L1, L3, R2, L2, L3, R4, R3, L2, L5, R4, R5, L2, R2, L1, L3, R3, L4, R4, R5, L1, L1, R3, L5, L2, R76, R2, R2, L1, L3, R189, L3, L4, L1, L3, R5, R4, L1, R1, L1, L1, R2, L4, R2, L5, L5, L5, R2, L4, L5, R4, R4, R5, L5, R3, L1, L3, L1, L1, L3, L4, R5, L3, R5, R3, R3, L5, L5, R3, R4, L3, R3, R1, R3, R2, R2, L1, R1, L3, L3, L3, L1, R2, L1, R4, R4, L1, L1, R3, R3, R4, R1, L5, L2, R2, R3, R2, L3, R4, L5, R1, R4, R5, R4, L4, R1, L3, R1, R3, L2, L3, R1, L2, R3, L3, L1, L3, R4, L4, L5, R3, R5, R4, R1, L2, R3, R5, L5, L4, L1, L1"

c = [ 0,  0,  0,  0]
d = 0 #Direction facing
for b in myInput.split(", "):
    d += {"L": 1, "R": -1}[b[0]]
    c[d&3] += int(b[1:])

print c #c[0], c[1], c[2], c[3]
print c[0] - c[2] + c[1] - c[3] #Remove the sign.

#Extra:
print d #Difference between L and R turns.[/spoiler]

Edit: Replaced if block with dictionary check, and swapped regex with the more simplified.
Title: Re: Advent of Code
Post by: Luna_blade on 04, December, 2016, 07:33:10 AM
Do you write super short Python, or is it naturely this short?
Title: Re: Advent of Code
Post by: Daddy Poi's Oily Gorillas on 04, December, 2016, 11:49:25 AM
Um? Both? Well, it depends on the coder... ( For example, someone who divides things up might code like https://github.com/jldork/Advent_04/blob/master/room.py , but that's a spoiler for today's AOC. ... And yeah, I looked on reddit to see what everyone's talking about. :) )

Someone else also tried Day 1, and their code was a bit longer than mine... They had written out if blocks for the caps, where-as I just &3.

My Part 2 for the Day 1 challenge was a bit longer than Part 1 as well... I didn't look into much optimizations.

[spoiler]import re
a = "R4, R3, L3, L2, L1, R1, L1, R2, R3, L5, L5, R4, L4, R2, R4, L3, R3, L3, R3, R4, R2, L1, R2, L3, L2, L1, R3, R5, L1, L4, R2, L4, R3, R1, R2, L5, R2, L189, R5, L5, R52, R3, L1, R4, R5, R1, R4, L1, L3, R2, L2, L3, R4, R3, L2, L5, R4, R5, L2, R2, L1, L3, R3, L4, R4, R5, L1, L1, R3, L5, L2, R76, R2, R2, L1, L3, R189, L3, L4, L1, L3, R5, R4, L1, R1, L1, L1, R2, L4, R2, L5, L5, L5, R2, L4, L5, R4, R4, R5, L5, R3, L1, L3, L1, L1, L3, L4, R5, L3, R5, R3, R3, L5, L5, R3, R4, L3, R3, R1, R3, R2, R2, L1, R1, L3, L3, L3, L1, R2, L1, R4, R4, L1, L1, R3, R3, R4, R1, L5, L2, R2, R3, R2, L3, R4, L5, R1, R4, R5, R4, L4, R1, L3, R1, R3, L2, L3, R1, L2, R3, L3, L1, L3, R4, L4, L5, R3, R5, R4, R1, L2, R3, R5, L5, L4, L1, L1"
wordList = re.sub("[^\w]", " ",  a).split()

#Part 2
d = 0
mxy =