|laziness, impatience, and hubris|
JPEG Zig-Zagby blackle (Beadle)
|on Oct 29, 2012 at 17:07 UTC||Need Help??|
For the last week I've been trying to figure out an algorithm for JPEG's zig-zag spacefilling curve. Specifically, I wanted an algorithm that maps all elements in an NxN matrix to a N*N array given their x and y values. I finally figured it out with the help of my analysis 101 TA. He's not a computer scientist, but he knows what pairing functions are. Anyway, after a few hours messing with perl, I made this subroutine:
To use it, you do something like this:
For $size = 10 the loop will yield:
The body of getPos has 65 (non-whitespace) characters, any ideas on how to get it even smaller?
Here's the function sans obfuscation:
UPDATE: This prints a JPEG zig-zag when $ARGV is the size of the matrix:
97 characters! I started at 125!