4
6

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.

八面体を転がす

Last updated at Posted at 2014-02-10

問題:https://codeiq.jp/ace/nabetani_takenori/q708

https://twitter.com/Nabetani/status/432110418635395072 の「水曜」って2/19ではなく2/12で良いのですよね…?

ちなみにmap{|e|a[e]}はmap(&a.method(:[]))でもok。だから何って感じですが(ブロックを一段減らすことは可能なのかな?)。

#!/usr/bin/ruby
#面のマッピング
C='YRBGYRBG'
#初期状態から2時、6時、10時の方向に転がし、60度右に回転させた結果
T=[[3,6,0,5,7,2,4,1],[1,6,7,0,5,2,3,4],[2,0,7,5,6,4,3,1]]
D={'D'=>0,'2'=>0,'4'=>1,'6'=>1,'8'=>2,'T'=>2}

while gets
	r='Y'
	a=[*0..7]
	$_.chomp.each_char.with_index{|c,i|
		a=T[(D[c]+i/2)%3].map{|e|a[e]} # 60度ずつ右に回転させるから、i/2を足す必要がある
		r<<C[a[0]]
	}
	puts r
end
4
6
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
4
6

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?