This challenge is intended to utilize the C++ language as a means of solving a problem. However, language-specific challenges are generally discouraged on CG.

learn more… | top users | synonyms

7
votes
1answer
246 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 ...
-1
votes
1answer
139 views

Why does one stack variable have a weird address? [closed]

I was called a liar when I showed my output (while debugging a problem). So I thought I'll make it into a puzzle. The output of this code ... T a,b,c, d; printf("%p %p %p %p %d %d %d %d %d", &a, ...
3
votes
3answers
792 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 ...
2
votes
3answers
327 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 ...
7
votes
2answers
439 views

m3ph1st0s's programming puzzle 3 (C): “Easy bug”

This is the 3rd of my series of C/C++ puzzles; in case you missed the first 2 they are here: (1) m3ph1st0s's programming puzzle 1 (C++) (2) m3ph1st0s's programming puzzle 2 (C++): "Call ...
3
votes
4answers
334 views

Shortest undefined behavior sample in C++

What's the shortest, well-formed C++ code that exhibits undefined behavior?
-1
votes
1answer
198 views

Which is the most efficient prime algorithm? [closed]

Which is the most efficent and easy to understand prime algorithm in c++?
0
votes
11answers
544 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 ...
-2
votes
2answers
482 views

Conversion to palindrome with minimal points used

Input: a word (2-100 characters) Convert this word to a palindrome: delete character - 13 points add character - 12 points increase character - 5 points ('d' > 'e') decrease character - 4 points ...
5
votes
5answers
323 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 ...
1
vote
2answers
476 views

A small puzzle. Why does this code work the way it does? [closed]

This was given to me by a friend of mine, it prints out 0 through 9. We have been quite puzzled over this. Does anyone know why this works? #include <iostream> using namespace std; void x(int ...
2
votes
2answers
342 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
2answers
1k views

How can I loop through all the possibilites of building a panel with two diffenent block sizes?

Im trying to land an interview for a company in Austin, Tx. before I can be considered they asked me to solve a programming puzzle. I really need this interview. Your niece was given a set of ...
12
votes
7answers
2k views

Compute the CRC32 table at compile-time

The reference implementation of CRC32 computes a lookup table at runtime: /* Table of CRCs of all 8-bit messages. */ unsigned long crc_table[256]; /* Flag: has the table been computed? Initially ...
22
votes
3answers
2k views

Solve the eight queens problem at compile-time

Can you solve the eight queens puzzle at compile-time? Pick any suitable output format. I'm particularly interested in a C++ template metaprogramming solution, but you can use languages that have ...
18
votes
6answers
3k views

Generate the longest error message in C++

Write a short program, that would generate the longest possible error message, in a standard C++ compiler (gcc, cl.exe, icc, or clang). The score of each entry is the number of characters in the ...
20
votes
20answers
4k views

Print 1 to 1000 in C++ without semi-colons

Following this popular question, present your solution which prints the numbers 1 to 1000 (all of them, not the string "1 to 1000" verbatim or something funny) in C++ without using any semi-colons. ...
9
votes
4answers
835 views

Tips for golfing in C++

What general tips do you have for golfing in C++? I'm looking for ideas that can be applied to code golf problems in general that are at least somewhat specific to C++ (e.g. "remove comments" is not ...
6
votes
4answers
612 views

fizz buzz in TMP

The Fizz Buzz problem is a very basic problem to solve that is used by some to weed out interviewees that don't know how to program. The problem is: Set N = [0,100] Set F = x in N where x % 3 == 0 ...