Project Euler

Problem #62

The cube, 41063625 (345^(3)), can be permuted to produce two other cubes: 56623104 (384^(3)) and 66430125 (405^(3)). In fact, 41063625 is the smallest cube which has exactly three permutations of its digits which are also cube.

Find the smallest cube for which exactly five permutations of its digits are cube.

Erlang: Running time = 0.2s
+%digit_split

p62()->
	p62(100).
p62(Next)->
	Cube=Next*Next*Next,
	C=lists:sort(digit_split(Cube)),
	Class=case get(C) of
		undefined->[];
		L->L
	end,
	C2=[Cube|Class],
	if
		length(C2)==5->io:format("~w~n",[lists:last(Class)]);
		true->
			put(C,C2),
			p62(Next+1)
	end.

Ruby: Running time = 0.31s
+#cubes

+#dig_split

def p62
  i=0
  equ=Hash.new([])
  while true
    c=cubes(i+=1)
    d=dig_split(c).sort
    equ[d]+=[c]
    if(equ[d].length==5)
      up=d.join("").to_i
      cc=c
      while(cc<=up)
        cc=cubes(i+=1)
	dd=dig_split(dc).sort
	equ[dd]+=cc
      end
      if equ[d].length==5
	puts equ[d].sort.first
	return
      end
      return
    end
  end
end