-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy path79.easy.rb
35 lines (30 loc) · 916 Bytes
/
79.easy.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
# Write a function step_count(a, b, steps) that returns a list or array
# containing steps elements, counting from a to b in steps of an equal
# size. steps is a positive integer greater than or equal to 2, a and
# b are floating point numbers.
# For example:
# step_count(18.75, -22.00, 5)
# ==> [18.75, 8.5625, -1.625, -11.8125, -22.0]
#
# step_count(-5.75, 12.00, 5)
# ==> [-5.75, -1.3125, 3.125, 7.5625, 12.0]
#
# step_count(13.50, -20.75, 3)
# ==> [13.5, -3.625, -20.75]
#
# step_count(9.75, 3.00, 9)
# ==> [9.75, 8.90625, 8.0625, 7.21875, 6.375, 5.53125, 4.6875, 3.84375, 3.0]
require 'pp'
def step_count(a, b, steps)
returnArr = []
inc_amnt = (b-a)/(steps-1.0)
returnArr << a
for i in (1...steps)
returnArr << returnArr[i-1] + inc_amnt
end
return returnArr
end
pp step_count(18.75, -22.00, 5)
pp step_count(13.5, -20.75, 3)
pp step_count(9.75, 3.00, 9)
pp step_count(0.0, 100.0, 25)