laindir
  • Member for 8 years
  • Last seen more than a month ago
Compare two integers in C or C++ without comparison operators
5 votes

64 61 characters main(a,b){scanf("%d%d",&a,&b);for(a-=b;a/2;a/=2);putchar(a);} Prints the character values of -1, 0, and 1 for less than, equal to, or greater than, respectively. ...

View answer
Tower of Hanoi Sort
5 votes

C - 2547172 for 55986 inputs There is a lot of room for improvement here. For my own sanity, I simplified this so that it was only possible to inspect the top element of each stack. Lifting this self-...

View answer
Sort-a-number. Sorta
5 votes

C - 65 r,t,i;s(n){for(;++i;)for(t=n;t;t/=10)r=t%10-i?r:10*r+i;return r;} The astute observer will note that this sorting algorithm runs in O(n) time on the number of digits in n. The pragmatic ...

View answer
Tips for golfing in AWK
4 votes

Techniques Thanks to Peter Taylor for pointing out the language-generic version of this question for which I did not bother to search. I'll try to limit this answer to things that are not available ...

View answer
Merge two sorted lists
3 votes

C - 75 This operates on NULL terminated arrays of int *, though it would work equally well for pointers to other types by substituting the appropriate comparison function for **b < **a (e.g., ...

View answer
Destroy Them With Lazers
2 votes

C - 2468 Not golfed at all, but hopefully it's a starting point for more interesting implementations. The implementation of intersect is cribbed heavily from Adrian Boeing. His pseudo-code was ...

View answer
Print the prime factorization of the greatest common divisor of two numbers
1 votes

awk - 115 111 96 85 New version can only handle one line of input. Thanks to durron597 for pointing out that I only need to make sure i <= $1. {for(i=1;++i<=$1;)for(;$1%i+$2%i==0;f[i]++){$1/=i;$...

View answer
Hunt the Wumpus
1 votes

awk - big This didn't turn out as short as I had hoped, but I took a slightly different approach to dealing with the graph, so I'm posting the ungolfed version anyway. I took advantage of the fact ...

View answer
Finding Local Extremes
1 votes

awk - 32 chars {c=b;b=a;a=$0;$0=b}(b-c)*(a-b)<0 No hope of beating a language like J or APL on brevity, but I thought I'd throw my hat into the ring anyway. Explanation: At any given time, a, b, ...

View answer
Output the nth digits of an integer
0 votes

awk - 53 {for(d=10^9;!int($1/d)||--$2;d/=10);$0=int($1/d)%10}1 trim digits by division, starting with max possible for 32 bit unsigned int when we hit the left side of the integer, int($1 / d) ...

View answer
The Floating Horde
0 votes

awk - 44 Characters {for(i=NF;i>1;){n=int($i/2);$i%=2;$--i+=n}}1

View answer