Project Euler

Problem #47

The first two consecutive numbers to have two distinct prime factors are:

14 = 2 × 7
15 = 3 × 5

The first three consecutive numbers to have three distinct prime factors are:

644 = 2² × 7 × 23
645 = 3 × 5 × 43
646 = 2 × 17 × 19.

Find the first four consecutive integers to have four distinct primes factors. What is the first of these numbers?

Erlang: Running time = 37.73s
+%echo

+%prime_list

+%prime_iterator

+%factor

p47()->p47(2,[]).
p47(_,[_,_,_,D])->io:format("~w~n",[D]);
p47(Next,Already)->
	case sets:size(sets:from_list(factor(Next))) of
		4->
			p47(Next+1,[Next|Already]);
		_Else->
			p47(Next+1,[])
	end.

Ruby: Running time = 19.79s
+#PrimeList

+#factors

def p47
  st=0
  i=100
  while(st<4)
    if factors(i).uniq.length==4
      st+=1
    else
      st=0
    end
    i+=1
  end
  puts i-4
end