Posts

Showing posts from February, 2022

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

Multiplication table in html with python

 #Generate multiplication table by html #https://ideone.com/YVXmga import random from copy import deepcopy N = 15 colors = ['F','E','D','C','B','A'] i = 0 colorsall = [] while i < N:     colornow = deepcopy(colors)     random.shuffle(colornow)     colornow = "#"+"".join(colornow)     colorsall.append(colornow)     i += 1 t = "" for i in range(1,N+1):     s = ''     for j in range(1,N+1):         if j >= i:             s += '<td style="background-color:' + colorsall[i-1] + '">'+str(i*j)+'</td>'         else:             s += '<td style="background-color:' + colorsall[j-1] + '">'+str(i*j)+'</td>'     s = "<tr>" + s + "</tr>"     t = t + s + '\n'      print('<table>' + t + '</table>') html code: <table><tr><td style="back