Given a single *positive* integer (which can also be taken as a list of digits or a string), output whether the number terminates in a 37 cycle in the square sum reduction. Truthy/falsy follows the language's convention, or you can choose exactly one value for truthy and another for falsy. Your program should theoretically support all non-negative integers; however, if your language doesn't support unbounded integers, you may only support integers up to `2147483647`. ## Procedure Suppose you have the number `193`. * Square every individual digit in the number. Therefore the number's individual digits becomes: ``` [1] [81] [9] ``` * Sum all these individual digits: ``` 91 ``` * Repeat this procedure until it stabilizes at `1` or a 37-cycle like the following: ``` 37-58-89-145-42-20-4-16-37 ``` It has been shown that the procedure will always produce either one of these two outputs. ## Test cases [Here](https://tio.run/##PYxNCsIwFIT3OcXQVQJxUbooFeIJxI0niDTVJ01S8wO5fUwtOIs3wzzmI19rjAFnBWvSy8@8SIYmWnhRqocPaD6MR7srmJSDQ/kV4ncbgRfoeE@B3LOFK8UEqzeu4y3bhwmIn6yDmQVitoIJtvjASaKXmKaDvbYNpz9Fdjhd0MmdTQJKYRgF3p4ctvZPq2Oi1i8) is a sample program generating the test cases. [Here](https://tio.run/##VY5NCsMgEIX3OcUjKwU3oYuSgjco3fQElph2StR0VPD2qTFQ6FvMz2Pmm6GwbTEyLhrOpleYRFEdqgpWJp8W3zqaRdF6QGDUfDofM7vYpswepRmyxcoTBSbeUyU8a3GlmODMKky8ZfewjPjJhu0kEbOTnezmwIIUBoVxPNhL3RG93tUr0A@n0Mxe4h3I/z2536VK27Yv) is a step by step reduction of all input between 1 and 100. ``` 1 -> false 2 -> true 3 -> true 4 -> true 5 -> true 6 -> true 7 -> false 8 -> true 9 -> true 10 -> false 11 -> true 12 -> true 13 -> false 14 -> true 15 -> true 16 -> true 17 -> true 18 -> true 19 -> false 20 -> true 21 -> true 22 -> true 23 -> false 24 -> true 25 -> true 26 -> true 27 -> true 28 -> false 29 -> true 30 -> true 31 -> false 32 -> false 33 -> true 34 -> true 35 -> true 36 -> true 37 -> true 38 -> true 39 -> true 40 -> true 41 -> true 42 -> true 43 -> true 44 -> false 45 -> true 46 -> true 47 -> true 48 -> true 49 -> false 50 -> true 51 -> true 52 -> true 53 -> true 54 -> true 55 -> true 56 -> true 57 -> true 58 -> true 59 -> true 60 -> true 61 -> true 62 -> true 63 -> true 64 -> true 65 -> true 66 -> true 67 -> true 68 -> false 69 -> true 70 -> false 71 -> true 72 -> true 73 -> true 74 -> true 75 -> true 76 -> true 77 -> true 78 -> true 79 -> false 80 -> true 81 -> true 82 -> false 83 -> true 84 -> true 85 -> true 86 -> false 87 -> true 88 -> true 89 -> true 90 -> true 91 -> false 92 -> true 93 -> true 94 -> false 95 -> true 96 -> true 97 -> false 98 -> true 99 -> true ```

# [Python 2] REPL, ~~53~~ 40 bytes while _>4:sum(int(x)**2for x in`_`) _<2 [Try it online!][TIO-kiqik1w0] ## Explanation The 37 cycle contains a 4. This means that all input values will eventually end up less than 5. Of the numbers `[1, 2, 3, 4]`, only `1` is a happy number; we know this, so we don't need to recurse any more. Checking for `1`, here, is equivalent to checking for `< 2`; the latter is shorter. In Python 2, `_` is equivalent to `repr(_)`, which for integers is equivalent to `str(_)`. `**` is the “to the power of” operation in Python, and generators don't need to be enclosed by additional brackets if they're the only argument to a function. In the REPL (code compiled with the `'single'` mode), the value of the last statement is assigned to the `_` builtin. This code assigns the value `False` for truthy and `True` for falsy – i.e., it answers the question in the title, not the question specified in the challenge body. [Python 2]: https://docs.python.org/2/ [TIO-kiqik1w0]: https://tio.run/##nVJNb8IwDL33V1hIqA1j1UCTJiHojUm7bIftxlApxR0ZrROlQYRfz9zy/XWZL4md52fn6em1nSvqbjKjCkjVDEEWWhnL90LLHGM@i4RmXg2wJklxmqSLPUobSTZGl3reDDMwqPNAip4HHBIGIC0aLtQ5cf5U31ZzZoYvs8QtsoqaCfwoivz2oWjN@oiowjEHobN7zvNud1bLJWHJ@JEbH@q8KWoLn1bpN14tsVLR@YSpwWRxqNzatIqUeS8UCvxv8sNfJSmoJ4s2ZPxMSYEDvy9JL22zjPwmnW8uMyaTJZCy8K7oYs71RidahWF4otW/5AkTrZF3d@K@5ugwDVJxoWHvekDlg@CII3gYQGdrjMpZMSszxUwZbEO58whn7BNJYBL6wd2zOHKvJeYzflzFtYA79qrLVV1lWOpc2lp6Mer0Hjvjy15313FXH7097MQ2w4/XoTHK3HKMV3t//89OG0yj0dhs58bRc69cFgFrxEq3Wt39BybxRHhe3O9uGCzE5uUP "Python 2 – Try It Online"

# [Jelly], 7 bytes D²SƊÐL’ [Try it online!][TIO-khpb7etc] [Jelly]: https://github.com/DennisMitchell/jelly [TIO-khpb7etc]: https://tio.run/##y0rNyan8/9/l0KbgY12HJ/g8apj5/3D7o6Y1//9HG@ooGOkoGOsomOgomOoomOkomOsoWOgoWOooGBoAMVDeEKjAEKjC0CQWAA "Jelly – Try It Online" Returns truthy (≠0) for happy numbers and falsy (0) for sad numbers. ## Explanation D²SƊÐL’ Main monadic link ÐL Repeat until the results are no longer unique Ɗ ( D Decimal digits ² Square [each] S Sum Ɗ ) ’ Decrement

# [Runic Enchantments], 60 bytes Duqi/'^̖1}͍?X)1l+\ Rc4*-:0(4*?:*}!/ /:'%≠?@'/Squ \?=1:+\ [Try it online!][TIO-knibi8gf] [Runic Enchantments]: https://github.com/Draco18s/RunicEnchantments/tree/Console [TIO-knibi8gf]: https://tio.run/##KyrNy0z@/9@ltDBTXz3uzDTD2rO99hGahjnaMVxBySZaulYGGiZa9lZatYr6XPpW6qq2Z3bYO6jrBxeWcsXY2xpaacf8/29oAAA "Runic Enchantments – Try It Online" Still working on the path visualizer, but it's coming along pretty nicely. ![image.png](/image?hash=e7d4f6b206b277e60b5f968a65d9653e1adaf003763ed14c53ae626f6e81ae36) Visualizer displays unicode combining characters as boxes (Unity issue) and there's still folds in the line corners and the occasional path overlap that's hard to avoid (but I manually hid those). Bends when it switches from skip to not skip (top right) are also hard to fix, as are bends after wrapping. Program starts at the `^̖` (top, blue) and while it initializes pointing up, the reflection modifier bounces it to the left (this is 1 byte shorter, due to the space available on the first line and where things line up on the last line--this is rare!). Basically the program reads in a number, concats a `/` onto it, then parses it into a sequence of characters (top left), subtracts 48 from each and squares (green) using "value less than 0" as a loop terminator (loop exit the thin red bit). Then adds the stack back up again (top right), adds 1 (`/` is ascii 47, so the program add a -1 to the sum; popping and adding a zero didn't fit on the second line; bottom left), then checks for 1-ness and 37-ness (ascii `%`; bottom two, left). If not, it concats a new `/`, and re-enters the initial loop (third line, right). If 1 or 37, print the entire stack (the only remaining value being a 1 or 37). There's also a rare "not-equals" for checking for 37-ness, as boolean negation isn't very optimal (takes a lot of space), involves swapping the locations of the two halves of the logic, or `!` skipping if one of the sides is only a single instruction. The latter is true here, but the extra command, saving 1 byte, moves the `@` out of line to receive the 1-ness exit, so an extra `@` is needed.

# [Husk], 6 bytes ←ω(ṁ□d [Try it online!](https://tio.run/##yygtzv7//1HbhPOdGg93Nj6atjDl////hpbGAA "Husk – Try It Online") or [Verify first 99 values][TIO-km298wsn] [Husk]: https://github.com/barbuz/Husk [TIO-km298wsn]: https://tio.run/##AT0Awv9odXNr/20owqcrb2ArIiAtPiAic28/InRydWUiImZhbHNlIuKCgSnhuKP/4oaQz4ko4bmB4pahZP///zk5 "Husk – Try It Online" ## Explanation ``` ←ω(ṁ□d ω( repeat the following until fixpoint: d get the digits ṁ□ sum of their squares ← decrement