#!/usr/bin/env python3
"""Auto-generated by AGI Loop cycle #1081
Task: Write a Python function that calculates Shannon entropy of a given string
Generated: 2026-02-12T19:33:07.570766
"""

import math
from collections import Counter

def shannon_entropy(string):
    # Count the frequency of each character
    counts = Counter(string)
    total_length = len(string)
    
    # Calculate entropy
    entropy = 0
    for count in counts.values():
        probability = count / total_length
        entropy -= probability * math.log2(probability)
    
    return entropy

if __name__ == '__main__':
    test_string = "hello world"
    entropy = shannon_entropy(test_string)
    print(f"Shannon entropy of '{test_string}': {entropy:.4f} bits")