当日不参加でした。ので久々のオンラインノンリアルタイムどう書く。
湯上りにプレッシャーのない状況も手伝って 23 分で書けました。
珍しく最初に思いついたものをそのままコードにできて、珍しくつまずきなく全入力がパスしました。
- 問題はこちら: http://nabetani.sakura.ne.jp/hena/orde05dokitruck/
- みなさんの回答へのリンクはこちら: http://qiita.com/Nabetani/items/c516875b13a4d282affe
orde05dokitruck.rb
def move((a, b, c) , no)
case no
when '1' then [a, (a | b), (b | c)]
when '2' then [a, (b | c), (a | c)]
when '3' then [(a | b), b, (a | c)]
when '4' then [(a | b), (b | c), c]
when '5' then [(a | c), b, (b | c)]
when '6' then [(a | c), (a | b), c]
when '7' then [a, [], c]
when '8' then [[], b, c]
when '9' then [a, b, []]
end
end
def solve(input)
result = input.chars.reduce([['a'], ['b'], ['c']]) {|course, c| move(course, c) }.reduce(:|).sort
if result.empty?
'-'
else
result.join
end
end
DATA.each do |line|
input, expected = line.split
actual = solve(input)
if actual == expected
print '.'
else
puts(<<~EOS)
input: #{input}
expected: #{expected}
actual: #{actual}
EOS
end
end
puts
__END__
1728398 bc
789 -
274 ac
185 abc
396 ab
1278 abc
7659832 a
178 bc
189 ab
197 a
278 ac
289 bc
297 a
378 ac
389 b
397 ab
478 c
489 bc
497 ab
578 bc
589 b
597 ac
678 c
689 ab
697 ac
899 b
7172 ac
54787 bc
83713 bc
149978 -
159735 abc
1449467 abc
9862916 b
96112873 ab
311536789 -
281787212994 abc
697535114542 ac