Unable to load image

r/drama Advent of Code S02E01 - Official DISCUSSION Thread

Ok you Python-using heathens. What did you think for difficulty this time around?

Post your coding atrocities below.

For those of you who missed the early signups. Feel free to join the leaderboard late (though rankings are based on time).

42
Jump in the discussion.

No email address required.

Regex is king:

https://i.rdrama.net/images/17014259927056096.webp

Side note: Nim has a nice bit of syntactic sugar for matching regexes:

import std/re
let regex = re".*?(drama)"
const text = "rdrama.net"
if text =~ regex:
   echo matches[0] # prints "drama"

However, it will only use an existing matches array if it's declared in the enclosing scope, not any scopes above it. This means the array would be recreated every loop cycle, making it several times slower :marseysadge:

Jump in the discussion.

No email address required.

literally, For the first:

https://i.rdrama.net/images/17014402120388875.webp

For the second:

https://i.rdrama.net/images/17014400076768467.webp

Got pretty much the same thing, but couldnt figure out how to do a backward regex cause I suck at regex but go off i guess

Jump in the discussion.

No email address required.

Regex is the way, but I completely admit to getting stuck for a minute because I forgot about match consumption and lookahead and all that shit that you tend not to think about from day to day: https://stackoverflow.com/questions/11430863/how-to-find-overlapping-matches-with-a-regexp

// LOL nope:
let matches = Array.from(line.matchAll(/[1-9]|one|two|three|four|five|six|seven|eight|nine/g));

// Better:
let matches = Array.from(line.matchAll(/(?=([1-9]|one|two|three|four|five|six|seven|eight|nine))/g));
Jump in the discussion.

No email address required.

Link copied to clipboard
Action successful!
Error, please refresh the page and try again.