Created
December 2, 2022 22:06
-
-
Save karmacoma-eth/01227912ad012fdd8056dbf7819c4bb2 to your computer and use it in GitHub Desktop.
FizzBuzz in Solidity but ridiculous
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// SPDX-License-Identifier: MIT | |
pragma solidity 0.8.15; | |
import {console2} from "forge-std/console2.sol"; | |
contract FizzBuzz { | |
modifier fizz(uint256 n) { | |
_; | |
if (n % 3 == 0 && n % 5 != 0) { | |
console2.log("Fizz"); | |
} | |
} | |
modifier buzz(uint256 n) { | |
_; | |
if (n % 5 == 0 && n % 3 != 0) { | |
console2.log("Buzz"); | |
} | |
} | |
modifier both(uint256 n) { | |
_; | |
if (n % 3 == 0 && n % 5 == 0) { | |
console2.log("Fizz Buzz"); | |
} | |
} | |
modifier neither(uint256 n) { | |
_; | |
if (n % 3 != 0 && n % 5 != 0) { | |
console2.log(n); | |
} | |
} | |
modifier recurse(uint256 n) { | |
_; | |
if (n > 1) { | |
fizzbuzz(n - 1); | |
} | |
} | |
function fizzbuzz(uint256 n) public fizz(n) buzz(n) both(n) neither(n) recurse(n) {} | |
} | |
contract FizzBuzzTest { | |
FizzBuzz fizzbuzz; | |
function setUp() public { | |
fizzbuzz = new FizzBuzz(); | |
} | |
function testFizzbuzz100() public { | |
fizzbuzz.fizzbuzz(100); | |
} | |
} |
Author
karmacoma-eth
commented
Dec 2, 2022
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment