"Code golf" is a fun programming pastime that challenges you to solve a problem with the least amount of code possible. Like regular golf, the goal is to use fewest code "strokes" to hit the mark. Here's a recent challenge that was posted to me via Twitter.

@cjdinger@SASJedi got a fun puzzle for you guys, we've been discussing at my office.You have a character var with the string "000112010302". What's the least about of code that can be written to determine what is the highest number (3) in the string?

The answers were quick, creative, and diverse. I'll share a few of them here.

The winner, in terms of concision, came from FreelanceReinhard. He supplied a macro-function one-liner:

%sysfunc(findc(123456789,00112010302,b));

With this entry, FreelanceReinhard defied a natural algorithmic instinct to treat this as a numerical digit comparison problem, and instead approached it as simple pattern matching problem. The highest digit comes from a finite set (0..9). COMPRESS function is often used to eliminate matching characters from a string, but the k directive inverts the action to keep only the matching characters instead.

If you wanted to use the more traditional approach of looping through values, comparing, and keeping just the maximum value, then you can hardly do better than the code offered by hashman.