Created
August 11, 2023 18:20
-
-
Save fassko/b22c722f1d488528791f8c99e42c6a73 to your computer and use it in GitHub Desktop.
Created using remix-ide: Realtime Ethereum Contract Compiler and Runtime. Load this file by pasting this gists URL or ID at https://remix.ethereum.org/#version=soljson-v0.8.21+commit.d9974bed.js&optimize=false&runs=200&gist=
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.21; | |
contract NumberGame { | |
error ToLowerThanFrom(uint256 from, uint256 to); | |
error NumberTooHigh(uint256 from, uint256 number); | |
error NumberToLow(uint256 to, uint256 number); | |
uint256 private from; | |
uint256 private to; | |
constructor(uint256 _from, uint256 _to) { | |
if(_to < _from) { | |
revert ToLowerThanFrom(_from, _to); | |
} | |
from = _from; | |
to = _to; | |
} | |
function guess(uint256 number) external view returns(bool) { | |
if (number < from) { | |
revert NumberToLow(from, number); | |
} else if (number > to) | |
revert NumberTooHigh(to, number); | |
else { | |
return true; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment