llama-4-maverick-17b-128e-instruct· Meta LMArena Human Preference 140K
Generate the Fibonacci sequence in a visual form using ASCII\
- User
Generate the Fibonacci sequence in a visual form using ASCII\
- 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
- The
generate_fibonaccifunction generates the Fibonacci sequence up to the nth number. - The
visualize_fibonaccifunction 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. - The
mainfunction calls the above two functions with a specified value ofn.
You can adjust the value of
nin themainfunction to generate more or fewer Fibonacci numbers. - The
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.