Rafał’s random comments – programming, IT, other

March 24, 2008

Fast blur algorithm in any language

Filed under: c++,contest,programing — limcore @ 3:34 pm

This time a real programming contest.

Write the fastest possible function that will blur (4×4) a gray-scale image ( char[1024][1024] ), for dual core 64 bit CPU.

Blurring image is quite simple, for each pixel, take value of surrounding pixels, sum them up, take average and use that.

Typically we would use 3×3 matrix – the pixel and the 8 pixels next to it; But lets use 4×4 here, as it probably may open more room for optimize (16 is nicer then 9 for computers 😉

Everyone can take part in this small competition; Submissions are up to 2008-05-20, after 1 week the results will be presented. All send source will be published as Open Source.

Programs may be in C++, also with C and asm, and also in any other language as well.

This page will be updated soon with more exact rules and possible test framework program.

Testing will be done on dual core, amd64 bit class CPU, under Linux based operating system; programs will be build with recent (ubuntu am64) compilers (i.e. recent gcc/g++).

Participants may include own Makefile (in example to choose compiler flags).

Testing program will create in memory an array: new char[1024*1024] and fill it with some values and pass it to your function.

Your function Blur_DoIt must:

  • will receive pointer to array of 1024*1024 chars
  • will return a pointer to array of 1024*1024 chars
  • it may mutate the input data in place and return the same pointer
  • or it may allocate new data (either once per program or in each execution) and return that
  • the resulting data must contain blurred image
  • each pixels new value is based on input data values around the point averaged
  • take columns x-1, x, x+1, x+2 in rows y-1, y, y+1, y+2 sum it up, divide by 16 and that is the result
  • algorithm can ignore 64 pixel borders from each side – that is, the resulting data may contain any values there and still it will be valid

You may use threads (dual core) etc, up to 512 MB ram. You may NOT use any files, network, execute any programs, erase my hard drive etc 😉

The testing program will execute test function 1000 times, checking timer before and after each call, and the program which sum of all times is the lowest wins.

All submissions – send to blog at limcore.com, with subject “blur” and with license that you release your code to public domain, as LGPL, BSD license, or other similar.

March 9, 2008

“Lol-Woot”

Filed under: c++,contest,tiny-code — limcore @ 3:30 am

How to make short as possible function that outputs “Lol-Woot”? Using ##C++ compiler-bot geordi by Eelis.

What is the shortest command to Geordi (counting from { to } ) that will make him output Lol,Woot
the text must be somehow crypted, anything above reverse order

So, simple geordi << “Lol, woot”; do not count. Also the code must not contain Lol-Woot nor tooW-loL strings.

From the oryginal encoding with 61 chars (67 for xor), we went down to 49, 48, and finally 42! (errno usage is not very legal here, so 44 is shortest legal).

Ok, actually here is 23 char version, but it is a hack – we all know it’s not encrypted 😉

// the oryginal – XOR
{char x[]=”Mmo,Ulnv”;for(int i=0;i<8;++i)cout<

Create a free website or blog at WordPress.com.