The idea of proving programs correct has been around (and hotly debated) for roughly forty years. The irony is that some proof advocates anticipated by more than thirty years what the agile advocates are now saying: Designing with verification in mind improves the quality of the resulting design. To be even more specific, compare these [...]
The fifth problem from Project Euler asks for “the smallest number that is evenly divisible by all of the numbers from 1 to 20″. The key, for me, was to paraphrase that as “the least common multiple of 1 to 20″. The least common multiple (lcm) of two natural numbers is their product divided by [...]
The fourth task from Project Euler is to find the largest palindrome that is a product of two three-digit numbers. (I’m assuming decimal. ) Name no one man The first sub-task is to determine whether the decimal representation of an integer is palindromic. A direct approach yields this: def reverseInt(n: Int) = { def rev(a: [...]
The previous post began working with problem 3 from Project Euler. The allFactors function produced a list of the prime factors of its argument (all occurrences of all prime factors), such as: scala> val nums = allFactors(96000) nums: List[Long] = List(5, 5, 5, 3, 2, 2, 2, 2, 2, 2, 2, 2) It would be [...]
“The purpose of computing is insight, not numbers.” – Richard Hamming My interest in pursuing this series is not in the numbers, nor the Mathematics, but in the process of constructing reliable solutions. I’m also learning Scala, and want to understand how its hybrid OO/FP nature may offer fresh perspectives to my pursuit of programming. [...]
The second problem from Project Euler asks for the sum of the even Fibonacci numbers which are at most 4,000,000. An aside on the numbers The problem’s description of the Fibonacci sequence is flawed (or at least non-standard); the problem statement begins the sequence with 1 and 2, showing the first 10 terms as: 1, [...]
Inside out This series has used the first problem from Project Euler to look at different programming styles; Part 1 asked questions about the obvious imperative solution, and Part 2 used higher-order functions in a functional approach. This part considers performance to take us in a different direction. Despite their differences in style, all of [...]
Do you have anything to declare? Part 1 looked critically an imperative-style solution to the first problem from Project Euler. This part of the discussion introduces a more functional style, using higher-order functions. The goal is to think more declaratively, familiar territory to any programmer who has used SQL. In the solution from last time… [...]
A rude awakening… When the fire alarm sounded at about 2:00 AM, I didn’t want to think about electrical engineering, hydrology, or locksmithing. I wanted a quick fix. The tiniest of pinhole leaks in the attic water heater drain line had released a fine mist, some of which escaped the footprint of the catch pan. [...]