Not quite, marking a variable as invalid in this context is essentially a job for the type system. For example, in C, you can have a void* which can be null. This can lead to seg faults, and NaN has the same pitfall. Instead, with the Maybe idea above, the type system explicitly makes you handle the NaN case since the type is a discriminated union. This is like `int?` in C#.
HN user
aromogato
5 karma
Posts0
Comments3
No posts found.
How to handle division by zero in a language that doesn't support exceptions? 12 years ago
Eating Lions, Wolves, and Goats Faster 12 years ago
This reminds me of those counting problems in college. First you get an answer by trying examples, writing programs, OEIS, etc. and then you come up with an almost trivial counting proof completely unrelated to how the problem was actually solved.
It is a really cool math problem, and we should be using math to solve it! This problem took me 30 minutes to solve without programming and so I'm only a few minutes off Fortran. (I scale well too since I can now do it in constant time - fine log time if we count reading the input.)
A minor nit to pick: the 1,448,575,636 number is not the number of buyouts. (It looks like the number of nodes in the evaluation graph.)
Spoiler: the answer is 111110110111_2. (edit: had the wrong answer)