x 54 1 using Combinatorics 2 3 allegies = [ "eggs" , 4 "peanuts" , 5 "shellfish" , 6 "strawberries" , 7 "tomatoes" , 8 "chocolate" , 9 "pollen" , 10 "cats" ] 11 12 function getCombs () 13 N = 7 14 15 scores = 2 .^ collect ( 0 : N ) 16 combs = [] 17 for i in 1 : N + 1 18 combs = vcat ( combs , collect ( combinations ( scores , i ))) 19 end 20 21 combs 22 end 23 24 allCombs = getCombs () 25 26 function getAllergies ( score ) 27 28 println ( score ) 29 30 #score = 45 31 score1 = mod ( score , 256 ) 32 33 flag = 0 34 35 36 for comb in allCombs 37 if sum ( comb ) == score1 38 flag = 1 39 #println(comb, ", ") 40 println ( join ( allegies [ Int64 . ( trunc . ( log . ( 2 , comb ))) .+ 1 ], "," )) 41 end 42 end 43 44 ...
Comments
Post a Comment