Previous thread: How do data structures work? edition
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.
>tfw specifically stayed awake until midnight and still didn't make top 100 on either star because of my shitty reading comprehension Feels like I'm free now tbqh; I can do them whenever and still get the same number of points.
Eli Campbell
Rate my first Python program!
input = open("input").readlines()
def part1(): freq = 0 for i in input: freq += int(i) print (freq)
def part2(): freq = 0 prev = [] while True: for i in input: freq += int(i) if freq in prev: print(freq) return else: prev.append(freq)
Isn't it because std::getline will return the line with \n which won't be able to be converted to an int?
Oliver Kelly
def advent1(): set_format("i")
print(sum(column(0)))
frequencies = set([]) result = 0 for freq in itertools.cycle(data): result += freq[0] if(result in frequencies): raise Exception(result) frequencies.add(result) how can i reduce script size further? note that set_format(), column() and data are helpers for reading data, along with some other functions unused here
Jordan Butler
wrong, std::getline split on '\n' by default and removes the '\n'
Eli Kelly
eww yikes your solution doesn't even pass the test cases
Cameron Watson
my guess is one of the line in your input is empty so you're trying to stoi an empty string
My day 2 solution: data = map(int, open("Day 01 input.txt", "r").read().split("\n")) freq = 0 freqs = {} while True: for f in data: freq += f if freq in freqs: raw_input(freq) freqs[freq] = 0
And day 1 is literally just: print(sum(map(int, open("Day 01 input.txt", "r").read().split("\n"))))
Levi Phillips
>Jow Forums is actually leaving the browser tab for this var res = 0; [].forEach.call(document.querySelector('body > pre:nth-child(1)').innerText.split('\n'), (i) => { res += Number(i) }); console.log(res);
Justin Peterson
you mean part1/2 not day hehe
Juan Bell
That's how my brain works. I scan and let my intuition form connections. Many brains work similarly. Others are more focused on details and order. Neither are better than the other. It's just different approaches that have their pros and cons.
Using C for AoC is retarded, and not just as a subset of the way using C for almost anything is retarded >surely there is something like hashtables 8/8 b8; some Cnile will be along shortly to claim that writing hashtables over and over is an advantage of C
Angel Martinez
That's funny
Landon Harris
After I was done, I realized I could have just pasted the text into LaunchBar's built-in calculator to solve the first half.
>over and over Have you ever heard of this concept of libraries?
Jack Thomas
Python++ int part1(std::vector &data) { return std::accumulate(data.begin(), data.end(), 0); }
int part2(std::vector &data) { std::unordered_set memo{}; int i{0}, sum{0}; while (memo.insert(sum += data[i++ % data.size()]).second); return sum; }
int main() { std::vector data{std::istream_iterator{std::cin}, {}}; std::cout
Julian Hill
ghostbin.com/paste/g43n7 On the off chance Jow Forums lets me post the chars: data ¨ ((∼∊∘(UCS 13 10)) ⊂ ⊢) NREAD 'I:\\2018d1.txt' NTIE 0 NUNTIE ¯1 sum +/data sum, 0 {(+≢)>≢T∪,:∩⋄T∇+sum} +\data
If only one could manage sets in the same way it does arrays. May be a fun project.
you can play as user, it literally gives you the choice to while signing up
Nolan Richardson
;)))))));)
Connor Hernandez
WHY THE FUCK WILL YOU USE APL?
Justin Morales
Every time I see eval in an AoC solution I'm reminded of the user who ran an rm -rf from a malicious input last year. Didn't work due to permissions, but still a lesson in exploitation of eval.
Oliver Brown
let me get this clear, part 2. are you looking for a value the frequency lands on two times? the examples are messing me up
Isaac Peterson
>over and over
Christopher King
yes, the first frequency which is repeated
Noah Williams
yes
Jose Stewart
>tfw you didn't have to ask for help in Jow Forums to understand the instructions
yeah when the example says >+3, +3, +4, -2, -4 first reaches 10 twice. it means loop through them >+3, +3, +4, -2, -4, +3, +3, +4, -2, -4, +3, +3, +4, -2, -4 etc.
just make a throwaway r*ddit, they'll ask for an email but you can just leave the box blank
Ayden Adams
i wondered how they generated frequency changes that could have the second part run long enough, especially when they have multiple sets of data for different users. then i saw that the resulting frequencies form a square wave. that's pretty clever.
Logan Young
>>+3, +3, +4, -2, -4 first reaches 10 twice. but it only reaches 10 once? what am I missing...
Jordan Turner
from what i gathered they actually spend a lot of time on generating and testing decent inputs
Angel Cooper
literally read the rest of his post you brainlet retard
Noah Richardson
3. 6, 10, 8, 4, 7, 10
Matthew Rivera
sure, but this data set actually has some though behind it. it's just not brute force. each loop over the frequency changes will shift all resulting freqeuencies by a certain amount (the sum of the frequency changes). by using a square wave it's easy to determine how many loops it will take until the first duplicate resulting frequency is achieved: the amplitude of the wave divided by the sum of the frequency changes
Logan Nguyen
mybe ocaml just sucks
Camden Wright
Yes. But the good thing is you can improve.
Xavier Barnes
Shit, my code is very slow. Please Jow Forums be honest, am I a filthy code monkey?
not completely though, there's a set of inputs that gets distributed
Caleb Cruz
Seriously, I didn't know.
Cooper Stewart
The chances are too low to worry though. Also, it'll call you out for cheating.
Robert Rodriguez
>stay up til midnight to do this shit >wanna see if i can get on the global scoreboard or at least do well on the Jow Forums leaderboard >know from last year people do this shit in like 30 seconds so i have to go fast >open up prompt >5 paragraphs of retarded story shit about santa's elves and time travel at the beginning >skip to bottom >crank out solution >part 2 >looks like first paragrah is more dumb story solution >skip to bottom >crank out solution >didn't work
i'm assuming this is how it went for most people, they're intentionally speedreading to get a good time because the prompt has a lot of pointless flavortext
Josiah Martin
Little improvement using hashtable instead of a set. Maybe I should code it in C++.
$ time ./aoc1 XXXXXXXXXXXXX XXXXXXXXXXXXX
real 0m0.072s user 0m0.068s sys 0m0.004s
Cooper Jones
the series repeats r*tard
Zachary Harris
ok, gofag here Replaced going over a fucking list with a map and it seems to work perfectly. aoc$ time (./advent1 < input) 0m00.10s real 0m00.12s user 0m00.02s system
Logan Brooks
The first input is the first input?
Cameron Thomas
so who here made the fastest solution?
Isaac Flores
The Fortran guy.
Sebastian Campbell
First time writing rust, anyone have any pointers for any bad stylistic things I did?
use std::fs; use std::collections::HashSet;
fn main() { let contents = fs::read_to_string("input.txt").unwrap(); let lines: Vec = contents.split("\n").collect(); let digits: Vec = lines.into_iter().map(|x| x.parse::().unwrap()).collect(); let mut cum_sum: i32 = 0; let mut prev_vals = HashSet::new(); prev_vals.insert(cum_sum);
for xx in digits.iter().cycle() { cum_sum += xx; if !prev_vals.contains(&cum_sum) { prev_vals.insert(cum_sum); } else { println!("The first repeating value is {}", cum_sum); break; } } }