Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions tools/decimal_to_hex.py
Original file line number Diff line number Diff line change
@@ -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:]
10 changes: 10 additions & 0 deletions tools/factorial.py
Original file line number Diff line number Diff line change
@@ -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))
11 changes: 11 additions & 0 deletions tools/gcd.py
Original file line number Diff line number Diff line change
@@ -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))
8 changes: 8 additions & 0 deletions tools/hex_to_decimal.py
Original file line number Diff line number Diff line change
@@ -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))
8 changes: 8 additions & 0 deletions tools/octal_to_decimal.py
Original file line number Diff line number Diff line change
@@ -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))