Skip to content

Instantly share code, notes, and snippets.

@Bort-777
Created January 3, 2018 19:04
Show Gist options
  • Save Bort-777/3f98f6880560c6a5171408f2057cf509 to your computer and use it in GitHub Desktop.
Save Bort-777/3f98f6880560c6a5171408f2057cf509 to your computer and use it in GitHub Desktop.
contract CalculateRace {
function test() returns (uint8[11] race) {
return _calculateRace([1, 3, 0, 0, 0, 0, 0, 0, 0, 0, 0],
[2, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0]);
}
function _calculateRace(uint8[11] _momRace, uint8[11] _dadRace) internal returns (uint8[11] race) {
bool remainder = false;
for (uint8 i = 0; i < 11; i++) {
race[i] = (_momRace[i] + _dadRace[i]) / 2;
if ((_momRace[i] + _dadRace[i]) % 2 != 0 && remainder) {
race[i] += 1;
remainder = false;
} else if ((_momRace[i] + _dadRace[i]) % 2 != 0) {
remainder = true;
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment