2014-09-25

Change 1 character puzzle #2

Add or replace at most 1 character in the longest line of the following program so that it will print 20 dots. There are at least 10 solutions.

#include <stdio.h>
int main() {
  int i, n = 20; for (i = -n; n > i; i++) putchar('.');
  return 0;
}

SPOILER ALERT! Here are 10 solutions:

int i, n = 10; for (i = -n; n > i; i++) putchar('.');
int i, n = 20; for (i = -0; n > i; i++) putchar('.');
int i, n = 20; for (i = -!n; n > i; i++) putchar('.');
int i, n = 20; for (i = n-n; n > i; i++) putchar('.');
int i, n = 20; for (i = -n; !n > i; i++) putchar('.');
int i, n = 20; for (i = -n; 0 > i; i++) putchar('.');
int i, n = 20; for (i = -n; n * i; i++) putchar('.');
int i, n = 20; for (i = -n; n & i; i++) putchar('.');
int i, n = 20; for (i = -n; n = i; i++) putchar('.');
int i, n = 20; for (i = -n; n , i; i++) putchar('.');

No comments: