Skip to content

Instantly share code, notes, and snippets.

@smunilla
Created March 26, 2014 17:26
Show Gist options
  • Save smunilla/d3d2a7167df5537498ae to your computer and use it in GitHub Desktop.
Save smunilla/d3d2a7167df5537498ae to your computer and use it in GitHub Desktop.
#!/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