teratail header banner
teratail header banner
質問するログイン新規登録

回答編集履歴

1

Update

2021/11/24 03:29

投稿

melian
melian

スコア21265

answer CHANGED
@@ -15,13 +15,14 @@
15
15
  hand = index_on_keyboard(inputs[0], keyboard)[0] / 5
16
16
  mistake = 0
17
17
 
18
- inputs.chars.zip(inputs.chars[1..])[...-1].map{|consecutive|
18
+ inputs.chars.each_cons(2).map{|consecutive|
19
19
  a, b = consecutive.map{|c| index_on_keyboard(c, keyboard)}
20
20
  pos = [[1, 0], [-1, 0], [0, 1], [0, -1]].map{|x, y| [a[0]+x, a[1]+y]}
21
+ nhand = b[0] / 5
21
22
  if ([a] + pos).include?(b) then
22
- mistake += 1 if hand != (b[0] / 5)
23
+ mistake += 1 if hand != nhand
23
24
  else
24
- hand = index_on_keyboard(consecutive[1], keyboard)[0] / 5
25
+ hand = nhand
25
26
  end
26
27
  }
27
28