100 Days of Code Day 43
Today’s first exercise was word count. It looked like a perfect use for regular expressions. The community solutions seem to agree. The ones I saw were fancier than mine, but I think mine is more readable.
Bank Account had me running in circles. It was supposed to account for concurrency. I tried all sorts of things with async and await and tried to add other people’s Mutex classes to no avail. Eventually I removed it and it worked because Javascript is inherently single threaded. Don’t ask me how the tests failed before suddenly working when I removed the attempted concurrency.
Difference of squares there are special ways to calculate the parts better (n * (n+1))/2 is for one of the parts. I did it the dumb lazy way. It worked, I moved on.
Perfect-numbers I expected to find fancy ways of computing common denominators. Instead everyone was like me and just added up everything up to half the number where n % m == 0. So I wasn’t actually lazy in my implementation there.
Complex numbers failed me when a/b != a * (1/b). You would think multiplying by the reciprocal would work, but it is different by a small fraction and didn’t pass the test. Some of the formulas were also expressed poorly. Exponentiation for example, I had to figure out that n(a + bi) meant na + nbi. It can get hard when there are too many parenthesis in the mix. In fact, I thought the exponentiation just returned a number at first. That is why I prefer to have it be written like (a, bi) instead of (a + bi) so you know which part is which. Keep the a + bi in math but in computer science, use the comma. When looking at community solutions, the guy I picked was mutating the number while I was returning a new object with the result. I wonder which is the intended result. Don’t get me started about when my test failed because minus zero is not the same as zero. Why can I even have minus zero?
Luhn wasn’t too bad. I did get annoyed when they threw in random alphabet characters into a number string. With that, I am finally on pace to finish the Javascript track by the end of 100 Days of Code. I really need to get ahead because they will be getting hard soon and an extra three or so a week will get difficult to keep up.
Finally, on to the GameBoy stuff. For the first example, I wanted a clean set of code so I copied over his version from the github instead of typing it in. I found that IEF_LCDC is now IF_STAT. I also found out that me copying over the init OAM stuff all the time wasn’t useless. When I ran it I had random corrupted tiles in the way. When I put that back in, they went away. So that was nice. I got the two parallax demos running. I’ll continue with palette fade tomorrow.
| Old | New |
| IEF_LCD | IF_STAT |
| STATF_MODE00 | STAT_MODE_0 |
