Skip to content
The Chat Archive
llama-4-maverick-17b-128e-instruct· Meta LMArena Human Preference 140K

Generate the Fibonacci sequence in a visual form using ASCII\

  1. User

    Generate the Fibonacci sequence in a visual form using ASCII\

  2. Assistant

    Fibonacci Sequence in ASCII Art

    Below is a Python code snippet that generates the Fibonacci sequence and visualizes it using ASCII art.

    def generate_fibonacci(n):
        """Generate the Fibonacci sequence up to the nth number."""
        fib_sequence = [0, 1]
        while len(fib_sequence) < n:
            fib_sequence.append(fib_sequence[-1] + fib_sequence[-2])
        return fib_sequence
    
    def visualize_fibonacci(fib_sequence):
        """Visualize the Fibonacci sequence using ASCII art."""
        for i, num in enumerate(fib_sequence):
            print(' ' * (len(fib_sequence) - i - 1) + '*' * num)
    
    def main():
        n = 10  # Change this to generate more or fewer Fibonacci numbers
        fib_sequence = generate_fibonacci(n)
        print("Fibonacci Sequence:")
        print(fib_sequence)
        print("\nASCII Art Representation:")
        visualize_fibonacci(fib_sequence)
    
    if __name__ == "__main__":
        main()
    

    Example Output

    When you run this code, it will generate the first 10 Fibonacci numbers and visualize them using ASCII art. The output will look something like this:

    Fibonacci Sequence:
    [0, 1, 1, 2, 3, 5, 8, 13, 21, 34]
    
    ASCII Art Representation:
             *
            **
            **
           ***
          *****
         ********
        *************
       *********************
      *********************************
     ***************************************
    

    How it Works

    1. The generate_fibonacci function generates the Fibonacci sequence up to the nth number.
    2. The visualize_fibonacci function takes the generated Fibonacci sequence and prints an ASCII art representation. It uses the value of each Fibonacci number to determine the number of asterisks (*) to print on each line.
    3. The main function calls the above two functions with a specified value of n.

    You can adjust the value of n in the main function to generate more or fewer Fibonacci numbers.

Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.

Generate the Fibonacci sequence in a visual form using ASCII\ · The Chat Archive