This was an attempt to see how small I could make a decoder of base-26
numbers, encoded in ASCII uppercase. Answer: 58 characters. Can this
be improved?

    /* Code golf, from 
http://www.reddit.com/r/programming/comments/brsd0/use_the_right_tool_for_the_job/c0o9dii
 */
    s;main(c){while(c=getchar()+1)s=26*s+c-66;printf("%d",s);}

Example usage:

    : kra...@inexorable:~/devel/inexorable-misc ; gcc base26.c -o base26
    base26.c:2: warning: data definition has no type or storage class
    base26.c: In function ‘main’:
    base26.c:2: warning: incompatible implicit declaration of built-in function 
‘printf’
    : kra...@inexorable:~/devel/inexorable-misc ; echo -n 'AA' | ./base26; echo
    0
    : kra...@inexorable:~/devel/inexorable-misc ; echo -n 'BA' | ./base26; echo
    26
    : kra...@inexorable:~/devel/inexorable-misc ; echo -n 'ASDF' | ./base26; 
echo
    12251


This software is available via

    git clone http://canonical.org/~kragen/sw/inexorable-misc.git

(or in <http://canonical.org/~kragen/sw/inexorable-misc>) in the file
`base26.c`.

Like everything else posted to kragen-hacks without a notice to the
contrary, this software is in the public domain.

-- 
To unsubscribe: http://lists.canonical.org/mailman/listinfo/kragen-hacks

Reply via email to