31
4
Introduction
Santa has too many names to process, and needs your help! He needs you to write a program or a function, which outputs nice, naughty, very naughty or very very naughty. To determine how nice or naughty someone is, Santa had developed an algorithm:
First of all, we obtain a number from the name by adding all the letters up (spaces ignored). For example:
Doorknob =
D = 4
o = 15
o = 15
r = 18
k = 11
n = 14
o = 15
b = 2
4 + 15 + 15 + 18 + 11 + 14 + 15 + 2 = 94
If the number of divisors is equal to the length of the name, the person is considered nice. This means that your program should output [name] has been nice. Here, the divisors of 94 are:
Divisors of 94: 1, 2, 47, 94
There are 4 divisors, but the name has length 8 (spaces included). Conclusion, Doorknob has not been nice. So we continue our journey:
Santa has developed a new sequence, the christmas number. First, we will look at the following christmas trees:
n = 1 n = 2 n = 3 n = 4
*
***
*****
*******
*********
_ * ***
| *** *****
| ***** *******
* | ******* *********
* *** | *** ***
*** ***** n*n | ***** *****
* *** | ******* *******
***** | *** *********
* | ***** ***
|_******* *****
* *******
|_____| *********
2n+1 *
5 18 47 98
The amount of asterisks determines the christmas number. The sequence goes as following: 5, 18, 47, 98, 177, ....
From here, we can conclude that 94 is not a christmas number. That means that Doorknob has not just been naughty.
Very naughty (string):
For this, we need to find out if Doorknob is a raising ladder string. This is determined by the letters in the name with A = 1, B = 2, C = 3, etc.:
First we will look at the first letter, the D. This has value 4. This is our starting point. The next letter is o. This has the value 15, which is higher than our previous value, so we're going a step higher on the ladder. The next value is also an o. This is the same, so we're doing nothing. If the next value is higher than the current value, we will go a step higher. If the next value is lower than the current value, we will go a ster lower. If it's the same, we'll stay on the same step. This visualised for Doorknob, Martin Buttner and Alex A:
O
/ \
R N B
/ \ /
O-O K T N U L X
/ / \ / \ / \ / \ / \
D M R I B T-T A E A
\ / \
A N R
\ /
E
You can see that Doorknob ended higher than the starting position. So Doorknob has been very naughty. Martin Buttner and Alex A didn't get higher than the starting point. So they are both very very naughty.
Test cases
Input: Doorknob
Output: Doorknob has been very naughty
Input: Martin Buttner
Output: Martin Buttner has been very very naughty
Input: Jakube
Output: Jakube has been nice
Input: B
Output: B has been very very naughty
Rules
- You need to provide a program or a function which takes input (which consists of at least one letter).
- The input will consist of uppercase letters, lowercase letters and spaces. Spaces are ignored during the process, except for the length of the input.
- This is code-golf, so the submission with the least amount of bytes wins!
15Btw, the proper way to write Büttner without an umlaut is Buettner, not Buttner. – Dennis – 2015-12-20T15:50:21.047
Any limit on input length? – Lynn – 2015-12-20T16:00:09.700
3The Christmas numbers are generated by
n^3 + 2n^2 + 2, btw. – Lynn – 2015-12-20T16:10:58.617@Mauris, the length of the input will not exceed 99 characters. – Adnan – 2015-12-20T16:20:47.843
2Alrighty. Then the maximum "score" for a name is
ZZZ...Z = 26 * 99 = 2574, meaning you only need to check Christmas numbers up to and includingn=13. (Useful info for other golfers.) – Lynn – 2015-12-20T16:23:56.570@Mauris Yes, that is correct – Adnan – 2015-12-20T16:26:12.570
My name change has made me go from being very very naughty to just being very naughty. – Arcturus – 2015-12-20T18:19:16.093
23
Santa has been very very naughty. Wait, what? – Doorknob – 2015-12-20T18:35:00.5705@Doorknob冰 - You didn't get his full name:
Santa Claus has been very naughty. Should also try Saint Nick, Saint Nicholas, St. Nick, St. Nicholas, Kris Kringle, Father Christmas, Pere Noel, and all his other aliases - maybe one of them will work? Though why a "nice" guy should need so many aliases is already pretty suspect... – Darrel Hoffman – 2015-12-20T22:48:43.233How are you determining the number of factors? If a number has the same factor more than once, does that count? (You could then have an infinite number of 1 factors.) Or only unique factors? Only unique prime factors? I'm trying to figure out how Jakube passed as "nice" - the letters add up to 48, which has factors 1, 2, 3, 4, 6, 8, 12, 16, 24, 48, which is way more than the 6 letters in the name. Or it could be 2, 2, 2, 2, 3, still not 6. You could add a 1 to that, but you could also add four 1's to Doorknob and it would add up to 8 factors. Need to clear that up a bit. – Darrel Hoffman – 2015-12-20T22:59:20.220
@DarrelHoffman The letters of
Jakubeadd up to 50, not 48 – Adnan – 2015-12-20T23:03:55.897D'oh. Math error (had
Uas 19 instead of 21). So it's unique factors (since there'd be two 5's otherwise), not necessarily prime. Okay. – Darrel Hoffman – 2015-12-20T23:10:34.740