0Ah, 5032, 91d, 8d, 1917, 3Eh, 27c3h, 1d4ch, 2453, 5d8h, 59d, 7537, 3c0h, a20h, 1337, 4h, 2B3h, f1dh, 32d, 2710

image.png

# quicksort.py
#
# getting familiar with the vs code and python
# Quick Sort Algorithm
#
import os

def quick_sort(arr):
    if len(arr) <= 1:
        return arr
    pivot = arr[0]
    left = [x for x in arr[1:] if x[0] < pivot[0]]
    right = [x for x in arr[1:] if x[0] >= pivot[0]]
    return quick_sort(left) + [pivot] + quick_sort(right)

def parse_token(token):
    original = token.strip()
    token = original.lower()

    handlers = {
        'h': lambda x: int(x[:-1], 16),
        'd': lambda x: int(x[:-1], 10),
        '': lambda x: int(x, 10),
    }

    if token.endswith('h'):
        value = handlers['h'](token)
    elif token.endswith('d'):
        value = handlers['d'](token)
    else:
        value = handlers[''](token)

    return (value, original)

def read_input(file_path):
    with open(file_path, 'r') as f:
        content = f.read().strip()
        tokens = [x.strip() for x in content.split(',') if x.strip()]
        parsed = [parse_token(token) for token in tokens]
        return parsed

def main():
    current_dir = os.path.dirname(os.path.abspath(__file__))
    input_file = os.path.join(current_dir, 'input.txt')
    try:
        parsed_numbers = read_input(input_file)
        sorted_pairs = quick_sort(parsed_numbers)
        sorted_originals = [x[1] for x in sorted_pairs]
        print("Sorted (original format):")
        print(sorted_originals)
    except Exception as e:
        print(f"Error processing file: {e}")

    print("end")
if __name__ == '__main__':
    main()