Created
June 22, 2010 09:02
-
-
Save tomohiro/448205 to your computer and use it in GitHub Desktop.
桁区切りとフラグの悪夢
This file contains 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
<?php | |
$month = array_combine( | |
array(4, 5, 6, 7, 8, 9, 10, 11, 12, 1, 2, 3), | |
str_split('001001000000')); | |
$combo = array(); | |
foreach ($month as $m => $flg) { | |
$combo[] = $m . ((boolean) $flg ? '月期' : null); | |
} | |
var_export($combo); | |
/** | |
$ php separate_and_flags.php | |
array ( | |
0 => '4', | |
1 => '5', | |
2 => '6月期', | |
3 => '7', | |
4 => '8', | |
5 => '9月期', | |
6 => '10', | |
7 => '11', | |
8 => '12', | |
9 => '1', | |
10 => '2', | |
11 => '3', | |
) | |
*/ |
This file contains 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 | |
flags = "001000001000" | |
month = %w[4 5 6 7 8 9 10 11 12 1 2 3] | |
combo = [] | |
month.each_index do |key| | |
suffix = flags[key, 1] == "1" ? '月期' : nil | |
combo << "#{month[key]} #{suffix}" | |
end | |
puts combo | |
=begin | |
$ ruby separate_and_flags.rb | |
4 | |
5 | |
6 月期 | |
7 | |
8 | |
9 | |
10 | |
11 | |
12 月期 | |
1 | |
2 | |
3 | |
=end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment