Skip to content

Instantly share code, notes, and snippets.

@KolevDarko
Created March 29, 2023 09:16
Show Gist options
  • Save KolevDarko/686334ecfc50c1d6b285fd54b712a24e to your computer and use it in GitHub Desktop.
Save KolevDarko/686334ecfc50c1d6b285fd54b712a24e to your computer and use it in GitHub Desktop.
Yul prime number
function isPrime(uint256 x) external pure returns (bool ret) {
ret = true;
assembly {
let halfX := add(div(x, 2), 1)
for {let i := 1} lt(i, halfX) {i := add(i, 1)} {
if iszero(mod(x, i)) {
ret := 0
break
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment