Golden Sun Hacking Community
June 28, 2017, 01:49:55 AM *
Welcome, Guest. Please login or register.
Did you miss your activation email?

Login with username, password and session length
News:
 
  Home   Forum   DC Wiki Help Search Calendar Downloads Login Register  
Pages: [1]   Go Down
  Print  
Author Topic: Advent of Code  (Read 271 times)
0 Members and 1 Guest are viewing this topic.
Fox
Fox McCloud, the Hacking Doctor
Mercury Clan

Prodigy
*

Coins: 27
Offline Offline

I am: certainly not a Gallant!
Clan Position: Head Gallant
Posts: 2306

« on: December 03, 2016, 03:36:40 PM »

So thanks to Luna_blade, we know this started recently... anyone else interested.... ? http://adventofcode.com

Spoiler for 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.

Edit: Replaced if block with dictionary check, and swapped regex with the more simplified.
« Last Edit: December 04, 2016, 09:07:35 PM by Fox » Logged

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...
View Profile
Luna_blade
The last member of the Luna clan
Luna Clan

Great Member
*

Coins: 0
Offline Offline

I am: Timeless. As in, i don't have much free time.
Posts: 531

« Reply #1 on: December 04, 2016, 12:33:10 PM »

Do you write super short Python, or is it naturely this short?
Logged

++++++++++[>+++++++>++++++++++>+++>+<<<<-]>++.>+.+++++++..+++.>++.<<+++++++++++++++.>.+++.------.--------.>+.>.
View Profile
Fox
Fox McCloud, the Hacking Doctor
Mercury Clan

Prodigy
*

Coins: 27
Offline Offline

I am: certainly not a Gallant!
Clan Position: Head Gallant
Posts: 2306

« Reply #2 on: December 04, 2016, 04:49:25 PM »

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 for Hiden:
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
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.
« Last Edit: December 04, 2016, 05:12:45 PM by Fox » Logged

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...
View Profile
Pages: [1]   Go Up
  Print  
 
Jump to:  

Cbox
Yesterday at 10:52:35 PM
Fox: romhacking changed their appearance? A little bit.  Interesting...
June 25, 2017, 08:29:25 PM
Fox: Not as bad as a "HP to 1" hit... unless it kills you in one hit... but yeah, basically.....
June 25, 2017, 07:34:34 PM
Eon713: Toxic works similarly, first turn= 1/16 damage, 2nd 2/16, 3/16, etc. After a while you literally cannot survive the damage even at full health
June 25, 2017, 05:28:05 PM
Fox: With stacking support. ... So might be different numbers.
June 25, 2017, 04:58:36 PM
Fox: *Looks up* ... I suppose that could work. I had in mind that the damage would be greater than that max HP possible after like....  10? turns. So....random numbers:  5 10 20 40 80 160 320 640 1280 BOOM! (>2000)
June 25, 2017, 03:02:53 PM
Eon713: like toxic from pokemon?
June 25, 2017, 02:14:33 AM
Fox: @early stages = Small... or even no damage at all
June 25, 2017, 02:08:11 AM
Fox: Hm. Random thought of a mechanic like a poisonous snake bite. = Starts out with small damage... and if not treated, does big damage... In real life, waiting a long time makes the *poisonous* snake bite look really nasty, I believe. Or maybe that was some reality(?) tv I was watching once a long time ago....
June 24, 2017, 10:52:03 PM
Fox: Ooh... Salanewt's name is back! Hi Salanewt's name! And hello to you as well Salanewt! ; And yeah, SMF (and name) has been amazing.
June 24, 2017, 07:36:19 PM
Salanewt: Aw, RIP one of the best names this site has ever seen. It was time though!
June 24, 2017, 01:47:25 PM
Fox: 1pt text is great, yeah.... Meanwhile, I start feeling like I want to document GS2's MFT stuff. - Especially listing which file uses which compression format... to kind of get a sense of how gsmagic _could_ work.... Er....
June 23, 2017, 02:25:42 PM
Seto Kaiba: you know I miss how SMF is almost dead now because having 1pt text to hide my true feels was perhaps the best part of web 2.0
June 23, 2017, 04:19:13 AM
Fox: Alright. Sounds good.  I agree it does seem a bit silly.  Sounds more of an April Fools type of thing. (Maybe having an ability for people to change their names limitless times specifically on April Fools is an idea.)
June 23, 2017, 04:09:25 AM
Kain: Sala asked me about the name, I thought it was silly but agreed he could have it only for a week.  Tomorrow his name goes back to Salanewt.
June 23, 2017, 03:29:10 AM
Fox: And yay! Atrius is back! Thanks for the reply. Somehow I didn't notice the recuriveness before.
June 23, 2017, 03:25:29 AM
Fox: @ridiculous name for a week =  Hm? So, how many characters would you say should be the maximum to have a name "permanently"... or better yet... How many characters can a name have on registration?
June 23, 2017, 01:00:50 AM
Atrius: @Javi3, Lo siento, ya no tengo tiempo.
June 22, 2017, 08:57:37 PM
Fox: @conundrum = Think about 8/16/32 bit aligned address, and what that means... Etc.
June 22, 2017, 08:55:23 PM
Fox: @Space manager thought for gsmagic = What a conundrum... Whelp... I'll just do whatever.... Probably would waste more time thinking about preventing bugs than coding anyway. :P
June 21, 2017, 09:30:34 AM
Fox: Because he quit a long time ago and has other priorities?

Affiliates
Temple of Kraden Golden Sunrise
Powered by MySQL Powered by PHP Powered by SMF 1.1.21 | SMF © 2006-2009, Simple Machines Valid XHTML 1.0! Valid CSS!
Page created in 0.079 seconds with 22 queries.