39
8
Your task is to translate a 103-smooth number into an English word, using the method described below.
How?
- Generate the list of prime factors (with repetition) of the input number.
- Sort the list:
- If 2 is not one of the prime factors, sort the list in ascending order.
- If 2 is one of the prime factors, remove it from the list and sort the remaining factors in descending order.
Translate each factor into a letter, using the following table:
3 = S 13 = L 29 = X 43 = O 61 = Z 79 = H 101 = K 5 = P 17 = Q 31 = N 47 = R 67 = T 83 = V 103 = Y 7 = M 19 = U 37 = C 53 = A 71 = E 89 = D 11 = F 23 = I 41 = W 59 = G 73 = J 97 = B
Note: This table was built empirically to maximize the number of possible words. For the curious, here is a list of 2,187 words that can be encoded that way (may include rude language). It's definitely not guaranteed to be optimal, but it's good enough for this challenge.
Examples
Example 1: 579085261 (ascending order)
- The prime factors are [ 37, 47, 53, 61, 103 ].
- 2 is not a prime factor, so we keep the list sorted in ascending order.
- 37 = C, 47 = R, etc. The output is "CRAZY".
Example 2: 725582 (descending order)
- The prime factors are [ 2, 11, 13, 43, 59 ].
- 2 is a prime factor, so we remove it and sort the list in descending order, which gives:
[ 59, 43, 13, 11 ]. - 59 = G, 43 = O, etc. The output is "GOLF".
Example 3: 10757494 (with a repeated factor)
- The prime factors are [ 2, 11, 71, 71, 97 ].
- 2 is a prime factor, so we remove it and sort the list in descending order, which gives:
[ 97, 71, 71, 11 ]. - 97 = B, 71 = E, 11 = F. The output is "BEEF".
Clarifications and rules
- The input number is guaranteed to be 103-smooth and divisible by 2 at most once.
- By definition, a smooth-number is a positive integer.
- Input and output can be handled in any reasonable format. The output can be in lowercase or uppercase. Trailing whitespace is acceptable. Leading whitespace is not.
- If your program/function can't support large inputs, please specify it in your answer.
- This is code golf, so the shortest answer in bytes wins.
Test cases
34874 --> ARM
483254 --> BAR
353722 --> EAR
494302 --> EGG
39061 --> FAT
6479 --> FUN
60421 --> ICE
54166 --> JAM
48911474 --> BETA
2510942 --> BOOM
2303854 --> DOOM
844261 --> FIRE
1606801 --> MAZE
1110085 --> PAGE
5212974 --> BALLS
67892046 --> BEANS
885396199 --> CREEK
67401037 --> FUNKY
27762173 --> QUICK
1238440506 --> ARROWS
33045832681 --> CRAGGY
1362714005 --> PIRATE
137302698 --> TROLLS
358310128062 --> BEGGARS
40255151586 --> DETAILS
164633248153 --> FIXATED
621172442227 --> UNRATED
2467812606 --> VACUUMS
86385078330 --> GROWNUPS
26607531423091 --> UNWORTHY
9Ohhh crap... 05AB1E cache hit when using
Ò
on579085261
, feel like <s>Emigna</s> Adnan has already started. – Magic Octopus Urn – 2017-04-27T17:20:20.307You could've allowed multiple factors of 2, then made it so that increasing the number of factors changes the index at which the reversal starts. – mbomb007 – 2017-04-27T18:16:04.443
@mbomb007 Yes, there are many possible variants. My initial idea was to encode any word by working on groups of letters. – Arnauld – 2017-04-27T18:47:55.070
5The test cases on this challenge remind be of those "discover your X name" things on Facebook. Find the title of the movie you're in! Step one, choose your favorite prime number
<=103
... your result isPIRATE MAZE
, orDOOM VACUUMS
... – mbomb007 – 2017-04-27T19:21:03.150I'm curious as to how you assigned each number to a letter. Was it random, or did you have a specific pattern to it? – clismique – 2017-04-28T07:27:25.017
2
@Qwerp-Derp It was first randomly shuffled and tested against a dictionary of ~106K words, up to 11 letters (the file is on my HD for a long time -- I think it was originally extracted from the TWL). Then I forced 'S' to be either first or last to maximize plural words and tried a couple of individual letter exchanges on a good combination (recursively). Finally, I lost patience and wrote the challenge. :-) Actually, before all of this, I tried to take Letter Counts by Position Within Word into account but it wasn't all that great.
– Arnauld – 2017-04-28T08:25:10.007What's the rule on trailing whitespace? – Value Ink – 2017-04-28T21:44:52.503
@ValueInk Updated. Trailing whitespace is allowed. – Arnauld – 2017-04-28T22:14:58.710