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 (currently full):
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:
def obfuscate(data,num): from random import randint, choice from string import ascii_lowercase as lo, ascii_uppercase as up ins = [a+b for a,b in list(zip(up,lo)) + list(zip(lo,up))] for _ in range(num): n = randint(0,len(data)) rep = choice(ins) data = data[:n] + rep + data[n:] return data
Noah Morales
import string
def polylen(line): while 1: oldLen = len(line) for c in string.ascii_lowercase: line = line.replace(c + c.upper(), "") line = line.replace(c.upper() + c, "") if len(line) == oldLen: return len(line)
x = open("input").read().strip() best_d = float('inf') for c in string.ascii_lowercase: d = polylen(x.replace(c, "").replace(c.upper(), "")) if d < best_d: best_d = d
Made a quick recursive function too, but if I cared about speed I'd probably check for new local matches instantly after each collapse, which should vastly reduce the overall amount of compares and copies.
Jack Butler
whats the efficient algo for solving day 5? this is my Nim solution part 1: 280ms part 2: 3352ms import sequtils, strutils, tables, threadpool
proc part_one(input: string): int = var stack = newSeq[char]() var offset = 0
fun main(args: Array) { val input = File("day5.txt").bufferedReader().readLines()[0] println("part 1: " + part1(input)) println("part 2: " + part2(input)) }
private fun part1(input: String): Int { val stack = Stack() for (c in input) { with(stack){ if (empty()) push(c) val tmp = pop() if (tmp == c+32 || tmp == c-32){} else { push(tmp) push(c) } } } return stack.size-1 }
private fun part2(input: String): Int { var result = input.length for (c in 'A'..'Z'){ val s = input.replace(Regex("(?i)$c"), "") if (s.length < result){ result = s.length continue } var k = part1(s) if (k < result) { result = k } } return result }
Total: 104ms Part1: 15ms Part2: 78ms
Parker Sanchez
1.2s /w
Cooper Davis
post code
Matthew Wilson
About 13.8s for my less fast haskell
Liam Johnson
>File("day5.txt").bufferedReader().readLines()[0] Why not just File(...).readText() ?
No reason, I've just been copy/pasting my file reading code all week, and they're usually by line. Just changed it, cut about 5-10ms off the paring time
let rec react left c = function | [] -> List.rev (c :: left) | r :: right -> if are_opp c r then match left with | [] -> begin match right with | [] -> [] | c :: right -> react [] c right end | l :: left -> react left l right else react (c :: left) r right ;;
btw. since so little people noticed it was a stack problem, are there any resources that can help you train using basic data structures by posing simple fizz-buzz problems involving stacks, queues, heaps, priority queues, etc? Something on a level that a middle school kid who just learned programming could handle? I know a book like that but it's not in English unfortunately
Eli Garcia
I was asking as in "click on username on leaderboard and see times"
Daniel Lee
>yesterdays task was like hour and half of coding for me. Today it was 15 min for both parts. Yesterday I solved it literally dead drunk in 20-something minutes while I did today in 30 minutes I can't even fucking remember what day 4 was about. My vision was spinning af and I threw up an hour later.
Gabriel Stewart
This is just how it always goes, on average the difficulty seems to go up but there are also local peaks & valleys maybe to give people a day off so to speak
Owen Morales
Well fuck that... After yesterday I was " no need to raise early, difficulty went up so I will not manage to do it before I need to go to work" and today proves me wrong... Now I will have to raise early every day just to check if task is easy or not. fuck this all.
Well... everyones brain works differently I guess.
Landon Scott
since today was the easy one it'll likely go up for a few days again
Ethan Moore
You know what they say - never skip the stack day.
We need more. I'm currently uploading a true big boy input, 10000x the size of the original.
Hunter Sanders
Fuck it. Not taking any chances of missing something as easy again.
Wyatt Perry
I'm ready.
Joseph Brooks
Easy.
Hunter Rogers
>half a gig I guess it's easy to generate the input for this, just needs to be random. Might be neat to propose implementing a specified LFSR for people to generate the same big boy input locally, as an extension to the puzzle. Perhaps a 31 bit one with the highest and lowest bits XORed for the next bit, mod 52 mapped to A...Za...z, symmetrical to ensure endianness has no impact on the random stream. Seed it with 1, and generate half a gig (by base 2 standards). No idea if anyone wants to give it a go, might be some fun.
The puzzle input is not random it's biased towards generating pairs, you wouldn't get a 90% size reduction with pure random inputs.
Michael Reyes
I guess that would be a problem. Defining a constant weighting mechanism is probably out of the scope for this, but it was worth suggesting. Maybe it's not so bad of an idea for a different puzzle.
Jeremiah Ortiz
Latecomer here, are you saving solutions anywhere or do I go back to previous threads to see them?
Connor Martin
I keep all of my solutions locally, but haven't put them in one place online.
Gavin Wood
NPC reporting in. Joined this "adventure" this morning. What did I miss?
react2' :: Char -> (String,String) -> String react2' c (a, []) = a --reverse a react2' c ([], (a:as)) = react2' c ([a], as) react2' c ((a:as), (b:bs)) | a == c || toLower a == c = react2' c (as, b:bs) | isLower a && isUpper b && a == toLower b = react2' c (as, bs) | isUpper a && isLower b && a == toUpper b = react2' c (as, bs) | otherwise = react2' c (b:a:as, bs)
react2 c i = react2' c ([], i)
Logan Wood
I'm annoyed that in my stack implementation if you cancel the attempts in part 2 after the resulting stack becomes too big, the extra check negates any time you save by doing it.
Nolan Stewart
So is 10 seconds a good runtime for a BASH solution?
(define (reduce-r l r) (if (null? l) r (reduce-r (cdr l) (simple (cons (car l) r)))))
(define (reduce l) (reduce-r l '()))
(define (with-removed l c) (length (reduce (filter (compose not (cute same? c )) l)))) (define (part2 l) (apply min (map (cute with-removed l ) (alphabet))))
Everyone using Rust, Haskell etc. is childish. Here's a list of languages that real companies use:
>JavaScript >C# >Visual Basic >C++ >Go (if you're at Google)
Learning a new language takes months, and becoming fluent takes years. Studying gimmick languages is a waste of time and brainpower, especially if they won't get you hired.
65ms with OCaml, a language with a non zero cost abstraction. Are you even trying?
Isaiah Nelson
>Learning a new language takes months Also some hot opinions from this faggot:
>You can teach yourself computer science. >Java is a meme language >Web devs are paid better than software engineers >RUST is a real language how many did I get right?
Hunter Gutierrez
I wrote a horrible O(n^2) solution but at least I'm still in the Jow Forums top 20
Wyatt Fisher
Are you sure you use the big boy input? If so post source code.
John Hughes
why the fuck is everyone's goal to get some shitty job working for in ? you get one fucking life then you die and you're gone forever motherfucker, don't piss that shit away on writing data-shuffling code for people who don't care about you i'd rather do ANYTHING else there are way better ways to have fun, and way better ways to improve the world. the corporate option provides nothing of value fuck you
Bentley Phillips
I just want the money, man
Jonathan Morales
Imagine being so out of touch with reality
Samuel Cook
Oh, you're talking of the big boy, sorry. I'm gonna try with sepples.
Owen Walker
This. Believe me, I'd love to be working on the big world-changing type stuff. But it's hard to get there when you grow up poor and everything is a climb. I'm not complaining, but there's a long way to go before I feel comfortable starting to go after the life I really want to have lived all along. That's kind of sad but that's just the way it is. I also hate corporate bullshit, so I'm gonna get in and get out with the resources I need to actually do something valuable with the rest of my time. It's like investing in my own future.
Gabriel Price
Nice bait
James Ramirez
I'm learning some things from you fellow rust user.. I spent a while trying to figure out how to run code inside an arm of a match statement. That "if let Some(&)" is pretty nice.
I also hooked into rayon to mutlithread part two out for free.
Use two indexes src and dst, src is the current character you are examining, dst is the last character that you added (starting at -1) >if dst < 0 then buf[++dst] = buf[src] >if tolower(buf[src]) == tolower(buf[dst]) then dst-- > otherwise buf[++dst] = buf[src] Something like this, haven't tested it.
Christian Sanchez
Oh fuck that's neat, I actually applied the same technique some time ago but forgot about it. Guess yesterday turned me into a pajeet.
Wyatt Brooks
Using my Rust solution from here: Part 1: 43563512 Part 2: 41818510 Time: 8.23s
Nicholas Wood
note that the quadratic solution is completely fine with the puzzle input if you are coding in C
Oliver King
You're off by 1
Thomas Hughes
BLAZING speed my haskell solution took 4m3s
Blake Clark
and apparently it wasn't off by one either 43563511 41818509
Bentley Johnson
I'm optimizing my solution but I don't know why I'm getting the wrong output. can anyone help import sequtils, strutils, threadpool
proc part_one(input: string): int = var stack = newSeq[char]()
for ch in input: if stack.len == 0: stack.add(ch) elif stack[stack.high] == ch: stack.del(stack.high) else: stack.add(ch)
return stack.len
proc async_helper(input: string, ch: char): int = var stack = newSeq[char]()
for i in input: if i == ch: continue elif stack.len == 0: stack.add(i) elif stack[stack.high] == i: stack.del(stack.high) else: stack.add(i) return stack.len
proc part_two(input: string): int = var count_t: array[26, FlowVar[int]] var smallest: int
for i in 'a'..'z': count_t[ord(i) - ord('a')] = spawn async_helper(input, i) sync() smallest = ^count_t[0] for i in count_t[1..25]: if ^i < smallest: smallest = ^i return smallest
let input = readFile("biginput.txt").strip.toLowerAscii echo part_one(input) echo part_two(input)
Chase Turner
>0.5GB Fuck off.
Leo Young
SEETHING brainlet alert
Ryan Reyes
not my fault when you retarded nigglet have a \n at the end. the input must only be ascii letters.
Brandon Reed
What's the problem? The rustard did it in 8 seconds.