LoginSignup
0
0

More than 5 years have passed since last update.

六角形のテトロミノ

Last updated at Posted at 2017-04-27

総当り。しかもYの判定だけ気持ち悪い。
なお、実装は30分ですが構想に数週間かかっています。会場参加だったら大泣きでしたorz

henae13.rb
#!/usr/bin/env ruby
#http://nabetani.sakura.ne.jp/hena/orde13hextet/
#http://qiita.com/Nabetani/items/50cd05989b6e2812f879
require 'set'

M=[
[0,0],[0,1],[0,2],[0,3],[0,4],
[1,0],[1,1],[1,2],[1,3],
[2,-1],[2,0],[2,1],[2,2],[2,3],
[3,-1],[3,0],[3,1],[3,2],
[4,-2],[4,-1],[4,0],[4,1],[4,2],
]

#CCW
T=[
    [0,1],[1,0],[1,-1],[0,-1],[-1,0],[-1,1]
]
Z={
    'B'=>'004','D'=>'040','I'=>'500','J'=>'550',
    'L'=>'005','N'=>'411','O'=>'421','S'=>'051',
    'Y'=>'0131','Z'=>'415',
}

while gets
    q=$_.chomp.bytes.map{|b|b-97}
    s=q.map{|e|M[e]}
    h=Set.new()
    s.each{|e|h.add(e)}
    s.all?{|e|
        Z.each{|k,v|
            if 6.times.any?{|d|
                y,x=e
                v.chars.all?{|dd|
                    d=(d+dd.to_i)%6
                    y+=T[d][0]
                    x+=T[d][1]
                    h.include?([y,x])
                }
            }
                puts k
                break
            end
        }
    } and puts :-
    STDOUT.flush
end
0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0