mirror of
https://github.com/mruby/mruby
synced 2026-06-08 16:11:16 +00:00
2438195289
commit eeb33da43035b5400f8d1830ea52a68691b3a678
Author: John Bampton <jbampton@gmail.com>
Date: Mon Oct 31 23:53:43 2022 +1000
Fix up
commit 80923c8f92a58b2f33a36d6403de7f6341973110
Merge: bc89500f6 416f012f6
Author: John Bampton <jbampton@users.noreply.github.com>
Date: Mon Oct 31 20:12:59 2022 +1000
Merge branch 'master' into ruby-remove-parenthesis
commit bc89500f6357c453b457516452ffcc7fd03fee88
Author: John Bampton <jbampton@gmail.com>
Date: Mon Oct 31 14:39:20 2022 +1000
ruby: remove unneeded parenthesis from methods
50 lines
1.1 KiB
Ruby
50 lines
1.1 KiB
Ruby
# from http://www.bagley.org/~doug/shootout/bench/lists/lists.ruby
|
|
# which is lost long time ago. The past content can be retrieved from
|
|
# https://web.archive.org/web/20040805115204/http://www.bagley.org/~doug/shootout/bench/lists/lists.ruby
|
|
|
|
NUM = 300
|
|
SIZE = 10000
|
|
|
|
def test_lists
|
|
# create a list of integers (Li1) from 1 to SIZE
|
|
li1 = (1..SIZE).to_a
|
|
# copy the list to li2 (not by individual items)
|
|
li2 = li1.dup
|
|
# remove each individual item from left side of li2 and
|
|
# append to right side of li3 (preserving order)
|
|
li3 = Array.new
|
|
while (not li2.empty?)
|
|
li3.push(li2.shift)
|
|
end
|
|
# li2 must now be empty
|
|
# remove each individual item from right side of li3 and
|
|
# append to right side of li2 (reversing list)
|
|
until li3.empty?
|
|
li2.push(li3.pop)
|
|
end
|
|
# li3 must now be empty
|
|
# reverse li1 in place
|
|
li1.reverse!
|
|
# check that first item is now SIZE
|
|
if li1[0] != SIZE
|
|
p "not SIZE"
|
|
0
|
|
else
|
|
# compare li1 and li2 for equality
|
|
if li1 != li2
|
|
return(0)
|
|
else
|
|
# return the length of the list
|
|
li1.length
|
|
end
|
|
end
|
|
end
|
|
|
|
i = 0
|
|
while i<NUM
|
|
i += 1
|
|
result = test_lists()
|
|
end
|
|
|
|
result
|