Skip to content

Learning Scheme: Euler Problem 3

Been a long time since I last posted; real life has a way of getting in the way. The past few months read like the back cover of A Series of Unfortunate Events: if you don't want to hear about a thwarted move, a house fire, 2 graduations, negotiations for a new job and a carrot salad with lots of garlic, then you should put this down and live someone else's life.

But I'm not complaining; everything looks like it's working out well.

Going back to Scheme, the next Project Euler problem is:

The prime factors of 13195 are 5, 7, 13 and 29. What is the largest prime factor of the number 600851475143 ?

And straightforwardly:

(define gpf ; greatest prime factor
  (lambda (n try) ; n is the number to find the factor of; try is the lowest number to try
    (cond
      ((> try (sqrt n)) n) ; no need to try a factor higher than the square root; if we get here, n is prime
      ((divides try n) (gpf (/ n try) try)) ; divide out the current trial factor and try again
      (else (gpf n (+ try 1))))))
(define euler3
  (lambda (n) (gpf n 2)))

(euler3 600851475143) gives us the answer 6857 pretty quickly.

But this is getting boring; I'm not using the interesting parts of Scheme. This sort of problem cries out for a prime number generator, and that cries out for call-with-current-continuation, and that cries out for some more playing and learning. I'll see what I can do.

jQuery UI 1.8

Well, they released jQuery UI 1.8 two days ago, and now everything is broken. I understand why the changes were made, but it sure is inconvenient. Plugins and posts updated so far:

And on top of that, chili stopped working with jQuery 1.4 and I haven't fixed it yet. Andrea Ercolino was nice enough to send me an updated version, but I haven't gotten around to installing it yet.

Update: got chili to work!

So much for using my spare time to learn Scheme!

A real pain scale

I usually don't blog about medical stuff here, but Allie Brosh's comments about the Wong-Baker pain scale are perfectly on-target. The Joint Commission accredits health care organizations and comes up with intrusive, well-intended but largely pointless standards that the rest of us have to uphold. A sort of "unfounded mandate." One of these is the requirement that we document pain levels in every patient on a scale of one to ten. For pediatric patients, we have this "FACES" scale that starts from a big smile and doesn't even get to a frown until number six. I like Allie's much better.

And her comment about not eating red food when you're sick is absolutely right. Never give your kid red popsicles when they've got a stomach bug; you'll just rush into the ER worried that they're throwing up blood.

Learning Scheme, Euler problem 2

The second project Euler problem is:

Each new term in the Fibonacci sequence is generated by adding the previous two terms. By starting with 1 and 2, the first 10 terms will be: 1, 2, 3, 5, 8, 13, 21, 34, 55, 89, ... Find the sum of all the even-valued terms in the sequence which do not exceed four million.

Continue reading ›

Learning Scheme

OK, so my new mini project is to learn Scheme. It can't be too hard, right? I mean Javascript is just Lisp in C's clothing, and I'm good at Javascript. I've installed PLT-Scheme and I figure the best way to learn it is solving Project Euler problems until I get bored.

Continue reading ›

The Quicken, the Dead

I've been using Quicken for years, since Quicken 97 on Window then Quicken 5 on the Mac and then Quicken 2001 when I got my iMac. The problems is that Intuit doesn't upgrade Quicken, it replaces it each year with a version that has more frilly bells and whistles and less real utility (especially on the Mac; just look at the "Using a prior version of Quicken Mac?"). And the datafile is often different from the old file, so stuff gets lost with each "upgrade".

So I've kept my current Mac (a blue & white G3, the "Mickey Mouse" one) just to be able to run Quicken 2001 under Classic. I can't upgrade to an Intel Mac, since Classic won't work. And I want to balance my checkbook while talking to my wife, not only downstairs in my basement office. So I wanted something I could run on my dual-boot (XP and Ubuntu) laptop.

I've been looking at alternatives to Quicken for 5+ years, but with 20 years of data I was too scared. Until now. I've been using gnuCash for just a week now, but it seems to everything I need it to, including importing all my data, even from multiple investment accounts, from Quicken's exported QIF file. I haven't done any complicated investment things, so I don't know how well that side of it works.

Strong points

  • It Just Works. Does what I expect it to do, in the way I expect it to. Of course, I'm a geek who understands double-entry bookkeeping, so that may not be surprising.
  • I can control-S and save the file; I always felt out of control with Quicken since you couldn't force it to save.
  • Open source. I will probably never have the time to tinker, but it's nice knowing that I could

Weak points

  • Keyboard shortcuts. I miss being able to assign my own keystrokes; I hate going back to the trackpad to do anything. But see Open Source above; I can probably fix that.
  • I'm going to have to learn Scheme to create custom reports. Not sure if that's a bug or a feature.

The biggest advantage is the feeling of freedom of not being tied to Intuit anymore. I'll see how it works out, but I'm not going back.

Jewish History from a Unique Perspective

My children's Jewish history teacher, Rabbi Yonason Goldson has been teaching at Block Yeshiva High School for many years and presents Jewish history with a mix of traditional and scholarly sources, always from a Torah-true perspective and always looking at the broad sweep of history and the Jews' role in it. He has now published his notes (which I have always found fascinating) in book form, as Dawn to Destiny: Exploring Jewish History and its Hidden Wisdom. I'm looking forward to reading it.

From the publisher's summary:

A comprehensive overview of Jewish History from Creation through the redaction of the Talmud, illuminating the intricacies and complexities of Torah tradition and philosophy according to the sages and classical commentaries, spanning the length and breadth of Jewish experience to resolve many of history’s most perplexing episodes, offering profound insights and showing their relevance to life in the modern world. An invaluable resource for scholars and laymen. A priceless tool for education and outreach.
How did the sin of Adam transform mankind and the world? How were the prophecies of Noah fulfilled through the rise of the Greek Empire? How did the builders of the Tower of Babel believe they could wage war against G-d? Why did there have to be three patriarchs? What was King David's crime regarding his involvement with BasSheva? Why did some Jews oppose the construction of the Second Temple? How can we trust the transmission of Torah if our scholars engaged in such fierce disagreements? These and many other questions are answered in this unique volume.

Engauge Digitizer Tutorial

A simple walkthrough to use the Engauge Digitizer to pull values off a "printed" graph

There's a far more complete manual that comes with the download, but these are the steps I used to generate the data for the webservices graphs. It assumes you've got a black and white image of the graph, with continuous lines for the data and orthogonal gridlines, and linear axes.

Continue reading ›

Digitizing graphs

I wanted to add Down Syndrome growth charts to the bililite.com webservices, but as far as I can tell, the charts are available only as images in the AAP's guidelines (and the original paper; subscription only). The often-cited growthcharts.com has charts, and Greg Richards was generous enough to share his data with me. However, some of the data are from a different study, and he got his data from the original charts the old-fashioned way: with pencil, ruler, and a blown-up copy of the paper. Nothing wrong with that; that's how I got my numbers for the bilirubin chart, but I wanted all my charts to match the AAP's.

So how to get the numbers off the graph? I emailed the lead author of the original paper, but haven't gotten any answer. I can pull the graphs as gif's from the PDF of the paper (thanks to OpenOffice.org and Sun's PDF importer; Adobe's reader seems to get more limited with each upgrade). I was afraid I would have to digitize the graph by hand; I read the cool article on Sudoku recognition and figured I could learn about Hough transforms to get the graph, and 2-D Fourier transforms to remove the gridlines, then blob detection to find the lines. Turning pixels into measurements would be the trivial last step. Sounds like fun, if I had an infinite amount of free time.

Luckily, I found Engauge Digitizer. With almost no time reading the manual, I had it removing gridlines, digitizing the curves on the graph, and exporting values at x-values that I selected into CSV files. It was close to easy. Not quite automated, but with only 4 graphs to digitize, I was done in half an hour. Highly recommended. With my remaining free time, I'll write a quick tutorial so I don't forget what I did.

Parsing the HTTP Accept: header

I wanted the webservices to be as RESTful as possible, so they should use the Accept: header rather than file name extensions to determine the type. Continue reading ›