With that change, we now have the following for noTwos and associated functions. (Oh, yeah... we made the one-digit case special as we did for counting the d-digit Ys, for the same reason, i.e. putting the special case in one place.)
evenNoTwos = [justOnes n (min 3 (n `div` 2 - 1)) | n <- [2,4..]]
noTwos :: Int -> [Integer]
noTwos n
| even n = base
| otherwise = concat [[p, p + tenToThe halfN] | p <- map spread base]
where halfN = n `div` 2
base = evenNoTwos !! (halfN - 1)
spread x = let (a, b) = x `divMod` (tenToThe halfN)
in a * tenToThe (halfN + 1) + b
Did it make a difference? Yes, but... it was a bit slower. By profiling output, 193 ticks instead of 187; time output looked worse, with the best apparently
real 0m0.232s
user 0m0.200s
sys 0m0.028s
Recall that for the previous version, the best was
real 0m0.224s
user 0m0.176s
sys 0m0.044s
On the other hand, looking deeper into the profiler output, before, noTwos and things it called was eating 19.3% of the CPU time, while now that's 7.8%, but to be fair we should include evenNoTwos, which snarfs 7.3%--but still that's a total of 15.1%, which should be a win. Despite total allocation being down, actual memory usage is up, from maybe 6.25 MB to close to 7 MB; we are, after all, keeping more stuff around.
random notes and thoughts, mostly about Haskell these days, of a rather past middle-aged programmer
Subscribe to:
Post Comments (Atom)
Riddler Classic, May 23, 2020—Holy Mackerel!
Another one using Peter Norvig's word list . It turns out that the word "mackerel" has a curious property: there is exactly ...
-
Back in the Cretaceous era I worked at the University of Oklahoma as a student assistant at Remote 1. OU was a [shudder] IBM big iron shop a...
-
You've probably heard about how the notion of sum types (e.g. Algol 68 union s, Rust enum s, Haskell type s) and product types (e.g. tup...
-
Verbal Abuse as Entertainment When I grew up, my parents always told me that there was a sort of person who needed to tear down others t...
No comments:
Post a Comment