Communities

Writing
Writing
Codidact Meta
Codidact Meta
The Great Outdoors
The Great Outdoors
Photography & Video
Photography & Video
Scientific Speculation
Scientific Speculation
Cooking
Cooking
Electrical Engineering
Electrical Engineering
Judaism
Judaism
Languages & Linguistics
Languages & Linguistics
Software Development
Software Development
Mathematics
Mathematics
Christianity
Christianity
Code Golf
Code Golf
Music
Music
Physics
Physics
Linux Systems
Linux Systems
Power Users
Power Users
Tabletop RPGs
Tabletop RPGs
Community Proposals
Community Proposals
tag:snake search within a tag
answers:0 unanswered questions
user:xxxx search by author id
score:0.5 posts with 0.5+ score
"snake oil" exact phrase
votes:4 posts with 4+ votes
created:<1w created < 1 week ago
post_type:xxxx type of post
Search help
Notifications
Mark all as read See all your notifications »
Challenges

Post History

60%
+1 −0
Challenges Collatz conjecture; Count the tries to reach $1$

Wolfram Language (Mathematica), 38 bytes Tr[1^ResourceFunction["Collatz"]@#]-1& Don't Try it online! Doesn't work on TIO due to using the Collatz builtin which needs to be downloaded from ...

posted 2y ago by romanp‭  ·  edited 2y ago by romanp‭

Answer
#3: Post edited by user avatar romanp‭ · 2022-05-10T17:20:00Z (over 2 years ago)
  • # [Wolfram Language (Mathematica)], 38 bytes
  • ```Tr[1^ResourceFunction["Collatz"]@#]-1&```
  • Don't [Try it online!][TIO-l2z7430a]
  • Doesn't work on TIO due to using the Collatz builtin which needs to be downloaded from the [Function Repository](https://resources.wolframcloud.com/FunctionRepository/resources/Collatz)
  • [Wolfram Language (Mathematica)]: https://www.wolfram.com/wolframscript/
  • [TIO-l2z7430a]: https://tio.run/##y00syUjNTSzJTE78n2b7P6Qo2jAuKLU4v7QoOdWtNC@5JDM/L1rJOT8nJ7GkSinWQTlW11Dtf0BRZl5JdJq@Q1BiXnpqtKFBbOx/AA "Wolfram Language (Mathematica) – Try It Online"
  • Relatively badly-golfed version without ResourceFunction (52 bytes):
  • `i=0;If[#!=1,i++;#0[If[EvenQ@#,Floor[#/2],3 #+1]],i]&`
  • [Try it online!](https://tio.run/##y00syUjNTSzJTE78/z@gKDOvJDrT1sDaMy1aWdHWUCdTW9ta2SAayHUtS80LdFDWccvJzy@KVtY3itUxVlDWNoyN1cmMVXMwj/3/HwA)
  • Had to add a slightly janky print statement into the main body for the value of i to get reset on each evaluation.
  • # [Wolfram Language (Mathematica)], 38 bytes
  • Tr[1^ResourceFunction["Collatz"]@#]-1&
  • Don't [Try it online!][TIO-l2z7430a]
  • Doesn't work on TIO due to using the Collatz builtin which needs to be downloaded from the [Function Repository](https://resources.wolframcloud.com/FunctionRepository/resources/Collatz)
  • [Wolfram Language (Mathematica)]: https://www.wolfram.com/wolframscript/
  • [TIO-l2z7430a]: https://tio.run/##y00syUjNTSzJTE78n2b7P6Qo2jAuKLU4v7QoOdWtNC@5JDM/L1rJOT8nJ7GkSinWQTlW11Dtf0BRZl5JdJq@Q1BiXnpqtKFBbOx/AA "Wolfram Language (Mathematica) – Try It Online"
  • Relatively badly-golfed version without ResourceFunction (52 bytes):
  • i=0;If[#!=1,i++;#0[If[EvenQ@#,Floor[#/2],3 #+1]],i]&
  • [Try it online!](https://tio.run/##y00syUjNTSzJTE78/z@gKDOvJDrT1sDaMy1aWdHWUCdTW9ta2SAayHUtS80LdFDWccvJzy@KVtY3itUxVlDWNoyN1cmMVXMwj/3/HwA)
  • Had to add a slightly janky print statement into the main body for the value of i to get reset on each evaluation.
#2: Post edited by user avatar romanp‭ · 2022-05-10T17:19:06Z (over 2 years ago)
  • # [Wolfram Language (Mathematica)], 38 bytes
  • `Tr[1^ResourceFunction["Collatz"]@#]-1&`
  • Don't [Try it online!][TIO-l2z7430a]
  • Doesn't work on TIO due to using the Collatz builtin which needs to be downloaded from the [Function Repository](https://resources.wolframcloud.com/FunctionRepository/resources/Collatz)
  • [Wolfram Language (Mathematica)]: https://www.wolfram.com/wolframscript/
  • [TIO-l2z7430a]: https://tio.run/##y00syUjNTSzJTE78n2b7P6Qo2jAuKLU4v7QoOdWtNC@5JDM/L1rJOT8nJ7GkSinWQTlW11Dtf0BRZl5JdJq@Q1BiXnpqtKFBbOx/AA "Wolfram Language (Mathematica) – Try It Online"
  • Relatively badly-golfed version without ResourceFunction (52 bytes):
  • `i=0;If[#!=1,i++;#0[If[EvenQ@#,Floor[#/2],3 #+1]],i]&`
  • [Try it online!](https://tio.run/##y00syUjNTSzJTE78/z@gKDOvJDrT1sDaMy1aWdHWUCdTW9ta2SAayHUtS80LdFDWccvJzy@KVtY3itUxVlDWNoyN1cmMVXMwj/3/HwA)
  • Had to add a slightly janky print statement into the main body for the value of i to get reset on each evaluation.
  • # [Wolfram Language (Mathematica)], 38 bytes
  • ```Tr[1^ResourceFunction["Collatz"]@#]-1&```
  • Don't [Try it online!][TIO-l2z7430a]
  • Doesn't work on TIO due to using the Collatz builtin which needs to be downloaded from the [Function Repository](https://resources.wolframcloud.com/FunctionRepository/resources/Collatz)
  • [Wolfram Language (Mathematica)]: https://www.wolfram.com/wolframscript/
  • [TIO-l2z7430a]: https://tio.run/##y00syUjNTSzJTE78n2b7P6Qo2jAuKLU4v7QoOdWtNC@5JDM/L1rJOT8nJ7GkSinWQTlW11Dtf0BRZl5JdJq@Q1BiXnpqtKFBbOx/AA "Wolfram Language (Mathematica) – Try It Online"
  • Relatively badly-golfed version without ResourceFunction (52 bytes):
  • `i=0;If[#!=1,i++;#0[If[EvenQ@#,Floor[#/2],3 #+1]],i]&`
  • [Try it online!](https://tio.run/##y00syUjNTSzJTE78/z@gKDOvJDrT1sDaMy1aWdHWUCdTW9ta2SAayHUtS80LdFDWccvJzy@KVtY3itUxVlDWNoyN1cmMVXMwj/3/HwA)
  • Had to add a slightly janky print statement into the main body for the value of i to get reset on each evaluation.
#1: Initial revision by user avatar romanp‭ · 2022-05-09T21:02:48Z (over 2 years ago)
# [Wolfram Language (Mathematica)], 38 bytes

`Tr[1^ResourceFunction["Collatz"]@#]-1&`

Don't [Try it online!][TIO-l2z7430a]

Doesn't work on TIO due to using the Collatz builtin which needs to be downloaded from the [Function Repository](https://resources.wolframcloud.com/FunctionRepository/resources/Collatz)

[Wolfram Language (Mathematica)]: https://www.wolfram.com/wolframscript/
[TIO-l2z7430a]: https://tio.run/##y00syUjNTSzJTE78n2b7P6Qo2jAuKLU4v7QoOdWtNC@5JDM/L1rJOT8nJ7GkSinWQTlW11Dtf0BRZl5JdJq@Q1BiXnpqtKFBbOx/AA "Wolfram Language (Mathematica) – Try It Online"


Relatively badly-golfed version without ResourceFunction (52 bytes):

`i=0;If[#!=1,i++;#0[If[EvenQ@#,Floor[#/2],3 #+1]],i]&`

[Try it online!](https://tio.run/##y00syUjNTSzJTE78/z@gKDOvJDrT1sDaMy1aWdHWUCdTW9ta2SAayHUtS80LdFDWccvJzy@KVtY3itUxVlDWNoyN1cmMVXMwj/3/HwA)

Had to add a slightly janky print statement into the main body for the value of i to get reset on each evaluation.