問題はこちらのリンクから
http://nabetani.sakura.ne.jp/hena/ord17foldcut/
class Paper
def initialize
@tl = [:s]
@tr = [:s]
@bl = [:s]
@br = [:s]
end
def r
@tl += @tr
@bl += @br
@tr = @tr.map{|e| {:s=>:dv,:dv=>[:dv,:dv],:dh=>:f,:f=>[:f,:f]}[e]}.flatten
@br = @br.map{|e| {:s=>:dv,:dv=>[:dv,:dv],:dh=>:f,:f=>[:f,:f]}[e]}.flatten
end
def l
@tr += @tl
@br += @bl
@tl = @tl.map{|e| {:s=>:dv,:dv=>[:dv,:dv],:dh=>:f,:f=>[:f,:f]}[e]}.flatten
@bl = @bl.map{|e| {:s=>:dv,:dv=>[:dv,:dv],:dh=>:f,:f=>[:f,:f]}[e]}.flatten
end
def t
@bl += @tl
@br += @tr
@tl = @tl.map{|e| {:s=>:dh,:dh=>[:dh,:dh],:dv=>:f,:f=>[:f,:f]}[e]}.flatten
@tr = @tr.map{|e| {:s=>:dh,:dh=>[:dh,:dh],:dv=>:f,:f=>[:f,:f]}[e]}.flatten
end
def b
@tl += @bl
@tr += @br
@bl = @bl.map{|e| {:s=>:dh,:dh=>[:dh,:dh],:dv=>:f,:f=>[:f,:f]}[e]}.flatten
@br = @br.map{|e| {:s=>:dh,:dh=>[:dh,:dh],:dv=>:f,:f=>[:f,:f]}[e]}.flatten
end
def tl
@tl.count(:f)
end
def bl
@bl.count(:f)
end
def tr
@tr.count(:f)
end
def br
@br.count(:f)
end
end
def solve(q)
fold, cut = q.split('-')
paper = Paper.new
fold.chars.each{|e|
eval('paper.'+e.downcase)
}
eval('paper.'+cut)
end
DATA.readlines.each do |line|
no,q,a = line.chop.split(/\s+/)
ans = solve(q)
print no + "\t"
print ans
puts ans == a.to_i ? 'o' : 'x'
end
__END__
0 RRTRB-bl 6
1 R-tr 0
2 L-br 0
3 T-tl 0
4 B-tl 0
5 BL-br 0
6 LB-tl 0
7 RL-tl 0
8 BL-tl 0
9 TL-bl 0
10 RT-tr 1
11 TRB-tl 0
12 TRL-bl 0
13 TRB-br 2
14 LLB-bl 2
15 RTL-tr 1
16 LBB-tr 0
17 TLL-tl 2
18 RLRR-tr 0
19 BBTL-tl 4
20 TBBT-tr 0
21 LLBR-tl 0
22 LBRT-tl 2
23 RLBL-bl 4
24 BRRL-br 3
25 TBBTL-tl 8
26 TLBBT-br 0
27 LRBLL-br 7
28 TRRTT-br 6
29 BBBLB-br 0
30 RTTTR-tl 4
31 BBLLL-br 6
32 RRLLTR-tr 16
33 TTRBLB-br 8
34 LRBRBR-bl 14
35 RBBLRL-tl 8
36 RTRLTB-tl 12
37 LBLRTR-tl 14
38 RRLTRL-tl 16
39 TBLTRR-br 12
40 TTTRLTT-bl 30
41 TBBRTBL-tr 15
42 TRTRTLL-tr 28
43 TLLRTRB-tr 24
44 RLLBRLB-tr 15
45 LTLRRBT-tr 32
46 RBBRBLT-br 21
47 LLRLRLR-tr 0