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.
The new leaderboard with empty space is join-code: 43046-941b8011
The old (full) leaderboard is join-code: 194764-c554ff91
public static long generateNumber(char generator, long prev, int part) { long factor = (generator == 'A') ? 16807 : 48271; long modulo = (generator == 'A') ? 4 : 8; prev = (prev * factor) % 2147483647; if(part == 2) while((prev % modulo) != 0) prev = (prev * factor) % 2147483647; return prev; }
public static int solve(int part, long A, long B, long mask) { int matched = 0; int loopRange = (part == 1) ? 40000000 : 5000000;
for(int i=0; i
Justin Wright
so what are some actually good ways to achieve the same result without string slicing?
Gavin Evans
See: Bit ops are a thing.
Zachary Watson
I corrected my functions a bit and this is what I have Note how the stable squares in the middle keep their colors
I'll be off to work now, have a good day anons
Jacob Reyes
that was underwhelming.
Brandon Peterson
4256ms for both parts combined. sepples with an i5 2500k. anyone have a fast solution?
Jonathan Turner
make that 685ms with -O3 flag
Aaron Martin
>6x9=42
Leo Robinson
>mod 0x10000 instead of & 0xffff Why's that?
Alexander Bailey
Hitchhiker's Guide to the Galaxy.
Ryder White
The more you get bantsed for sloppy code, the more likely you'll come up with the better answer first next time around (at least in theory)
Josiah Moore
In base 13 it's true
Asher Johnson
Well, I feel like a fucking idiot. I forgot that it was 6*9 specifically.
Carter Allen
I don't think negative reinforcement is as productive at achieving those goals as you think it is.
Colton Harris
mine is similar, 5s on debug and ~550ms with --release on an i5.
cuz that's the first thing I thought of and the compiler is smart enough to optimize it. and-ing 0xffff would have made more sense tho
Chase Brown
It sounds like a fine idea to me
Nathaniel James
Well you could always try the reddit circle jerk if this place is too much for you
Wyatt Diaz
And you wouldn't be wrong. Negative reinforcement CAN work. However, in the most ironic fashion, according to a number of experiments, positive reinforcement is more effective at conditioning than its negative counterpart. Moreover, negative reinforcement tends to create a wealth of other issues down the line.
In a way, it's logical to care about feelings.
The more you know.
Jayden Mitchell
Why? You don't want to bant about bants?
Luke Thomas
>repeating yourself instead of using do-while this is the power of Rust
Elijah Moore
A-at least I finally got to use generators in Python: def dueling_generators(modulo=False): a = generate_value(512, 16807, 4, modulo) b = generate_value(191, 48271, 8, modulo) count = 0 times = 5000000 if modulo else 40000000
for _ in range(times): x, y = next(a), next(b) count += 1 if bin(x)[-16:] == bin(y)[-16:] else 0
return count
def generate_value(default_value, factor, modulo, use_modulo): n = default_value while True: n = (n * factor) % 2147483647 if use_modulo and n % modulo != 0: continue yield n
# Part 1 print(dueling_generators()) # Part 2 print(dueling_generators(modulo=True))
let score = 0; for (let i = 0; i < 5e6; i++) { const scr1 = genA.next().value; const scr2 = genB.next().value; if ((scr1 & 65535) === (scr2 & 65535)) score++; }
console.log(score);
Easton Butler
Please change image for Day 12. It is highly offensive.
John Lopez
Just noticed, but /ourguy/ is number one on the overall leaderboard
Gavin Bailey
oy vey its annuda 40 million think of poor python fags whos cpus where ovened
Jayden Taylor
Good joke, friend. I am sure you have added that image by mistake. You don't want to be an antisemite, right?
Logan Gray
Congrats, user. You're an hero to all of us.
Jeremiah Ramirez
Mehmet / Pajeet hopscotch: A-okay Travelling merchant: OY to the VEY
Daniel Phillips
Behold, the fastest solution in this thread:
#include #include #include #include
long long * aL; long long * bL;
void Loop(long long start, long long * x, int y, int z) { int i = 0; long long a = start; while (1) { a = a * y % 2147483647; if (a % z == 0) { x[i++] = a; if (i == 5000000) { break; } } } }
void ALoop(long long aS) { Loop(aS, aL, 16807, 4); } void BLoop(long long bS) { Loop(bS, bL, 48271, 8); }
int PartTwo(long long aS, long long bS) { int count = 0, i; aL = malloc(5000000 * sizeof(long long)); bL = malloc(5000000 * sizeof(long long));
for (i = 0; i < 5000000; i++) { if ((aL[i] & 65535) == (bL[i] & 65535)) { count++; } }
free(aL); free(bL); return count; }
int main() { clock_t begin = clock(); int output = PartTwo(65, 8921); clock_t end = clock(); double time_spent = (double)(end - begin) / CLOCKS_PER_SEC; printf("%d (%.0f ms)\n", output, time_spent * 1000); }
240 ms when compiled with -Ofast. The big bottleneck here is (a * y % 2147483647); if there was a way to do it with bitwise operations, it could probably break sub-100 ms.
Kevin Young
>BLoop
jej
Wyatt Watson
what other flags?
Ryan Hall
Nice compiler warnings, fuckface.
Dylan Carter
Finished day 14 but my ranking is ass because I was busy with finals til day 10.
Luis Robinson
God I'm retarded, meant to say day 15.
Adrian Ward
man, part 2 took me forever because I stopped after generating 5 million candidates instead of actually sending 5 million to the judge and I just couldn't see my mistake.
Cameron Young
Could anyone point me to some resources about understanding strictness and thunks and shit in Haskell? My first solution overflowed and all the help I could find was variations of
> just make it strict bro! Don't let those thunks get too deep bro!
Evan Howard
15, scala, quick n sloppy due to being in transit p1 var matches = 0 var a = L var b = L for(i
Adrian Young
Yeah. you didn't use enough iterator adapters. fn main() { let gen = |a: u64, b| { (0..).scan((a, b), |s, _| { s.0 = s.0 * s.1 % 2147483647; Some(s.0) }) }; println!( "{}", gen(65, 16807) .zip(gen(8921, 48271)) .take(40000000) .filter(|&(a, b)| (a ^ b) & 0xFFFF == 0) .count() ); println!( "{}", gen(65, 16807) .filter(|&a| a % 4 == 0) .zip(gen(8921, 48271).filter(|&b| b % 8 == 0)) .take(5000000) .filter(|&(a, b)| (a ^ b) & 0xFFFF == 0) .count() ); }
Luis Harris
package main
import "fmt"
func generator(factor, start, div int) func() int { return func() int { for { start = (start * factor) % 2147483647 if start % div == 0 { break } } return start } }
func main() { a := generator(16807, 883, 4) b := generator(48271, 879, 8) count := 0 for i := 0; i < 5000000; i++ { av, bv := a(), b() if (av & 65535) == (bv & 65535) { count++ } } fmt.Println(count) }
Wyatt Peterson
OY VEY SHUT IT DOWN
Hunter Carter
>tfw whole fucking day without electricity.
Bentley Baker
r8 my solution pls no bully
Isaac Peterson
it's basically the same as everyone else's/10
Angel Ramirez
Yeah this day was fucking easy wtf.
Benjamin Nelson
no spaces between operators / 10
seriously WHY do people do this?
David Smith
Elegant but twice as slow as package main
import ( "fmt" "time" )
func main() { o := time.Now() a := 289 b := 629 pairs := 0 iterations := 5000000 arr := make([][2]int, 5000000) i := 0 for i < iterations { a = genA(a) if a%4 == 0 { arr[i][0] = a i++ } } i = 0 for i < iterations { b = genB(b) if b%8 == 0 { arr[i][1] = b i++ } } for _, row := range arr { if row[0]&0xffff == row[1]&0xffff { pairs++ } } fmt.Println(pairs)
fmt.Println(time.Since(o)) }
func genA(i int) int { return (i * 16807) % 2147483647 }
func genB(i int) int { return (i * 48271) % 2147483647 }
Elijah Sullivan
Honestly the only somewhat hard day so far was 7.
Jackson Gonzalez
I've had more trouble with day 11. 7 was on the easier side in my opinion.
Nathaniel Adams
how is your box so colorful?
Ryan Smith
and 7 wasn't even hard, it was just annoying. You could describe the algorithm in a few sentences.
Levi Peterson
I did a hexagonal coordinate problem for my uni's programming competition a few months back. So problem 11 was easy for me.
Michael Roberts
you have to actually complete the challenges to get a cool visualization :^)
John Watson
0 stars brainlet detected
Jonathan Morgan
>mfw only 8 stars
Austin Brown
Show your boxes. boxlets need to apply.
Hudson Taylor
Rate my code for Day 11 ins = input().split(",") dir = {"nw":[0,-1,1],"n":[-1,0,1],"ne":[-1,1,0],"se":[0,1,-1],"s":[1,0,-1],"sw":[1,-1,0]} loc = [0,0,0]
for i in ins: loc[0] += dir[i][0] loc[1] += dir[i][1] loc[2] += dir[i][2]
print(max(loc))
Carson Reyes
patrician box here
Wyatt Cox
...
Austin Wilson
...
Michael Hernandez
neat. I used it as an excuse to fuck around with channels.
go generate(116, 16807, 4, cha) go generate(299, 48271, 8, chb)
for i := 0; i < 5000000; i++ { i, _ :=
Ryan Walker
When you write shit code that takes 70 seconds to run but then you run through pypy and 70 seconds goes down to 2.5 seconds without any changes to the code.
It's just better at some tasks than CPython but keep in mind it's not always faster, I always take my code for a spin through pypy when I'm done with a solution and some days it's actually much slower than CPython.
Dominic Edwards
initially I though the array alignment could have something to do with it, but it's faster only due to hardcoded factor and divisor.
Josiah Ortiz
>but it's faster only due to hardcoded factor and divisor. LOL. Is his the true power of Go?
Jonathan Stewart
>faster only due to hardcoded factor and divisor
Jayden Ward
Yeah, that's plain stupid. Seriously did not expected that. Checked the same in C and it is both the same speed there.
Jack Hall
well at least it compiled fast
Adam Miller
>has a compiler >it is still sometimes slower than the interpreter So this is the true power of python?
Elijah Jones
user...
Daniel Wright
Ok it happens to C as well with -O0, so Go compiler is missing some optimization. Anyone has an idea what could that be?
Carter Hill
generics?
Ayden Cooper
>please register with fagbook, jewgle or your big brother of choice to continue Thanks but no thanks.
Asher Bailey
You wouldn't be able to deal with day 1 anyway.
Charles Cook
...
Ryan Stewart
while you're being a little bitch who won't register a dummy github, we're all enjoying saving Christmas
Ayden Fisher
>(((sjwhub))) >just do it
John Ward
it's ok, you can keep spamming your latest fizzbuzz on /dpt/ instead
Anyone did this adventofcode.com/2016/day/5 ? I finished part 1 easily using openssl MD5 function in C++ but it takes 4.5 seconds to find the password. I feel like there is a better way than hashing everything like a retard.
Thomas Robinson
There is no better way
Logan Carter
Am I understanding this correctly?
>&A Address of A >(uint16_t*) Cast the address of A to a 16-bit unsigned integer (treat A as a 16-bit unsigned integer) >* dereference that pointer
Levi Russell
hashing on more cores hashing on GPU hashing on distributed cluster
Eli Perry
Anything for today's calendar image?
Michael Jackson
>part 2 is even more brute forcing JUST
yeah I'll try using multiple cores latter but I think openssl MD5 function is not parallelizable (is that a real word?)
Ian Ross
No, D5P2 in 2015 was literally "what if you needed to spend a billion more computing power to solve this?"
Jason Long
Did some profiling and modulo was an issue. Seems like compiler knows some tricks for modulo with constants and does some generic algo for variables. Unlike GCC it doesn't pay attention that arguments are constants only that keeps it generic.
Colton Harris
Judge Dredd judging binary numbers
Adrian Perry
Part 2 takes 17 fucking seconds >mfw I imagine the python fags trying to compute the password
Eli Myers
Unless they implement MD5 in Python it shouldn't be a big problem