# Programming Challenges

Show 40 post(s) from this thread on one page
Page 3 of 19 First 123456713 ... Last
• 08-22-2003, 11:41 AM
o0zi
Did any of you ever read "The Code Book" by Simon Singh? He did what Sepero's just done, and had 10 levels of difficulty. If I remember rightly, there was a cash prize, but that was several years ago. Great read.
• 08-22-2003, 12:37 PM
tecknophreak
Quote:

Originally posted by o0zi
Did any of you ever read "The Code Book" by Simon Singh? He did what Sepero's just done, and had 10 levels of difficulty. If I remember rightly, there was a cash prize, but that was several years ago. Great read.
I'm actually in the process of reading that. Singh writes some damn good math books. I also read his Fermat's Theorem book(can't remember exactly what it was)...maybe Fermat's Enigma, or was that by someone else, ramble, ramble...
• 08-22-2003, 02:18 PM
Strogian
Quote:

Compute the complex product ( a + ib ) * ( c + id ) using only three real multiplications
You have no idea how much pain this problem gave me. :D

x = (a+b)(c+d)
y = ac
z = bd

• 08-22-2003, 03:33 PM
o0zi
(claps Strogian) Ingenious, absolutely ingenious...:)
• 08-22-2003, 05:00 PM
Hey strogian g/j, you got all my challenges. :)

Here's another challenge:
rand( ) in C generates a flat distribution of numbers; you are equally likely to get any given number the generator is capable of returning. If you histogram these numbers the histogram is relatively flat. Looking at the histogram ( sideways ) it might look like this:

x =0
xxxxxxxxxxx
xxxxxxxxxx
xxxxxxxxxxxx
xxxxxxxxxx
xxxxxxxxxxx
xxxxxxxxxxxx
xxxxxxxxxxxx
xxxxxxxxxxx
xxxxxxxxxxxx
xxxxxxxxxxx
xxxxxxxxxx
xxxxxxxxxxx
x = 2^32 - 1

Write a function such that the numbers are distributed as x^2. In other words if you histogrammed many numbers from your function it would look like this ( sideways ):

x = -1
xxxxxxxxxxxxxxxxxxxxxxxxxxxxx
xxxxxxxxxxxxxxxxxxxxxxxx
xxxxxxxxxxxxxxx
xxxxxxxxxx
xxxxx
xx
x
xx
xxxx
xxxxxxxxxx
xxxxxxxxxxxxxx
xxxxxxxxxxxxxxxxxxxxxx
xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
x = 1

only produce numbers on the interval [-1,1] instead of [0,2^32-1]. Put your function in a small program that outputs to the console a 20 bin ( line ) histogram similar to the one's I've shown above to prove ( by eyeball method ) that your function works correctly. If you really want to show off the function's legitimacy compute the chi-squared. You are allowed to use your language's native flat-distribution random number generator in your program.
• 08-22-2003, 05:23 PM
trashthing
i have a challenge. write a program that reads a text file and prints out how many characters, numbers, letters, words, and lines there are.
• 08-22-2003, 07:44 PM
bwkaz
Quote:

Originally posted by trashthing
i have a challenge. write a program that reads a text file and prints out how many characters, numbers, letters, words, and lines there are.
Code:

```#!/bin/bash /usr/bin/wc "\$@"```
You just have to give it the right options... ;)
• 08-23-2003, 12:21 PM
o0zi
Another challenge: write a program that converts any decimal number to any base up to base 36, where numbers after 0-9 are represented by A-Z.
• 08-23-2003, 10:36 PM
Sepero
Quote:

Originally posted by o0zi
Convert decimal numbers to a base up to base 36, where numbers after 0-9 are represented by A-Z.
Cool. I only thought I had to do 36base, but after re-reading it, I see he wanted "up to base 36". After a few modifications, it does binary, octal, hex, up to base36 and everything inbetween!!! :D
• 08-23-2003, 10:40 PM
Sepero
I'm attaching the binary for any non-C++ programmers. I might actually use this program sometime, so I thought you guys might too. :)
• 08-24-2003, 02:59 AM
o0zi
Cool solution. You put it under the LGPL? There's a man with principles:p
• 08-24-2003, 04:04 AM
Sepero
Thanks for the compliment.(Notice my signature) :D
I was gonna use GPL, but I figured it's a little extreme for something small as this.
• 08-25-2003, 06:42 PM
Challenge: Write a function that reverses the bits of an integer, i.e. 100110 -> 011001. The shorter the function the better. This is an essential procedure when coding a fast fourier transform.
• 08-25-2003, 07:38 PM
tecknophreak
do you mean like this:

Code:

```unsigned int x(1000); return ~x;```
or
Code:

```unsigned int reverseBits(unsigned int x) {     unsigned int res(0), cntr(0xFFFFFFFF);     while (cntr) {           cntr >>= 1;           res <<= 1;           res |= x & 1;           x >>= 1;     }     return res; }```
• 08-25-2003, 08:08 PM