{"id":1216,"date":"2010-07-13T20:46:30","date_gmt":"2010-07-14T02:46:30","guid":{"rendered":"http:\/\/bililite.nfshost.com\/blog\/?p=1216"},"modified":"2010-07-23T03:00:56","modified_gmt":"2010-07-23T09:00:56","slug":"learning-scheme-euler-problem-3","status":"publish","type":"post","link":"https:\/\/bililite.com\/blog\/2010\/07\/13\/learning-scheme-euler-problem-3\/","title":{"rendered":"Learning Scheme: Euler Problem 3"},"content":{"rendered":"<p>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 href=\"http:\/\/www.amazon.com\/s\/ref=nb_sb_noss?url=search-alias%3Daps&field-keywords=A+Series+of+Unfortunate+Events&x=0&y=0&tag=bililitecom-20\">A Series of Unfortunate Events<\/a>: 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.<\/p>\r\n<p>But I'm not complaining; everything looks like it's working out well.<\/p>\r\n<p>Going back to Scheme, the next <a href=\"http:\/\/projecteuler.net\/index.php?section=problems\">Project Euler<\/a> problem is:<\/p>\r\n<blockquote>The prime factors of 13195 are 5, 7, 13 and 29.\r\nWhat is the largest prime factor of the number 600851475143 ?<\/blockquote>\r\n<p>And straightforwardly:<\/p>\r\n<pre><code class=\"language-lisp\">(define gpf ; greatest prime factor\r\n  (lambda (n try) ; n is the number to find the factor of; try is the lowest number to try\r\n    (cond\r\n      ((> try (sqrt n)) n) ; no need to try a factor higher than the square root; if we get here, n is prime\r\n      ((divides try n) (gpf (\/ n try) try)) ; divide out the current trial factor and try again\r\n      (else (gpf n (+ try 1))))))\r\n(define euler3\r\n  (lambda (n) (gpf n 2)))<\/code><\/pre>\r\n<p><code class=\"language-lisp\">(euler3 600851475143)<\/code> gives us the answer 6857 pretty quickly.<\/p>\r\n<p>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 <a href=\"http:\/\/community.schemewiki.org\/?call-with-current-continuation\"><code class=\"language-lisp\">call-with-current-continuation<\/code><\/a>, and <em>that<\/em> cries out for some more playing and learning. I'll see what I can do.<\/p>\r\n","protected":false},"excerpt":{"rendered":"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 [&hellip;]","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[14],"tags":[],"_links":{"self":[{"href":"https:\/\/bililite.com\/blog\/wp-json\/wp\/v2\/posts\/1216"}],"collection":[{"href":"https:\/\/bililite.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/bililite.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/bililite.com\/blog\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/bililite.com\/blog\/wp-json\/wp\/v2\/comments?post=1216"}],"version-history":[{"count":2,"href":"https:\/\/bililite.com\/blog\/wp-json\/wp\/v2\/posts\/1216\/revisions"}],"predecessor-version":[{"id":1219,"href":"https:\/\/bililite.com\/blog\/wp-json\/wp\/v2\/posts\/1216\/revisions\/1219"}],"wp:attachment":[{"href":"https:\/\/bililite.com\/blog\/wp-json\/wp\/v2\/media?parent=1216"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/bililite.com\/blog\/wp-json\/wp\/v2\/categories?post=1216"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/bililite.com\/blog\/wp-json\/wp\/v2\/tags?post=1216"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}