From 0e543919e418f3e0ab17192f57da20c30a2c3d1f Mon Sep 17 00:00:00 2001 From: chfr19820610-cell Date: Sat, 11 Jul 2026 23:18:40 +0800 Subject: [PATCH] feat: add 5 new tools (decimal_to_hex, hex_to_decimal, gcd, factorial, octal_to_decimal) Closes #193, Closes #194, Closes #195, Closes #196, Closes #197, Closes #198 --- tools/decimal_to_hex.py | 8 ++++++++ tools/factorial.py | 10 ++++++++++ tools/gcd.py | 11 +++++++++++ tools/hex_to_decimal.py | 8 ++++++++ tools/octal_to_decimal.py | 8 ++++++++ 5 files changed, 45 insertions(+) create mode 100644 tools/decimal_to_hex.py create mode 100644 tools/factorial.py create mode 100644 tools/gcd.py create mode 100644 tools/hex_to_decimal.py create mode 100644 tools/octal_to_decimal.py diff --git a/tools/decimal_to_hex.py b/tools/decimal_to_hex.py new file mode 100644 index 0000000..6298833 --- /dev/null +++ b/tools/decimal_to_hex.py @@ -0,0 +1,8 @@ +# tool: decimal_to_hex +# description: Converts a decimal integer to its hexadecimal string +# author: @chfr19820610-cell +# example: decimal_to_hex "255" -> "ff" + +def run(*args) -> str: + n = int(args[0]) + return hex(n)[2:] diff --git a/tools/factorial.py b/tools/factorial.py new file mode 100644 index 0000000..db84666 --- /dev/null +++ b/tools/factorial.py @@ -0,0 +1,10 @@ +# tool: factorial +# description: Computes the factorial of a non-negative integer +# author: @chfr19820610-cell +# example: factorial "5" -> "120" + +import math + +def run(*args) -> str: + n = int(args[0]) + return str(math.factorial(n)) diff --git a/tools/gcd.py b/tools/gcd.py new file mode 100644 index 0000000..42d3136 --- /dev/null +++ b/tools/gcd.py @@ -0,0 +1,11 @@ +# tool: gcd +# description: Finds the greatest common divisor of two integers +# author: @chfr19820610-cell +# example: gcd "12" "8" -> "4" + +import math + +def run(*args) -> str: + a = int(args[0]) + b = int(args[1]) + return str(math.gcd(a, b)) diff --git a/tools/hex_to_decimal.py b/tools/hex_to_decimal.py new file mode 100644 index 0000000..53a5cdf --- /dev/null +++ b/tools/hex_to_decimal.py @@ -0,0 +1,8 @@ +# tool: hex_to_decimal +# description: Converts a hexadecimal string to its decimal integer value +# author: @chfr19820610-cell +# example: hex_to_decimal "ff" -> "255" + +def run(*args) -> str: + hex_str = args[0] + return str(int(hex_str, 16)) diff --git a/tools/octal_to_decimal.py b/tools/octal_to_decimal.py new file mode 100644 index 0000000..3424313 --- /dev/null +++ b/tools/octal_to_decimal.py @@ -0,0 +1,8 @@ +# tool: octal_to_decimal +# description: Converts an octal string to its decimal integer value +# author: @chfr19820610-cell +# example: octal_to_decimal "77" -> "63" + +def run(*args) -> str: + octal = args[0] + return str(int(octal, 8))