Write a program to implement Hill Climbing Algorithm

import random

def fitness_function(x):
    return -(x - 3) ** 2 + 9  # Example function with a peak at x = 3

def hill_climb(start, step_size=0.1, max_iterations=1000):
    current = start
    for _ in range(max_iterations):
        neighbors = [current + step_size, current - step_size]
        best_neighbor = max(neighbors, key=fitness_function)
        if fitness_function(best_neighbor) <= fitness_function(current):
            break
        current = best_neighbor
    return current, fitness_function(current)

start_point = random.uniform(-10, 10)
best_x, best_fitness = hill_climb(start_point)
print(f"Best solution: x = {best_x}, fitness = {best_fitness}")