Challenge 5 - Crack the Code

Hi all, I’m back again with another challenge! This week I have hidden the function I created within the spoiler tag below - I would love to see what solutions you come up with and then compare it to my own. As always, any suggestions or feedback on how to improve my solution would be greatly appreciated. Can’t wait to see everyone’s answers! 

You are given a list of numbers.

The original numbers have been squared, multiplied by 3 then added 8 to give;

371, 56, 20, 251, 1091, 35, 683, 683, 440.

Your task is to create a function that takes each of the above numbers, works out the original number and maps it to the corresponding letter of the alphabet. E.g. 1 = a , 2 = b, 3 = c.

Once all 9 letters have been outputted it will reveal a message.

func1:{[number] orig_num:(sqrt[(number-8)%3]); index:(“i”$orig_num)-1; :.Q.a[index];}

 

 

dc: .Q.a -1+ “j”$ sqrt %[;3] -[;8] :: / decrypt dc 371 56 20 251 1091 35 683 683 440

 

A sequence of unaries is close to an ideal style in q. According to Arthur Whitney, Ken Iverson considered even infix notation as a sequence of unaries, e.g. 2*3+4 as (2*)(3+)4

Note how q’s apply/index dualism allows us to compose a list in with the unary functions.

Goes without saying that all the iteration is implicit…

q)n:371 56 20 251 1091 35 683 683 440 q).Q.a -1+7h$sqrt(n-8)%3 “kdbiscool” q)//I agree

 

Nice! So how would you write the function?