Skip to content

Conversation

@GideonBature
Copy link
Contributor

Overview

This PR implements the classic FizzBuzz problem in Cairo as requested in issue #216. The implementation follows the standard rules:

  • For numbers divisible by 3, print "Fizz"
  • For numbers divisible by 5, print "Buzz"
  • For numbers divisible by both 3 and 5, print "FizzBuzz"
  • Otherwise, print the number itself

Implementation Details

  • Created a new Scarb project in examples/cairo/scripts/fizzbuzz/
  • Implemented the main fizzbuzz function that takes a number n and returns an array of strings from 1 to n
  • Created a utility function u32_to_felt252 to convert numbers to string representation
  • Added comprehensive test cases covering multiple edge cases

File Structure

  • .tool-versions: Specifies Scarb version 2.11.2
  • Scarb.toml: Project configuration
  • src/fizz_buzz.cairo: Main FizzBuzz implementation
  • src/utils/number_converter.cairo: Utility functions for number-to-string conversion
  • tests/test_fizzbuzz.cairo: Test cases validating the implementation

Testing

The implementation includes tests for various input values:

  • Test with n=3: Validates handling of numbers 1-3, including the "Fizz" case
  • Test with n=5: Validates handling of numbers 1-5, including both "Fizz" and "Buzz" cases
  • Test with n=15: Comprehensive test covering all possible cases including "FizzBuzz"

All tests pass successfully, confirming the implementation meets the requirements specified in issue #216.

🖼️ Screenshots (if applicable)

Screenshot 2025-04-25 at 1 08 05 PM

Related Issue

Closes #216

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[FEAT]: FizzBuzz Implementation in Cairo

1 participant