Changes between Version 2 and Version 3 of libpipi/sandbox


Ignore:
Timestamp:
10/22/2008 03:57:47 PM (16 years ago)
Author:
Sam Hocevar
Comment:

C code for the Cantor polynomial

Legend:

Unmodified
Added
Removed
Modified
  • libpipi/sandbox

    v2 v3  
    2626$x = k - y$
    2727}}}
     28
     29The following C code works OK for values up to 10,000 (higher values may cause overflows), which potentially allows for procedural terapixel images.
     30
     31{{{
     32#!c
     33for(int y = 0; y < 10000; y++)
     34    for(int x = 0; x < 10000; x++)
     35    {
     36        int n = (x + y) * (x + y + 1) / 2 + y;
     37        int k = (sqrt((double)(n * 8 + 1)) - 1) / 2;
     38        int y2 = n - k * (k + 1) / 2;
     39        int x2 = k - y2;
     40        if(x != x2 || y != y2)
     41            printf("ERROR! %i %i -> %i -> %i %i\n", x, y, n, x2, y2);
     42    }
     43}}}