Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon.

Pages: 1-

C macro challenge

Name: Anonymous 2013-09-22 6:46

It has to swap two values if the first is greater than second.
a and b are both signed 32 bit integers.
function: macro(a,b) if (a>b) swap(a,b)
Rules:
1.No conditionals or comparisons allowed.(Ternary ?:, >,<,<=,>= are not allowed).
2.Cannot contain C keywords(while,do,if,else),semicolons,braces,backwards/forwards slashes and any other C macros.
3.Can't use temporaries or external variables/data.

Name: Anonymous 2013-09-22 7:17

macro(a, b) ((((b) - (a)) & 0x80000000) && ((a) -= (b), (b) += (a), (a) = (b) - (a)))

Name: Anonymous 2013-09-22 7:19

>>2
Oops
macro(a, b) ((((b) - (a)) & 0x80000000) || ((a) -= (b), (b) += (a), (a) = (b) - (a)))

Name: Anonymous 2013-09-22 7:24

>>3
ffs it was right the first time. It's because I changed the code a bit and got confused. >>3 is correct if you change (b) - (a) to (a) - (b).

Don't change these.
Name: Email:
Entire Thread Thread List