100 Days of Code Day 44
Exercises time. Prime factors, the community did the problem more gracefully than mine.
Grains was ok, but for the last square of the chessboard I was getting the wrong value. It looked like rounding error so I switched to bigint and that seemed to work except I also had to switch from math.Pow to the ** operator. Instead of the for loop I could have done 2^64 – 1 (each square was 2^(n-1) where n is the square number between 1 and 64). For loop still worked. Broke down and did a extra version to change that.
Pythagorean Triplet. This one confused me a bit. We had a random triplet class. I finally figured out they wanted an array of triplet objects returned. How about just saying that in the problem definition. I thought my implementation would take forever to run, it is O(N^2) after all. Well it probably still does but for the test cases it wasn’t bad. The community solutions are fancier than mine, but I can read mine better. I did wonder if walking it backwards from max to min was faster.
Palindrome Products keeps timing out. It is slow and exercism has been failing to run tests on and off today but I can’t get the system to run the test without timing out. I can’t see a way to make it significantly faster without cheating. So I am marking it done and that’s all the exercism for today.
Need about 1.5 exercises/day to keep pace.
Remember yesterday when I patted myself on the back for clearing the sprite data. I just realized the book code didn’t use that because they weren’t activating sprites. I kept copy/pasting the flags from other projects because the hardware constants had changed. So it was still unnecessary I just needed to actually follow what the book said.
Anyway today I got the palette fade demo working, and got the sprites without DMA demo going. I guess I will continue with the DMA sprites next.
Ok, I went back and optimized by palindrome products solution to not check things unless they are a candidate for being larger or smaller than the max/min and got it to finish before the timeout. I also did the anagram exercise to keep up the 5 exercises a day tempo. Really need to get to a 1:1 ratio before they get too hard.
