kingmanas's blog

By kingmanas, history, 8 months ago, In English

Level 1:

if(CONDITION) cout << "YES"; else cout << "NO"; cout << '\n';

Level 2:

cout << (CONDITION ? "YES" : "NO") << '\n';

Level 3:

This one just came to me while reading this amazing blog by Swift.

cout << "NO\0YES" + 3 * CONDITION << '\n';

Maybe be also written as (thanks to Xellos for correction)

cout << &("NO\0YES"[3 * CONDITION]) << '\n';

With a bit of learning curve:

yeputons's one-liner:

puts(reinterpret_cast<const char*>(&(const int&)(218124110 - CONDITION * 01453204765)));

monsoon's one-liner:

cout << (char*)&(const int&)(23438671621410638LL >> (CONDITION << 5)) << '\n';

Level 4:

(by Alperen_T)

CONDITION && cout << "YES" || cout << "NO"; cout << '\n';

Please share other "YES-NO" one-liners you know. Will add it to this list.

Read more »

 
 
 
 
  • Vote: I like it
  • +61
  • Vote: I do not like it