トップ «前の日記(2017-08-27) 最新 次の日記(2017-09-15)» 編集

日々の破片

著作一覧

2017-09-05

_ 3桁の数当て

子供がJavaで3桁の数当てプログラムを作ったとかいって見せるので、おれも作ってみた。
a = [rand(9) + 1, rand(10), rand(10)]
loop do
  line = gets
  if line =~ /\A(\d)(\d)(\d)\Z/
    b = [$1.to_i, $2.to_i, $3.to_i]
    eats = 0
    bytes = 0
    0.upto(2) do |i|
      if b[i] == a[i]
        eats += 1
      else
        bytes += 1 if b[i] == a[i - 1] || b[i] == a[(i + 1 > 2) ? 0 : i + 1]
      end
    end
    puts "eats:#{eats}, bytes:#{bytes}"
    exit if eats == 3
  else
    puts 'enter 3 digits number'
  end
end

2003|06|07|08|09|10|11|12|
2004|01|02|03|04|05|06|07|08|09|10|11|12|
2005|01|02|03|04|05|06|07|08|09|10|11|12|
2006|01|02|03|04|05|06|07|08|09|10|11|12|
2007|01|02|03|04|05|06|07|08|09|10|11|12|
2008|01|02|03|04|05|06|07|08|09|10|11|12|
2009|01|02|03|04|05|06|07|08|09|10|11|12|
2010|01|02|03|04|05|06|07|08|09|10|11|12|
2011|01|02|03|04|05|06|07|08|09|10|11|12|
2012|01|02|03|04|05|06|07|08|09|10|11|12|
2013|01|02|03|04|05|06|07|08|09|10|11|12|
2014|01|02|03|04|05|06|07|08|09|10|11|12|
2015|01|02|03|04|05|06|07|08|09|10|11|12|
2016|01|02|03|04|05|06|07|08|09|10|11|12|
2017|01|02|03|04|05|06|07|08|09|10|11|12|
2018|01|02|03|04|05|06|07|08|09|10|11|12|
2019|01|02|03|04|05|06|07|08|09|10|11|12|
2020|01|02|03|04|05|06|07|08|09|10|11|12|
2021|01|02|03|04|05|06|07|08|09|10|11|12|
2022|01|02|03|04|05|06|07|08|09|10|11|12|
2023|01|02|03|04|05|06|07|08|09|10|11|12|
2024|01|02|03|

ジェズイットを見習え