Skip to main content
Commonmark migration
Source Link

#05AB1E, 21 bytes

05AB1E, 21 bytes

'ŽØs[SnOD5‹#}≠i„unì}™ 

Try it online or verify the first 100 test cases.

Explanation:

Each number will eventually result in either 1 or 4, so we loop indefinitely, and stop as soon as the number is below 5.

'ŽØ '# Push string "happy" s # Swap to take the (implicit) input [ } # Loop indefinitely S # Convert the integer to a list of digits n # Square each O # Take the sum D5‹# # If this sum is smaller than 5: stop the infinite loop ≠i } # If the result after the loop is NOT 1: „unì # Prepend string "un" to string "happy" ™ # Convert the string to titlecase (and output implicitly) 

See this 05AB1E tip of mine (section How to use the dictionary?) to understand why 'ŽØ is "happy".

#05AB1E, 21 bytes

'ŽØs[SnOD5‹#}≠i„unì}™ 

Try it online or verify the first 100 test cases.

Explanation:

Each number will eventually result in either 1 or 4, so we loop indefinitely, and stop as soon as the number is below 5.

'ŽØ '# Push string "happy" s # Swap to take the (implicit) input [ } # Loop indefinitely S # Convert the integer to a list of digits n # Square each O # Take the sum D5‹# # If this sum is smaller than 5: stop the infinite loop ≠i } # If the result after the loop is NOT 1: „unì # Prepend string "un" to string "happy" ™ # Convert the string to titlecase (and output implicitly) 

See this 05AB1E tip of mine (section How to use the dictionary?) to understand why 'ŽØ is "happy".

05AB1E, 21 bytes

'ŽØs[SnOD5‹#}≠i„unì}™ 

Try it online or verify the first 100 test cases.

Explanation:

Each number will eventually result in either 1 or 4, so we loop indefinitely, and stop as soon as the number is below 5.

'ŽØ '# Push string "happy" s # Swap to take the (implicit) input [ } # Loop indefinitely S # Convert the integer to a list of digits n # Square each O # Take the sum D5‹# # If this sum is smaller than 5: stop the infinite loop ≠i } # If the result after the loop is NOT 1: „unì # Prepend string "un" to string "happy" ™ # Convert the string to titlecase (and output implicitly) 

See this 05AB1E tip of mine (section How to use the dictionary?) to understand why 'ŽØ is "happy".

Source Link
Kevin Cruijssen
  • 136.3k
  • 14
  • 155
  • 394

#05AB1E, 21 bytes

'ŽØs[SnOD5‹#}≠i„unì}™ 

Try it online or verify the first 100 test cases.

Explanation:

Each number will eventually result in either 1 or 4, so we loop indefinitely, and stop as soon as the number is below 5.

'ŽØ '# Push string "happy" s # Swap to take the (implicit) input [ } # Loop indefinitely S # Convert the integer to a list of digits n # Square each O # Take the sum D5‹# # If this sum is smaller than 5: stop the infinite loop ≠i } # If the result after the loop is NOT 1: „unì # Prepend string "un" to string "happy" ™ # Convert the string to titlecase (and output implicitly) 

See this 05AB1E tip of mine (section How to use the dictionary?) to understand why 'ŽØ is "happy".