From dfcf9577c58499b370fcd78062b69a2cf0bc14b9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Matei=20B=C4=83r=C3=AEl=C4=83?= Date: Tue, 8 Sep 2026 08:23:34 +0000 Subject: [PATCH] [tool] collatz_steps --- tools/collatz_steps.py | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) create mode 100644 tools/collatz_steps.py diff --git a/tools/collatz_steps.py b/tools/collatz_steps.py new file mode 100644 index 0000000..3a00a1e --- /dev/null +++ b/tools/collatz_steps.py @@ -0,0 +1,20 @@ +# tool: collatz_steps +# description: Returns the next element of a Collatz sequence for a given number +# author: @MateiB20 +# example: collatz_steps "6" -> "3" +def run(*args) -> str: + if len(args) != 1: + raise ValueError("Requires exactly one argument") + + num = args[0].lstrip("-") + + if num == "": + return "Error: Please provide a non-empty input." + + if not num.isdigit(): + return "Error: Please provide a numeric input." + + if int(num)%2==0: + return str(int(num)//2) + else: + return str(int(num)*3+1)