fork download
  1. s = "4 4 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16:11".split(":")
  2. s[0] = s[0].split(" ")
  3. s[1] = s[1].to_i
  4. p = Array.new(s[0][1].to_i) { Array.new }
  5. n = 0
  6. id, id2 = 0, 0
  7. (0..3).each do |i|
  8. (0..3).each do |i2|
  9. p[i][i2] = s[0][2 + n].to_i
  10. id, id2 = i, i2 if p[i][i2] == s[1]
  11. n += 1
  12. end
  13. end
  14.  
  15. a = Array.new
  16. a.push(p[id - 1][id2]) if id > 0 and p[id - 1][id2] < s[1]
  17. a.push(p[id + 1][id2]) if id < 4 and p[id + 1][id2] < s[1]
  18. a.push(p[id][id2 - 1]) if id2 > 0 and p[id][id2 - 1] < s[1]
  19. a.push(p[id][id2 + 1]) if id2 < 4 and p[id][id2 + 1] < s[1]
  20. a.push(p[id - 1][id2 - 1]) if id > 0 and id2 > 0 and p[id - 1][id2 - 1] < s[1]
  21. a.push(p[id + 1][id2 + 1]) if id < 4 and id2 < 4 and p[id + 1][id2 + 1] < s[1]
  22. a.push(p[id + 1][id2 - 1]) if id < 4 and id2 > 0 and p[id + 1][id2 - 1] < s[1]
  23. a.push(p[id - 1][id2 + 1]) if id > 0 and id2 < 4 and p[id - 1][id2 + 1] < s[1]
  24. puts a
Success #stdin #stdout 0s 4816KB
stdin
Standard input is empty
stdout
7
10
6
8