Just another update
This commit is contained in:
parent
a25938f123
commit
00a190b0a6
6591 changed files with 94363 additions and 23227 deletions
6
Task/Map-range/Ruby/map-range-1.rb
Normal file
6
Task/Map-range/Ruby/map-range-1.rb
Normal file
|
|
@ -0,0 +1,6 @@
|
|||
def map_range(a, b, s)
|
||||
af, al, bf, bl = a.first, a.last, b.first, b.last
|
||||
bf + (s - af)*(bl - bf).quo(al - af)
|
||||
end
|
||||
|
||||
(0..10).each{|s| puts "%s maps to %g" % [s, map_range(0..10, -1..0, s)]}
|
||||
3
Task/Map-range/Ruby/map-range-2.rb
Normal file
3
Task/Map-range/Ruby/map-range-2.rb
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
(0..10).each do |s|
|
||||
puts "%s maps to %s" % [s, map_range(0..10, -1..0, s)]
|
||||
end
|
||||
|
|
@ -1,9 +0,0 @@
|
|||
def map_range(a, b, s)
|
||||
af, al, bf, bl = a.first, a.last, b.first, b.last
|
||||
bf + (s - af).*(bl - bf).quo(al - af)
|
||||
end
|
||||
|
||||
11.times do |s|
|
||||
s *= 1.0 # force floating point
|
||||
print s, " maps to ", map_range((0..10), (-1..0), s), "\n"
|
||||
end
|
||||
Loading…
Add table
Add a link
Reference in a new issue