Last active
December 11, 2015 08:08
-
-
Save tatat/4571115 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
#!/usr/bin/env ruby | |
# -*- coding: utf-8 -*- | |
begin | |
page = ARGV[0].to_i | |
raise 'invalid arguments' if page <= 0 || page % 4 != 0 | |
column_width = 5 | |
row_width = 17 | |
result = ['=' * row_width] | |
(page / 2).times do |i| | |
remainder = i % 2 | |
numbers = [ | |
("%03d" % (page - i)).center(column_width), | |
("%03d" % (i + 1)).center(column_width) | |
] | |
numbers.reverse! if remainder == 0 | |
result << "| %s | %s |" % numbers << %w|- =|[remainder] * row_width | |
end | |
puts result.join "\n" | |
rescue | |
STDERR.puts $!.message | |
end | |
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
$ ./ryoumen.rb 24 | |
================= | |
| 001 | 024 | | |
----------------- | |
| 023 | 002 | | |
================= | |
| 003 | 022 | | |
----------------- | |
| 021 | 004 | | |
================= | |
| 005 | 020 | | |
----------------- | |
| 019 | 006 | | |
================= | |
| 007 | 018 | | |
----------------- | |
| 017 | 008 | | |
================= | |
| 009 | 016 | | |
----------------- | |
| 015 | 010 | | |
================= | |
| 011 | 014 | | |
----------------- | |
| 013 | 012 | | |
================= |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment