Through some combination of subconscious neglect and happy coincidence, I discovered that my camera battery was just about dead when I arrived at Burning Man. Thus I made a quick photo tour shortly after arrival and spent the rest of the event blissfully free of any feeling of responsibility to document my adventures.
The small selection of photos I took before the juice ran out can be seen on Flickr.
I’m not going to effuse, but I will admit to being very impressed with Heath Ledger’s Joker (RIP). I didn’t much like Christian Bale or the whole Two-Face story line, but they didn’t ruin an otherwise excellently executed film.
It’s been a while since I came away from a Woody Allen film without mixed feelings. Vicky Cristina seemed to have modest ambitions and achieved them with aplomb. I liked the schtick with the narrator, Barcelona was beautiful, the characters were endearing and believably flawed, the cast was amazing. Having most recently seen Javier Bardem in No Country for Old Men I was also in a permanent state of pleasant surprise at his lack of ruthless killing.
A robust set of functional libraries really makes our lives easier here. Our function for obtaining the count of primes that can be generated by substituting all digits for one particular digit in the original prime takes our number as a string, turns that into a list of digits, removes duplicates, maps a (curried) function onto each of those individual digits and then folds the resulting list with max to find the largest value. You could throw a rock and hit a hundred Java programs that use ten lines to do any one of those operations and we do all four in one concise and expressive line.
object Euler50 extends EulerApp {
val pvec = genprimes(1000000)
val primes = pvec.filter(0.!=)
case class PSum (sum :Int, length :Int) {
def add (prime :Int) = PSum(sum+prime, length+1)
}
def fsum (idx :Int, csum :PSum, lsum :PSum) :PSum = {
if (idx >= primes.length || csum.sum >= pvec.length) lsum
else fsum(idx+1, csum.add(primes(idx)), if (pvec(csum.sum) != 0) csum else lsum)
}
def longer (one :PSum, two :PSum) = if (one.length > two.length) one else two
println(0.until(primes.length).map(fsum(_, PSum(0, 0), PSum(0, 0))).reduceLeft(longer).sum)
}
I had a slightly shorter solution that did not make use of a helper class, but it’s just so easy to encapsulate a bit of data and functionality into a handy little helper that I couldn’t resist.
If Blind Willow, Sleeping Woman was a delicious table d’hôte, then After Dark was a light dinner. That may sound like faint praise, but really I’m just dragging out the metaphor. This was a brief and intense dose of Murakamian goodness.
This one’s been somewhat deconstructed. I originally just wrote a for loop, but then I wanted to make it a bit more functional. Then I wanted to make it a bit shorter. In the end it’s still fairly readable, in an HP calculator, Reverse Polish sort of way.
The Right Thing ™ here was to not rely on the magic of BigInt, but to do the addition modulo 10^10 as well as to compute the powers modulo 10^10, but laziness and the allure of a one line solution won out in the end.
object Euler47 extends Application {
val factors = Array.make(150000, 0)
var idx = 2
while (idx < factors.length) {
for (midx <- List.range(idx+idx, factors.length, idx)) factors(midx) += 1
do idx = idx+1
while (idx < factors.length && factors(idx) != 0)
}
println(1.to(factors.length-3).find(n => factors.slice(n, n+4).mkString == "4444"))
}
Here we do two things: first, use a modified Sieve of Eratosthenes to count up the unique factors of all numbers up to some maximum value (which cheat and choose to be “large enough”). Start with the first prime (2), increment by one the factors cell for all multiples of that number (that’s the for loop right after the while), then scan up the list for the next prime (the next number which has no factors, thus factors(idx) == 0). Lather, rinse, repeat.
The second part is easy (and less clunkily procedural): slide a window up that list of factors looking for four fours.
Fortunately this one is easier to disprove than Goldbach’s other conjecture. If n = p + 2*s*s, we can simply try all values of s from 1 to the square root of n/2 and check whether n – 2*s*s is prime. If so, we try the next larger odd integer until we find the (surprisingly small) value that disproves the conjecture. I’m sure Euler would have disproved it more cleverly, but it also would have taken him more than 26 milliseconds.
Wall-E had a slightly different feel from previous Pixar films. A bit more dystopian and contemplative. They accomplished a lot with very little dialog which gave the first half of the film a nice air of mystery. The second half was a bit more on formula, but still excellent all around. Score another one for Pixar.
Erin and I traveled across Russia on the Golden Eagle Trans-Siberian Express this June and we have the pictures to prove it. At the time of this posting, they’re not fully annotated, but I can’t imagine anyone will want to reexperience all 360 hours of travel across Russia in picto-narrative form anyway, so just look at the thumbnails and see if anything jumps out at you.