This week's book giveaway is in the Spring forum.
We're giving away four copies of Spring in Action (5th edition) and have Craig Walls on-line!
See this thread for details.
Win a copy of Spring in Action (5th edition) this week in the Spring forum!

Tim Cooke

Sheriff
+ Follow
since Mar 28, 2008
Tim likes ...
Clojure IntelliJ IDE Java
Standard Nerd
Belfast
Cows and Likes
Cows
Total received
286
In last 30 days
2
Total given
654
Likes
Total received
1286
Received in last 30 days
21
Total given
422
Given in last 30 days
11
Forums and Threads
Scavenger Hunt
expand Rancher Scavenger Hunt
expand Ranch Hand Scavenger Hunt Green check
expand Greenhorn Scavenger Hunt Green check

Recent posts by Tim Cooke

Yes, done. My hunch was right but not exactly as I first imagined it.
My hunch was that the plant state would repeat so didn't need to compute all the generations, but no
Day 12 Part 1, yup no problem. Part 2, dang I got nothing that doesn't take a bunch of time to run. I do have a hunch though, so I'll be back
Part 2 was a bit of an odd one. I still could not get my program to finish in any reasonable time but I got lucky. I had it print out any new highest power level as it found them and after about 5 seconds the output dried up but the program kept running. As it turned out the most recent output was the puzzle solution. I totally got lucky.
This week, we're delighted to have Craig Walls helping to answer questions about the new book Spring in Action (5th edition).


The promotion starts Tuesday, December 11th, 2018 and will end on Friday, December 14th, 2018

We'll be selecting four random posters in this forum to win a free copy of the book provided by the publisher, Manning.


Image from https://images-na.ssl-images-amazon.com

Please see the Book Promotion page to ensure your best chances at winning!

Posts in this welcome thread are not eligible for the drawing, and should be reserved for welcoming the author. Questions posted in this topic are subject to removal.
2 days ago
I think my Day 11 Part 2 needs some revision as it's been running for quite some time now.....
Oh man that's really frustrating Stephan. I liked yesterday's puzzle too as a demonstration that your choice of data structure can really really really make a difference to your application performance. I couldn't find a linked list in Python so ended up with a little hack using a queue that had very fast head insertion and deletion operations.

For today's puzzle I wrote a function that would generate and print the grid of dots and hashes but I made the mistake of having it print out every single iteration and it took so long generating the first grid (approx 100000 by 100000 item grid) that I quickly abandoned that before any output was generated at all. I took a similar approach to you and only printed anything out when the difference in y values was 10 or less. A guess that turned out to be spot on as it only printed one image and was the one I wanted.
Tee hee Bear successfully poked.

I can say nothing, some of my code is truly a crime against the profession.
Recursion and using variables declared outside of the recursive method Liutauras?

I managed to get part 1 done by simply processing the input sequence from left to right also using recursion to collect all the meta values. It was quite tidy even. But then along came part 2 and blew my design out the water and I had to start again
Day 10 was a fun one. It's a pleasant change of tact when you have to use your eyes to solve it rather than getting the computer to do it. The trick was having the computer present you visibly decipherable information but not too much or too little of it. Part 2 was a doddle.
My initial day 9 part 1 solution used an array, but with insertions and removals mid list it was not efficient. Using this solution part 1 completed in around 0.6 seconds which was ok. Then came part 2. Just increasing the marble count by 100 with my original algorithm really highlighted the problem. After a half an hour I aborted the run and went back to the drawing board. I replaced the array with a python deque (double ended queue), jigged the algorithm to suit it, and viola! 2.5 seconds to the part 2 solution.

If you're wondering how I did mid list inserts and deletions from a queue, well it turns out that a python deque has a rotate function that allows you to quickly rotate the list so that a popleft or appendleft achieves the desired action.
Oh my. Day 9 Part 1 was straight forward enough, but part 2 is a real test to your algorithm efficiency. I believe a data structure rethink is in order here.
Well I don't know Perl at all but you can use any list like structure as a queue as long as there are facilities to take things off one end of the list and put things on the other. I see in perl you can use an array like a queue by limiting use to the push and shift functions.

Day 8 is a welcome relief after yesterday. Straight forward enough, and even quite happy with the solution design too which is a rare thing.