1
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

瞬き星

Posted at

変形オセロ. 本当はLINESをハードコーディングせずに書くべきだったと思う.
あと, 指定された点以外に共有点を持つような2曲線だった場合に死ぬ. この場合は反転すべき点一覧を別途保持するしか無いと思う.

tyama_esm2.rb
#!/usr/bin/env ruby
#https://gist.github.com/mattsan/07674b095908fda117a0

LINES=['AFGD','AJIC','BJFE','BIHD','CHGE']

def dfs(line,d,cur,color)
	return false if cur==-1||cur==line.size
	return true if $colors[line[cur]]==color
	$colors[line[cur]]=color if dfs(line,d,cur+d,color)
end
		
if __FILE__==$0
	while gets
		$colors=Hash[*('A'..'E').flat_map{|e|[e,0]}+('F'..'J').flat_map{|e|[e,1]}]
		$_.chomp.chars{|c|
			$colors[c]^=1
			LINES.each{|l|
				idx=l.index(c)
				if idx
					dfs(l,1,idx+1,$colors[c])
					dfs(l,-1,idx-1,$colors[c])
				end
			}
		}
		puts ('A'..'J').map{|e|'WR'[$colors[e],1]}*''
		STDOUT.flush
	end
end
1
1
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
1
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?