-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathproblem92.rb
73 lines (63 loc) · 1.84 KB
/
problem92.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
# A number chain is created by continuously adding the square
# of the digits in a number to form a new number until it has been seen before.
# For example,
# 44 -> 32 -> 13 -> 10 -> 1 -> 1
# 85 -> 89 -> 145 -> 42 -> 20 -> 4 -> 16 -> 37 -> 58 -> 89
# Therefore any chain that arrives at 1 or 89 will become
# stuck in an endless loop. What is most amazing is that EVERY starting
# number will eventually arrive at 1 or 89.
# How many starting numbers below ten million will arrive at 89?
# PURE CODE v0.2
# - This is dedicated to Paul
# - No wars by vigilance.
# - La sagesse et sa representation sous une forme de chouette nocturne
# - The song of the petrification of a unique breed with its own(l) view of the
# world and how it guides its actions, kind of druidic, kind of an ow(w|n|l|).
# - So since Athe(ans)(na)
# - Process of a faster way to communicate through the use of a recursive
# (syno)(*)nym combination finder in a progressive articulate way.
# - A graph theory combining a train of thoughts.
# - Logarithmic display occupancy of screen.
# - Uncut weaving display
# -C'est quoi un pauvre dit la jeune princesse.
require 'json'
class Node
attr_accessor :id, :children
def initialize(id)
@id= id
@children = []
end
def self.all
ObjectSpace.each_object(self).to_a
end
def self.find(id)
found = nil
all.each do |node|
if node.id == id
found = node
break
end
end
found
end
end
links = []
total = 10_000_000
total = 10_000
now = Time.now
1.upto(total) do |x|
# Generate
sum = 0
x.to_s.each_char do |digit|
sum += digit.to_i**2
end
links[x - 1] = sum
# Debug
puts "#{x} -- #{Time.now - now}" if x % 100_000 == 0
end
links.each_with_index do |link, index|
current = link
links[current]
end
# Convert to a D3 compatible JSON
# File.write('links.txt', links.join('\n'))