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

第2回 ESM オフラインリアルタイムどう書く( http://d.hatena.ne.jp/E_Mattsan/20151230/1451449205 )の問題
「星めぐり( https://gist.github.com/mattsan/38a752dca30423902b0a )」を解いた。

所要時間 9分。

で。

私の実装。

M={"W"=>"AIGECA/BG/DI/FA/HC/JE",
  "R"=>"FHJBDFH/AH/CJ/EB/GD/IF" }

def solve(src)
  src.chars.drop(1).inject([src[0]]){ |acc,c|
    path=M[c]
    ix=path.index(acc.last)
    acc.push path[ix+1]
  }.join
end

DATA.map{ |line|
  src, expected = line.split(/\s+/)
  actual = solve( src )
  ok = actual==expected
  puts( "%s : %s->%s / %s" % [ (ok ? "ok" : "**NG**" ), src, actual, expected ] )
  ok
}.tap{ |x| puts( x.all? ? "all ok" : "something wrong" ) }

__END__
AW  AI
IRWWRRWWWWWRRWWR  IFAIFHCAIGEBDIGD

いつも通り、テストデータの大半は省略。

9分経過時点のコードそのまま。
まだリファクタリングしていない。

グラフを表現する部分が若干邪悪な感じだけど、急いでいるのでこんなもんだと思う。
ix は変数で受けなくてもよかったね。

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?