2
votes
3answers
187 views

Preprocessing primality

The challenge: Given an integer N, 1 < N < 2³¹, write code that uses the C preprocessor to determine whether N is prime, and produces a "Hello world" program if N is prime, or an error ...
12
votes
14answers
3k views

Compare two integers in C or C++ without comparison operators

Produce the shortest program which takes two signed integers as input (through stdin or as arguments) and displays 3 different outputs depending upon whether the first number is (1) greater than, (2) ...
7
votes
1answer
264 views

Smallest Lua table copy

So I really like to mess with tables and shallow and deep copies and I can do it in 239 chars! I wonder if there's a shorter way to do it... Rules: It must be done in less than 239 chars. You must ...
18
votes
4answers
1k views

Add two numbers safely, in C

Everyone knows that C is a lovely, safe, high level programming language. However you, as a coder are set the following task. Write a program to add two numbers. Input: Two space separated ...
11
votes
14answers
1k views

Golfed+Fast sorting in C

[Latest update: benchmark program and preliminary resuls available, see below] So I want to test the speed/complexity tradeoff with a classic application: sorting. Write an ANSI C function that ...
14
votes
1answer
826 views

Create a C preprocessor

The goal is to create a preprocessor for the C language, as small as possible in terms of source code size in bytes, in your preferred language. Its input will be a C source file, and its output will ...
8
votes
8answers
1k views

Shortest C \ C++ function to generate -1, 0 ,1

Let a function receive two integers i and j between 0 and 3, it should return the value in position (i,j) in the following 2D array: 1, 0, -1, 0 1, 0, -1, 0 0, 1, 0, -1 0, -1, 0, 1 Shortest ...
0
votes
1answer
3k views

Smallest C code to Crash an Operating System? [duplicate]

A shortest C program, that can crash the Operating system, either on a Windows or a Linux PC... Rules: The code is to be developed in C language, but it may use other api, specific to linux or ...
12
votes
1answer
535 views

Implement an IEEE 754 64-bit binary floating point number through integer manipulation

(I've tagged the question "C" for the time being, but if you're aware of another language that supports unions, you can also use that.) Your task is to build the four standard mathematical operators ...
0
votes
2answers
240 views

Shortest conditional to run a specific statement: C code golf

Currently I have the code (expanded for your benefit): <number> != <number> ? printf("|\\"); : <number>; The idea here, is to do this condition in the least number of characters. ...
10
votes
20answers
3k views

print 1 to 100 without using recursion and conditions

can we print 1 to 100 without using any if conditions and loops in c&c++? Conditon: main point is you must not use recursion...and doesnt hardcode code in it for e.g print(1 2 3..etc);
5
votes
3answers
2k views

The shortest code to tell if a number is even or odd

One of my colleagues proposed us a challenge: to write the shortest C/C++ program to determine if a number is even or odd. These are the requirements: Get a number from keyboard, at run-time (not ...
3
votes
3answers
535 views

m3ph1st0s's programming puzzle 4 (C/C++): “3-way swap”

My last puzzle has generated some confusion and controversy so I decided to give up, for now, on those "replace one character"-type puzzles. Hope this 4th puzzle will redeem myself after all the ...
1
vote
11answers
652 views

Code-golf: square of the number of ones

I'm solving problem: in file "a.in" given the number N - length of the number consists of ones. Need to gets square of it, and put this in file "a.out". This is my shortest solution(150 bytes): char ...
7
votes
12answers
960 views

“First time” test

What is the shortest C expression that is defined to evaluated to false the first time and true for every time after that: Reference implementation: bool b = false; // you get this for free. (b ? ...
4
votes
2answers
441 views

HangOver ACM problem!

there is only one rule: get accept for this problem http://acm.ut.ac.ir/sc/problemset/view/1032! to submit your code, you need to create an account(if you don't want to do so, just post your code ...
6
votes
7answers
823 views

Shortest code that return SIGSEGV among the given languages

I come across a question in a coding competion "write a code that returns SIGSEGV(Segmentation fault ) " . Points were given on the basis of length of code. The prgramming languages available ...
3
votes
2answers
541 views

Fastest C/C++ comparison function for an opaque field containing doubles

Description: Write the fastest comparison function for an opaque field containing a double. Here is my example: // Three-way comparison function: // if a < b: negative result // if a > b: ...
3
votes
5answers
2k views

C: Output “tomorrow's date”

I'm a code golf novice, but I'm eager to give it a go. My challenge is: Write the shortest program in C which takes in a date D as input and outputs the date D + 1 day Rules: program must compile ...
2
votes
1answer
2k views

Poisson random number generator

What is the shortest function (implemented in C) that will return a random draw from a Poisson distribution (given the mean or λ parameter)? int random_poisson(double lambda);