Skip to content

Conversation

@GideonBature
Copy link
Contributor

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

@GideonBature
Copy link
Contributor Author

@coxmars This PR is ready for review and to be merged.

Copy link
Contributor

@coxmars coxmars left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@GideonBature Just adjust what I told you, if you are not using it just delete it or if you use it try to change that for our own functions from simple_math than creating a new one.

@GideonBature
Copy link
Contributor Author

@GideonBature Just adjust what I told you, if you are not using it just delete it or if you use it try to change that for our own functions from simple_math than creating a new one.

True, almost forgot that, was playing around with it while trying out other implementations, till I got a better way of using ASCII. Thank you for the review. Done as requested.

Copy link
Contributor

@coxmars coxmars left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM 🫡

@coxmars coxmars merged commit 396ff2b into Kaizenode:main May 2, 2025
2 checks passed
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

2 participants