Created
May 29, 2017 19:01
-
-
Save cia-rana/82434d1684db8d5faafb9daef7855140 to your computer and use it in GitHub Desktop.
7セグパネルがよく見えない 横へな2016.9.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
# http://nabetani.sakura.ne.jp/hena/orde07_7seg/ | |
LIGHT = %w!3f 06 5b 4f 66 6d 7d 27 7f 6f!.map(&:hex) | |
def solve l, u | |
# 7セグパネルのビットが全て立っていないときは,注目桁の最小値に空白を挿入するが | |
# 注目桁より上位の桁の最小値の中に空白でない桁が存在するときfalseとなるフラグ | |
flg = true | |
a = l.zip(u).map.with_index{|(a,b), i| | |
c = ~a&~b # red parts | |
d = LIGHT.map.with_index { |e, j| | |
j if (a|c)&e == e && (a|e)^e == 0 | |
}.compact | |
if i == 0 && l.size != 1 && !d.empty? && d[0] == 0 | |
if d.size == 1 | |
next nil | |
else | |
d.shift | |
end | |
end | |
if flg && a == 0 && l.size - 1 != i | |
d.unshift("") | |
else | |
flg = false | |
end | |
d unless d.empty? | |
} | |
# 最小値,最大値を作る処理 | |
if a.include?(nil) | |
return ?- | |
else | |
0.upto(a.size-2) do |i| | |
if a[i] == "" | |
next | |
elsif a[i][0] != 0 | |
break | |
else | |
a[i-1].shift | |
if a[i-1][0] == 0 | |
if a[i-1].size == 1 | |
return ?- | |
else | |
a[i-1].shift | |
break | |
end | |
end | |
break | |
end | |
end | |
end | |
return a.map{|e|[e[0],e[-1]]}.transpose.map(&:join)*?, | |
end | |
puts solve *gets.split(?,).map{|e|e.split(?:).map(&:hex)} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment