chapter6-code-3

PHOTO EMBED

Thu Mar 30 2023 09:49:18 GMT+0000 (Coordinated Universal Time)

Saved by @RareSkills

contract ExampleContract {

	function findPrimeFactor(uint256 x) public pure returns (uint256) {

		// start at 2, 1 is not a prime factor
		// use <= because x might be prime
		for(uint256 i = 2; i <= x; i++) {
			if (x % i == 0) {
				return i;
			}
		}
	}
}
content_copyCOPY