-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdur_visualizer.rb
More file actions
68 lines (60 loc) · 1.5 KB
/
dur_visualizer.rb
File metadata and controls
68 lines (60 loc) · 1.5 KB
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
require_relative 'duration_utilities'
class ExplodableArray < Array
def rot(n)
m = n % self.length
self.last(self.length - m) + self.first(m)
end
def explode(n)
this = []
1.upto(self.length) do |x|
k = self[(x* n-1 ) % self.length]
this.push(k)
end
return this
end
def collect_explosions
exploded_hash = Hash.new
selection = self.length.get_exploder_values
selection.each {|x| exploded_hash.store(x, self.explode(x))}
return exploded_hash
end
end
def exploded_array(input_array, index, startval, endval, precision)
totval = 0.0
thing = []
this = []
runningtot = []
1.upto((input_array.length)) do |x|
k=input_array[(x*index-1) % input_array.length]
nextvalue = startval * (endval/startval)**((k-1)/(input_array.length-1.to_f))
nexttrunc = nextvalue.round_to(precision)
this.push(nexttrunc)
totval+=nextvalue
runningtot.push(totval.round_to(precision))
end
thing.push(this)
tottrunc = totval.round_to(precision)
thing.push(tottrunc)
thing.push(runningtot)
end
=begin
puts "Provide the starting value"
initial = gets.chomp!.to_f
puts "Provide the ending value"
final = gets.chomp.to_f
puts "Provide the precision"
places = gets.chomp.to_f
while ok_user == false
my_array = [1,2,3,4,5,6,8,9,10,11,12,13].shuffle
my_array.push(7)
my_array.display
puts "Is this ok?"
if /[yY]/.match(gets.chomp)
ok_user == true
break
end
end
puts ""
1.upto(12) {|x| puts exploded_array(my_array, x, initial, final, places).display
}
=end