CatEye and Project Euler

Though very painfully, I solved project euler question 1 in CatEye - - Here's the source

[load "scm/p.scm"]

[! from-to-step [|x y s|
    if  [> x y]
        {}
        [cons x [from-to-step [+ x s] y s]]]]

[! quick-sort-unique [|xs| 
    if  [xs, null?]
        {}
        [reduce concat 
          { [quick-sort-unique [filter [curry > [car xs]] xs]]
            {[car xs]}
            [quick-sort-unique [filter [curry < [car xs]] xs]]
          }
        ]]]

[! unique quick-sort-unique]

[! [q1] [[[[    
            from-to-step 3 999 3
        ],  concat [from-to-step 5 999 5]
        ],  unique
        ],  sum
        ]]
blog comments powered by Disqus