Skip to content

Instantly share code, notes, and snippets.

@ochaochaocha3
Last active December 23, 2015 10:18
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ochaochaocha3/6620028 to your computer and use it in GitHub Desktop.
Save ochaochaocha3/6620028 to your computer and use it in GitHub Desktop.
CodeIQ Q431 Restricted Words。リテラルを使わずに「Hello World」を出力する。整数拡張を忘れていて int ではなく char を使っていたり、変数に格納している数値が中途半端だったり、改めて見ると粗が目立つ。
#include <stdio.h>
int
main(void) {
char one = sizeof(char); /* is 1 by definition */
char zero = one >> one;
char two = one << one;
char four = two << one;
char five = four | one;
char six = four | two;
char eight = four << one;
char LF = eight | two; /* 0x10 */
char SP = one << five; /* 0x20 */
char H = (one << six) | eight; /* 0x48 */
char W = (one << six) | (one << four) | four | two | one; /* 0x57 */
char d = (one << six) | (one << five) | four; /* 0x64 */
char e = (one << six) | (one << five) | four | one; /* 0x65 */
char l = (one << six) | (one << five) | eight | four; /* 0x6c */
char o = (one << six) | (one << five) | eight | four | two | one; /* 0x6f */
char r = (one << six) | (one << five) | (one << four) | two; /* 0x72 */
putchar(H);
putchar(e);
putchar(l);
putchar(l);
putchar(o);
putchar(SP);
putchar(W);
putchar(o);
putchar(r);
putchar(l);
putchar(d);
putchar(LF);
return zero;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment