News:

As a consequence of the forum being updated and repaired, the chatbox has been lost.
However, you can still come say hi on our Discord server!

Main Menu

Advent of Code

Started by Daddy Poi's Oily Gorillas, 03, December, 2016, 10:36:40 AM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

Daddy Poi's Oily Gorillas

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.
Golden Sun Docs: Broken Seal - The Lost Age - Dark Dawn | Mario Sports Docs: Mario Golf & Mario Tennis | Misc. Docs
Refer to Yoshi's Lighthouse for any M&L hacking needs...

Sometimes I like to compare apples to oranges. (Figuratively) ... They are both fruits, but which one would you eat more? (If taken literally, I'd probably choose apples.)
Maybe it is over-analyzing, but it doesn't mean the information is useless.


The only GS Discord servers with significance are:
Golden Sun Hacking Community
GS Speedrunning
/r/Golden Sun
GS United Nations
Temple of Kraden

Can you believe how small the Golden Sun Community is?

2+2=5 Don't believe me? Those are rounded decimal numbers. Take that, flat earth theorists! :)

Luna_blade

Do you write super short Python, or is it naturely this short?
"Hear the sounds and melodies
Of rilets flowing down
They're the verlasting songs
Whispering all the time
As a warning that behind some rocks
There's a rigid grap even
Oreads fear the tread"

Daddy Poi's Oily Gorillas

#2
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 =
  • * 1000000 #Random-ish number. But array-size.
    x = 0
    y = 0
    for b in wordList:
        if b[0] == 'R':
            d -= 1
        if b[0] == 'L':
            d += 1
        d = d & 3
        i = int(b[1:])
        while i > 0:
            if mxy[y*1000+x] == 1:
                print x, y
                break
            mxy[y*1000+x] = 1
            if d == 0:
                y += 1
            elif d == 1:
                x += 1
            elif d == 2:
                y -= 1
            elif d == 3:
                x -= 1
            i -= 1[/spoiler]I think the forum BBCode stuff is messing up something. :/ Don't mess with my
  • , forum!

    I don't know all the Python tricks yet, but it is possible it could be even shorter than that.
    Like the L and R checks:
    - Not sure if Python has a ? : operator.
    - Could probably use a dictionary type.
Golden Sun Docs: Broken Seal - The Lost Age - Dark Dawn | Mario Sports Docs: Mario Golf & Mario Tennis | Misc. Docs
Refer to Yoshi's Lighthouse for any M&L hacking needs...

Sometimes I like to compare apples to oranges. (Figuratively) ... They are both fruits, but which one would you eat more? (If taken literally, I'd probably choose apples.)
Maybe it is over-analyzing, but it doesn't mean the information is useless.


The only GS Discord servers with significance are:
Golden Sun Hacking Community
GS Speedrunning
/r/Golden Sun
GS United Nations
Temple of Kraden

Can you believe how small the Golden Sun Community is?

2+2=5 Don't believe me? Those are rounded decimal numbers. Take that, flat earth theorists! :)