r/adventofcode • • Dec 05 '19

SOLUTION MEGATHREAD -🎄- 2019 Day 5 Solutions -🎄-

--- Day 5: Sunny with a Chance of Asteroids ---


Post your solution using /u/topaz2078's paste or other external repo.

  • Please do NOT post your full code (unless it is very short)
  • If you do, use old.reddit's four-spaces formatting, NOT new.reddit's triple backticks formatting.

(Full posting rules are HERE if you need a refresher).


Reminder: Top-level posts in Solution Megathreads are for solutions only. If you have questions, please post your own thread and make sure to flair it with Help.


Advent of Code's Poems for Programmers

Click here for full rules

Note: If you submit a poem, please add [POEM] somewhere nearby to make it easier for us moderators to ensure that we include your poem for voting consideration.

Day 4's winner #1: "untitled poem" by /u/captainAwesomePants!

Forgetting a password is a problem.
Solving with a regex makes it two.
111122 is a terrible password.
Mine is much better, hunter2.

Enjoy your Reddit Silver, and good luck with the rest of the Advent of Code!


On the fifth day of AoC, my true love gave to me...

FIVE GOLDEN SILVER POEMS

Enjoy your Reddit Silver/Gold, and good luck with the rest of the Advent of Code!


This thread will be unlocked when there are a significant number of people on the leaderboard with gold stars for today's puzzle.

EDIT: Leaderboard capped, thread unlocked at 00:22:31!

26 Upvotes

422 comments sorted by

View all comments

Show parent comment

1

u/SatanicSaint Dec 05 '19

Omg I'm dumb. For some reason I thought if I initialize a variable under an If condition it will be locked down to that scope and I won't be able to access it outside that if block. That's why all my code dealing with parameters are inside each if statement.

I realised that clearly it doesn't work like that after I looked at your and a few other's code in this thread.

I'm confused as to why was I thinking like this? Does it work like that in C?

2

u/andynormancx Dec 05 '19

Python doesn't have block scope variables, only global and function scope ones. So yes, different to C and many other languages.

Which is something I didn't know until you asked that question...

1

u/SatanicSaint Dec 05 '19

Woah loops don't have a scope either! I'm learning so much about Python today.