Previous thread: adventofcode.com/ >Advent of Code is a series of small programming puzzles for a variety of skill levels. They are self-contained and are just as appropriate for an expert who wants to stay sharp as they are for a beginner who is just learning to code. Each puzzle calls upon different skills and has two parts that build on a theme. You need to register with an account but you can appear as anonymous.
Private leaderboard join code: 368748-e33dcae3 People who are inactive for 5 days will be kicked, but other leaderboards can be made if desired.
Alternative leaderboard for those waiting for inactives to be kicked from the first: 208834-4a1a9383
so if my input is 123 my recipe list looks like this: 7 3 0 1 8 9 2 1 2 3 i have to find 123 in the list and give back the index of the first digit? index = 6?
Dominic Murphy
Go for it. Just woke up and did both parts in ~20 minutes. Felt like a day 2 or 3 level problem
Carson Long
Meant to reply to
Jason Hughes
I get 1326928999 in about 36 seconds. Is this possibly correct?
Liam Peterson
This problem has had the worst wording yet so far. I was so fucking confused what the input was I had to come here to get it explained. In part one I was putting my input as the starting array instead of always using 37.
Dominic Edwards
yes but no you're basically returning the length of the array to the left of the first instance of your input in the scoreboard, which is basically the index at which it starts your scoreboard, however, is wrong, and your result should be 780, not 6 the first 20 items in the scoreboard are 3, 7, 1, 0, 1, 0, 1, 2, 4, 5, 1, 5, 8, 9, 1, 6, 7, 7, 9, 2 in that order
Josiah White
For anyone having issues with part 2, add this as a test: input = 15891, result = 10
Christian Young
That's correct.
John Nelson
>36 seconds Nice. What language?
Colton Clark
go with byte arrays
William Rogers
I did use bytearray in python and it still runs out of memory. Automatic cythonization still loses to pypy, perhaps unsurprisingly, and I couldn't find an easy way to cythonize more. .
Daniel Morales
A
WHOLE
FUCKING
HOUR
The only way I could understand the problem was to keep writing code until it matched the examples. People who solved any part of today within 15 minutes are obviously cheating, because you can't untangle the word mess within that time span.
I'm curious what people in the top 20 of the private leaderboard are using. If you are top 20 post user number and language / editor.
Julian Bennett
Python / spyder / windows 7
Justin Lee
#204638 / Go / Acme
Connor Anderson
Vorname Nachname / python / VS-Code / arch
Ayden Edwards
Actually I misspoke, with the bytearray cythonization becomes possible. Still 4 times slower than pypy for 12345678, but a massive improvement.
Gavin Lee
is first place user still doing this
Jordan Young
Can someone share his input and solution for task 1 and 2?
Elijah Stewart
Yeah, I've tried that already. Terrible idea.
Cameron Martin
Wow, I'm retarded. I read that as advice to "go with bytearrays," rather than the language Go. Thanks for the answer user.
Daniel Robinson
Your puzzle input was 440231. Your puzzle answer was 1052903161. Your puzzle answer was 20165504.
Isaiah Wilson
Some mathy thought about part2: Once the scoreboard is long enough, the path starting from the first 9 scores will eventually converge. This means that the elves always jump over most of the scores on the scoreboard (about ~80% ?), this considerably lowers the memory requirement. Are there any solutions that makes use of this?
Chase Ramirez
*first 10 scores, damn off by one.
Tyler Murphy
Haskell is fun! {-# LANGUAGE PartialTypeSignatures, ViewPatterns #-} module Main where
import qualified Data.Sequence as S import Data.Char (digitToInt) import Data.Digits (digits)
type State = (Series, Int, Int) type Series = S.Seq Int
main :: IO () main = do let subseq = map digitToInt input; input = "030121" let (_, nums) = (head.filter fst.map (match subseq 7)) sets putStrLn $ "Silver: " ++ concatMap show (S.take 10 $ S.drop (read input) nums); putStrLn $ "Gold: " ++ (show.length) nums
next :: State -> State next (xs, u, v) = (xs', f' u, f' v) where xs' = foldl (S.|>) xs (if null ys then [0] else ys) f' j = mod (j + 1 + ret j) $length xs' ys = digits 10 (ret u + ret v) ret = S.index xs
match :: [Int] -> Int -> State -> (Bool, Series) match str i (S.viewr -> S.EmptyR, u, v) = (False, S.empty) match str i (S.viewr -> xs S.:> x, u, v) | last (-1:str) == x = match (init str) (i-1) (xs, u, v) | i > 6 = match str (i-1) (xs, u, v) | otherwise = (null str, xs S.|> x)
I reached for a linked list the moment I saw a growing list and iterators on it. No time for reading the problem and understanding that you only append to the scoreboard.
Eh, why the heck not. I'm not really competing for the score at this point anyway. I didn't have any problems with the tasks so far, but I'm really slow with everything. If anything AoC should pressure me into working on my speed. How do I become faster?
How the fuck are you supposed to be in the top 100? Do you have to solve every problem sub 5 minutes?
Aaron Thompson
I guess you have to be well-prepared. workflow wise and also practice,practice,practice. like /ourguy/ said, any problem he comes across, he has already seen once or twice in almost the same form. and I guess being highly integlligent also helps
Samuel Mitchell
You can look at the per-problem leaderboards to see how fast you would have needed to solve each problem to get points.
Blake Clark
why would you want to? competitive programming is a meme only 3rd worlders are interested in that has no real world usefulness
Nathan Sanders
Who is /ourguy/ and what did he say?
Asher Walker
Also if using an array for part 2 you have to reallocate somehow, since you dont know in advance when you gonna find the sequence
Ian Harris
anonymous user #193354 (first on Jow Forums leaderboard and third global) and he said programming has been his only major hobby since he was ten and he has done lots of competitions.
Andrew Nelson
What programming language does he use?
Levi Sanders
it's a hobby. you could say the same about "competitive ultimate frisbee" having no real world usefulness.
Robert Peterson
std::vector have an amortized O(1) push_back(). It reallocates every time it reaches 2^n+1 elements (in libstdc++). std::deque is also a good candidate, it doesn't need reallocation, but has other problems.
Carter Flores
as far as I know mostly python. he mentioned C once.
Jason Adams
TIL using the encapsulating classes for primitives in Java removes any memory efficiency you might have had.
Like the other user said, you can just use a data structure that reallocates your scoreboard. Do make sure you use an iterator or index that moves with the scoreboard. Or allocate 1GB and be done with it, because if that's not enough you are doing it wrong.
Colton Gomez
i already know about that, but i guess its some kind of autism that makes me want to do every task with as little stdlib as possible, hence my list implementation came up as the idea for this one
Blake Gomez
it's a pity this thread slumbers during the day where are my eurobros and american neets at?
Jonathan Harris
Writing shitcode rather than shitposts
Adrian Foster
I'm here. I just don't really have anything to add. Well, maybe if you want to see and review my shitcode, then feel free to do so: pastebin.com/xmVzcW7w
Gavin King
>tfw not filtered yet
im gonna make it this year boyos
Jaxon Lopez
also all of this "node" bs is leftover from when I tried to implement it with a cyclic list for fun & giggles (boy, it didn't go well) lesson learned: constant factor optimizations matter
Can someone explain to me with simple english what task 2 is looking for?
Gabriel Brown
Basically run the recipe algorithm until the digits of the number you were given appear in it, then return the number of digits before that.
Alexander Ward
Keep adding more scores (numbers) to the scoreboard until you hit the pattern that's asked. return how many scores have been given before (are to the left of) the pattern. That's why "01245" results in "5": the scores 0,1,2,4,5 appear consecutively after 3,7,1,0,1 (the first 5 scores) on the scoreboard.
Brandon Thompson
Thank you very much!
Connor Walker
>because you can't untangle the word mess within that time span. I've had that issue with a few of his past questions. Worst was counting the plant pots on day 12 I believe. It sounded like total cumulative plants found throughout all generations. No he wanted the sum of the "indexes" of the plant pots on the final generation.
The other one was that marble game where they tell you the marbles are "placed in a circle". I thought they were putting marbles in a circle drawn on the ground or something. He meant that if you get to the end of your marbles you loop around to the start again.
is there a better way to measure mem usage than GNU/Linux time??
$ /usr/bin/time -v ./target/release/day14 2688510125 20188250 Command being timed: "./target/release/day14" User time (seconds): 0.51 System time (seconds): 0.01 Percent of CPU this job got: 99% Elapsed (wall clock) time (h:mm:ss or m:ss): 0:00.52 Average shared text size (kbytes): 0 Average unshared data size (kbytes): 0 Average stack size (kbytes): 0 Average total size (kbytes): 0 Maximum resident set size (kbytes): 21564 Average resident set size (kbytes): 0 Major (requiring I/O) page faults: 0 Minor (reclaiming a frame) page faults: 5056 [...] Page size (bytes): 4096 Exit status: 0
21MB BOIS
Wyatt Jackson
My English ain't very good. What is the second part asking?
Mason Williams
>ain't not a word
Dominic Young
english is the only language I speak and I had to read it 10 times myself
if your input is 12345 output how many digits there are before "12345" appears