Created
March 26, 2014 17:26
-
-
Save smunilla/d3d2a7167df5537498ae to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/ruby | |
unless ARGV.length > 0 | |
puts "You must specify a number of pages." | |
return -1 | |
end | |
num_pages = ARGV.first.chomp.to_i | |
remainder = num_pages % 4 | |
num_pages += 4 - remainder unless remainder == 0 | |
output = "" | |
count = 0 | |
(num_pages / 4).times do | |
output += "#{num_pages - count}," | |
output += "#{1 + count}," | |
count += 1 | |
output += "#{1 + count}," | |
output += "#{num_pages - count}," | |
count += 1 | |
end | |
puts "#{num_pages} pages are required for a booklet. Print them in this order #{output}" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment