[Ruby] I tried to make a numeron that is not good with Ruby

1 minute read

Introduction

Due to certain circumstances, I tried to make a bad Numeron. I have no regrets.

Numer0n-wikipedia

Numeron

I referred to this article. [Ruby] I made Numeron, a number-matching game

Source code

numeron.rb


d = []
while true
  d[102, 2] = rand(0..32767).divmod(10)
  d[101, 2] = rand(0..32767).divmod(10)
  d[100, 2] = rand(0..32767).divmod(10)
  break if d[101] != d[102] && d[102] != d[103] && d[103] != d[101]
end
puts "please call"
while true
  x200 = gets.chomp
  d[111] = x200[0].to_i
  d[112] = x200[1].to_i
  d[113] = x200[2].to_i
  d[300] = 0
  d[400] = 0
  d[300] += 1 if d[101] == d[111]
  d[300] += 1 if d[102] == d[112]
  d[300] += 1 if d[103] == d[113]
  d[400] += 1 if d[101] == d[112]
  d[400] += 1 if d[101] == d[113]
  d[400] += 1 if d[102] == d[111]
  d[400] += 1 if d[102] == d[113]
  d[400] += 1 if d[103] == d[111]
  d[400] += 1 if d[103] == d[112]
  if d[300] == 3
    puts "3 EAT"
    break
  else
    puts "#{d[300]} EAT-#{d[400]} BITE"
  end
end

rand.rb


  d[100, 2] = rand(0..32767).divmod(10)

  d[101] = rand(0..9)

Do not refactor with rand(0..9). There is also a convenience here.

Summary

  • I tried to make a numeron
  • I have no regrets
  • I became familiar with Ruby