# Submission 088296b0...

Challenge Integer sorting 0x53b21be84eece2e... 2018-19-27 910782
``````/**
* This file is part of the 1st Solidity Gas Golfing Contest.
*
*/
pragma solidity ^0.4.24;

// 920981
contract Sort {
// event Qsort(uint, uint, uint);
function qsort(uint[] mem, uint start, uint end) public pure {
uint tmp = end - start;
// emit Qsort(tmp, start, end);
uint a;
uint b;
uint i;
uint j;

if (tmp == 4) {
a = mem[start];
b = mem[start + 1];
i = mem[start + 2];
j = mem[start + 3];
tmp = 0;

if (a > b) {a ^= b ^= a ^= b; tmp |= 3;}
if (i > j) {i ^= j ^= i ^= j; tmp |= 12;}

if (a > i) {a ^= i ^= a ^= i; tmp |= 5;}
if (b > j) {b ^= j ^= b ^= j; tmp |= 10;}

if (b > i) {b ^= i ^= b ^= i; tmp |= 6;}

if (tmp & 1 != 0) mem[start] = a;
if (tmp & 2 != 0) mem[start + 1] = b;
if (tmp & 4 != 0) mem[start + 2] = i;
if (tmp & 8 != 0) mem[start + 3] = j;
} else if (tmp > 2) {
tmp = mem[(start + end) / 2];
i = start;
j = end - 1;
while(true) {
a = mem[i];
b = mem[j];
while (a < tmp) {
a = mem[++i];
}
while (b > tmp) {
b = mem[--j];
}

if (i >= j) break;

mem[i++] = b;
mem[j--] = a;
}

qsort(mem, start, i);
qsort(mem, i, end);
} else if (tmp == 2) {
a = mem[start];
b = mem[start + 1];
if (a > b) {
mem[start] = b;
mem[start + 1] = a;
}
}
}

function sort(uint[] input) public pure returns(uint[]) {
qsort(input, 0, input.length);

return input;
}
}

``````