プログラミングのお題スレ Part17at TECH
プログラミングのお題スレ Part17 - 暇つぶし2ch604:デフォルトの名無しさん
20/05/23 02:20:43.28 zNKp3hWU.net
>>582 Ruby
def moves( str )
x, y = 0, 0
r = 0
ta = [ [0,-1], [1,0], [0,1], [-1,0] ]
ts = %w{北 東 南 西}
str.split(/,\s*/).each{|ch|
case ch
when '1'; r = (r - 1) % 4
when '2'; r = (r + 1) % 4
when '3'
x += ta[r][0]
y += ta[r][1]
end
puts "%3d %3d %s" % [ x, y, ts[r] ]
}
end
moves( "1, 3, 3, 2, 3" )
moves( "3, 2, 3, 1" )


次ページ
続きを表示
1を表示
最新レス表示
レスジャンプ
類似スレ一覧
スレッドの検索
話題のニュース
おまかせリスト
オプション
しおりを挟む
スレッドに書込
スレッドの一覧
暇つぶし2ch