Log in

tachikoma valentines

Project Euler

Project Euler is a countable collection of problems, requiring a mix of mathematical reasoning and machine computation to solve.  Every once in a while, I get the urge to try to grow the subset of problems I’ve completed.

At only 85 solved, I’m still solidly within Level 2, which is not enough to make it into their permanent rankings yet.

For the most part, I write my calculations in Haskell, falling back to C when I’m unable to express an algorithm in anything but imperative form.

However, there is this very interesting language out there going by the un-Google-able name of J:

999999 A. '0123456789'

5 solutions to 5 problems in 5 lines, much more succinctly stated than would be possible in any other language.  (Largest prime factor of 600851475143; sum of primes under two milion; millionth permutation of 10 digits by lexical sort; how many distinct numbers n of the form xy where 1<x,y≤100; sum of the first hundred rows of Pascal’s triangle.)

The title of last week’s post, A.~(1:I.~([:*./}:<:}.)"_1)@(i.@!@#A.]), is an implementation of bogosort, which is very much not recommended for actual use.

However, quicksort can be written as (($:@(<#[),(=#[),$:@(>#[)){.)^:(1<#); this reads as “when count greater than 1, recurse on items less than and greater than head, joined by items equal in the middle”.

Not that you’d should use that either; /:~ is the built-in sort.