Last active
September 25, 2022 15:06
-
-
Save eugenioclrc/af4d257524ba99d67ad0d205def27aa0 to your computer and use it in GitHub Desktop.
Whitenoise challenge submission
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: UNLICENSED | |
pragma solidity 0.8.15; | |
interface ISolution { | |
/// @dev Returns the EOA you will be calling the Challenge contract | |
/// from. Used to ensure your solution cannot be used by other | |
/// participants. | |
function owner() external view returns (address); | |
/// @dev Your solution to the problem. | |
/// @return abi.encodePacked(uint128(evenSum), uint128(oddSum)) | |
function solve(uint256) external returns (uint256); | |
} | |
contract Solution is ISolution { | |
address public constant owner = 0xOWNERADDRESS; | |
constructor() { } | |
/// @dev Your solution to the problem. | |
// @return abi.encodePacked(uint128(evenSum), uint128(oddSum)) | |
/// 8 bit packed | |
function solve(uint256 input) external pure returns (uint256 ret) { | |
assembly { | |
let even | |
let odd | |
let aux | |
for { let i := 0} lt(i, 32) { i:= add(i,1) } | |
{ | |
aux := shr(mul(sub(31, i), 8) , and(input, shr(mul(i, 8), 0xff00000000000000000000000000000000000000000000000000000000000000))) | |
switch mod(aux,2) | |
case 0 { even := add(even, aux) } | |
case 1 { odd := add(odd, aux) } | |
} | |
ret := or(odd, shl(128, even)) | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment