Posts

Showing posts with the label exercism

Convert a phrase to its acronym in Julia

instructions Instructions Convert a phrase to its acronym. Techies love their TLA (Three Letter Acronyms)! Help generate some jargon by writing a program that converts a long name like Portable Network Graphics to its acronym (PNG). x 1 s = "Portable Network Graphics" 2 "Portable Network Graphics" 3 4 t = join ([ x [ 1 ] for x in split ( s )])

Given a person's allergy score, determine whether or not they're allergic to a given item, and their full list of allergies in Julia

​ 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 ...