Found solution easily in ruby
This commit is contained in:
parent
f80723b7d8
commit
e7200623fc
1 changed files with 43 additions and 0 deletions
43
062.rb
Normal file
43
062.rb
Normal file
|
@ -0,0 +1,43 @@
|
|||
# Algorithm:
|
||||
#
|
||||
# key(x) is the numbers ordered by decreasing value
|
||||
# x=0
|
||||
# while true; do
|
||||
# k = key(x^3)
|
||||
# let (n,xs) = hash[k]
|
||||
# hash[k] := (n+1,xs++[x^3])
|
||||
# if n>=4
|
||||
# break
|
||||
# i++;
|
||||
# done
|
||||
# result = head.snd $ hash[k]
|
||||
|
||||
def key(x)
|
||||
x.to_s.split('').sort {|x,y| y <=> x}.join.to_i
|
||||
end
|
||||
|
||||
x=0
|
||||
|
||||
hash=Hash.new
|
||||
while true do
|
||||
k = key(x**3)
|
||||
if hash[k].nil?
|
||||
then
|
||||
hash[k] = [0,x**3]
|
||||
next
|
||||
end
|
||||
v = hash[k]
|
||||
n=v[0]
|
||||
xs=v[1]
|
||||
hash[k]=[n+1,xs]
|
||||
if n >= 4
|
||||
then
|
||||
puts "BREAK"
|
||||
puts x
|
||||
puts k
|
||||
puts x**3
|
||||
break
|
||||
end
|
||||
x+=1
|
||||
end
|
||||
puts hash[k][1]
|
Loading…
Reference in a new issue