飯ã¯é£ããããã
ããã«èª²é¡ããã£ãã®ã§ã試ãã«ã¨ãã¦ã¿ãã
http://www.itmedia.co.jp/enterprise/articles/1004/03/news002.html
åé¡
麻éã®æçãå ¥åã¨ãã¦ä¸ããããã¨ãããå¾ ã¡ããåºåããããã°ã©ã ãæ¸ãã¦ãã ããã
- åçãªãã»è¬åã®ã¿ã®æ³å®ãã¤ã¾ããããããããã³ã¤ããéå®ã§çµæ§ã§ãï¼ããã°ã©ãã³ã°ã®æ¬è³ªçã«ã¯ãã®éå®ã§ã¾ã£ããåé¡ãªãããï¼
- 1ã9ã®æ°å13åãããªãæååãåãåããã§ãã¦ããé åã»å»åã»ã¢ã¿ãã()ãå¾ ã¡ã®é¨åã[]ã§ããã£ã¦åºåãã¦ãã ãã
- é¢åãã¤æ§åã¯åå¨ããªãåæã§OKã§ã
- ()[]ã®åºåé ã¯èªç±ã§ãããé åºã ããéããã®ã¯åä¸è¦ãã¦ãã ããï¼ä¾ï¼111222ãå»å2ã¤ã§æ§æããã¨ãã(111)(222)ã (222)(111)ã«å ¥ãæ¿ããã ãã®ãã®ã¯åä¸è§£çã¨ãã¾ãï¼
- å¤é¢å¾ ã¡ã®ã¨ããå«ããã¹ã¦ã®å¾ ã¡ãåºåãã¦ãã ãã
- å¾ ã¡ããªãã¨ãã¯ä½ãåºåããªãã§ãã ãã
ã³ã¡ã³ã
ç¡é§ãªæ¢ç´¢ãã§ããã ãããªãããã®å·¥å¤«ããããã°ãå¹çåããããã®å·¥å¤«ãªã©ãããã°ã½ã¼ã¹ã³ã¼ãã«ã³ã¡ã³ãã¨ãã¦è¨å ¥ãã¦ãã ããã
åºåä¾
1112224588899 :
åç´ãªã±ã¼ã¹ã§ãã45ã軸ã«ãã両é¢ã®å¾ ã¡ãªã®ã§ã(111)(222)(888)(99)[45]ã«ãªãã¾ãã
1122335556799 :
â99âãã¢ã¿ãã®ä¸¡é¢ãâ55ââ99âã®ã·ã£ãã§ããã®ã§ã(123)(123)(555)(99)[67]ã(123)(123)(55)(567) [99]ã(123)(123)(99)(567)[55]ãæ£è§£ã§ãã
1112223335559 :
å¾ ã¡ã¯â9âåé¨ã§ããã(123)(123)(123)(555)[9]ã¨(111)(222)(333)(555)[9]ã®2ã¤ããã¾ãã
1223344888999 :
1-4ã®âããã¿ã³âå¾ ã¡ã§ããã4ãã¢ã¿ãã«ãã¦ã®[23]å¾ ã¡ã¨ã1åé¨ã4åé¨ã§3åã®çãã«ãªãã¾ãã
1112345678999 :
ãä¹è®å®çãã¨ããå½¹ã§ãã1ã9ãã¹ã¦ãå¾ ã¡ã«ãªã£ã¦ãã¾ããããã«æ£ããçããåºãã®ã§ããã°ãããã°ã©ã ã¯ã»ã¼æ£ããã§ãããã
* 麻éãç¥ããªã人ã¯ãé åã»å»åã»ã¢ã¿ãã»å¾ ã¡ã¨ãã£ãç¨èªã®æå³ã ã調ã¹ã¦ãã解çã«åãããã£ã¦ãã ãããããã調ã¹ãæéã¯è¨ç®å¤ã¨ãã¾ãã
ã¨ããããã¨ãã¦ã¿ãã
twitterã§ç¢ºèªãã¦ã¿ãã¨ãã8:39ã«è§£ãå§ãã¦10:20ã§çµãã£ã¦ãã®ã§ã100åã§ä¸å¿è§£ããã¿ããã
ãã ãã³ã¼ãã¯éã
# æçã空ãã©ãã def end_check_tehai(tehai) tehai.each do | key, value | return tehai if value > 0 end return nil end def get_juntu(hai, tehai) if tehai[hai].to_i > 0 && tehai[hai + 1].to_i > 0 && tehai[hai + 2].to_i > 0 (0..2).each do | i | tehai[hai + i] -= 1 end return [(0..2).map{|i|hai + i}, end_check_tehai( tehai )] end return false end #é ãã§ãã¯ãå ¼ããã def get_kotu(hai, tehai, idx = 3) if tehai[hai].to_i >= idx tehai[hai] -= idx return [[hai]*idx, end_check_tehai( tehai )] end return false end def check_loop_inner(data, return_array) if data[1] data_2 = check_loop(data[1]) if data_2.empty? return_array << [data[0]] else data_2.each do | d | return_array << [data[0]] + d end end else return_array << [data[0]] end end #åãæ¢ãããã¸ã£ã³ãã¨ãã³ã¼ãã¨ãé ã¨ããåããã±ã¼ã¹ãå ¨é¨ãããã def check_loop(tehai) return_array = Array.new (1..9).each do | i | if data = get_juntu(i, tehai.dup) check_loop_inner(data, return_array) end if data = get_kotu(i, tehai.dup) check_loop_inner(data, return_array) end if data = get_kotu(i, tehai.dup, 2) check_loop_inner(data, return_array) end end return return_array end #ãããã±ã¼ã¹ããã¡ããã¨æãç«ã¤ããã§ã㯠def answer_check(answer, tehai) atama = Array.new nomal = Array.new answer.each do | a | if a.size == 2 atama << a else nomal << a end a.each do | i | tehai[i] = tehai[i] - 1 end end amari = [] tehai.each do | t , v| v.times do amari << t end end atama_count = atama.size tehai_count = amari.size if atama_count == 0 && tehai_count == 1 amari = amari.sort.join return nomal.map{|n| "(#{n.to_s})" } << "[#{amari}]" elsif atama_count == 1 && tehai_count == 2 if ( amari[0] - amari [1]).abs < 3 return answer.map{|n| "(#{n.to_s})" } << "[#{amari}]" else return nil end elsif atama_count == 2 && tehai_count == 0 return [ (nomal + [atama[0]]).map{|n| "(#{n.to_s})" } << "[#{atama[1].to_s}]" , (nomal + [atama[1]]).map{|n| "(#{n.to_s})" } << "[#{atama[0].to_s}]" ] elsif atama_count == 6 && tehai_count == 1 return answer.map{|n| "(#{n.to_s})" } << "[#{amari}]" end return nil end def get_machi(tehai_string) tehai = Hash.new input_strings = tehai_string.split(//).delete_if{|c| !( c =~ /^\d$/) } input_strings.each do|c| tehai[c.to_i] = (tehai[c.to_i] || 0) + 1 end answers = [] nocheck_answers = check_loop(tehai.dup) nocheck_answers.each do | answer | answer_check_return = answer_check(answer, tehai.dup) if answer_check_return.class == Array && answer_check_return.size == 2 answer_check_return.each do | a | answers << a.sort end elsif answer_check_return answers << answer_check_return.sort end end puts "check #{tehai_string}" puts answers.uniq.map{|a| a.to_s}.join("\n") end get_machi("1112224588899") get_machi("1122335556799") get_machi("1112223335559") get_machi("1223344888999") get_machi("1112345678999") get_machi("1444477888999") # => å¾ ã¡ç¡ãã®ãã¹ã
åºåçµæã¯
ruby majan.rb check 1112224588899 (111)(222)(888)(99)[54] check 1122335556799 (123)(123)(55)(567)[99] (123)(123)(567)(99)[55] (123)(123)(555)(99)[67] check 1112223335559 (123)(123)(123)(555)[9] (111)(222)(333)(555)[9] check 1223344888999 (123)(234)(888)(999)[4] (123)(44)(888)(999)[23] (234)(234)(888)(999)[1] check 1112345678999 (11)(123)(456)(789)[99] (123)(456)(789)(99)[11] (11)(123)(456)(999)[78] (11)(123)(678)(999)[54] (111)(234)(567)(999)[8] (111)(234)(567)(99)[89] (111)(234)(678)(999)[5] (111)(234)(789)(99)[56] (111)(345)(678)(999)[2] (111)(456)(789)(99)[23] (11)(345)(678)(999)[12] check 1444477888999
ãããªæã
å
¨ç¶ã¢ã«ã´ãªãºã èããäºããªãã£ãã®ã§ãã¡ãã£ã¨æ¥½ããã£ãã
10:53 ãã¼ãã¤ãã«ã対å¿ããã
elsif atama_count == 6 && tehai_count == 1 return answer.map{|n| "(#{n.to_s})" } << "[#{amari}]"
ã ã追å ã