han
  • Member for 10 years, 2 months
  • Last seen more than a month ago
Draw the rainbow
2 votes

R, 184 170 bytes Making an image with fixed pixel dimensions turns out to be surprisingly tricky with R, whose plotting functions are mostly intended for statisticians. In particular R leaves extra ...

View answer
Point in convex hull (2D)
4 votes

Octave, 82 72 bytes d=dlmread(0,";");i=2:rows(d);~isna(glpk(i,[d(i,:)';~~i],[d(1,:)';1]))&&1 The idea is to check whether the linear program min { c'x : Ax=b, e'x=1, x >= 0 } has a solution, ...

View answer
Who is the sleepiest of them all?
1 votes

C, 70 bytes char*f(char*s){char*p=s[3]?f(s+2):s;return*s+s[2]>*p+p[2]?s[3]=0,s:p;} The function returns the most awake face. It modifies the input string in place, so as to return a null-...

View answer
Detect Time Travel
2 votes

Python, 170 165 bytes from datetime import* n=datetime.now c=n() while 1: p=c;c=n() if(c-p).days:print p,"%s:"%c,["%s? You mean we're in the future?","Back in good old %s."][c<p]%c.year This ...

View answer
What? No error?
8 votes

C++11 struct comp { comp operator compl () { return comp { }; } operator comp () { return comp { }; } compl comp () { return; comp { }; } }; int main() { comp com; compl com; } ...

View answer
Pseudosort a list in 2*n comparisons
Accepted answer
2 votes

Python, 7910 (7704 + 206) This was inspired by shell sort. I found relatively good coefficients for the gap sequence (g) by checking a few hundred alternatives. The number of comparisons is limited ...

View answer
Solve the eight queens problem at compile-time
7 votes

Here's a C++11 solution without any templates: constexpr int trypos( int work, int col, int row, int rows, int diags1, int diags2, int rowbit, int diag1bit, int diag2bit); constexpr int ...

View answer
When does (x == x+2)?
14 votes

The following is not standards compliant C, but should work on just about any 64-bit platform: int (*x)[0x2000000000000000];

View answer
When does (x == x+2)?
31 votes

GNU C supports structures with no members and size 0: struct {} *x = 0;

View answer
Underhanded Password Hashing
13 votes

C This may not be the flashiest contest entry, but I think the following is the kind of hash function that could have been made by any coder too clever for their own good, with a vague idea of the ...

View answer
Sum of positive integers.
1 votes

C, 70 72 characters s;main(i,c){for(;c--;i>0?s+=i:0)scanf("%d",s?&i:&c);printf("%d",s-1);} The results on the SPOJ site definitely seem unreal - I have no idea how to get this down to 63. ...

View answer
Find the minimum edit distance between two strings
5 votes

Python, 138 148 152 characters Ok, I knew the principle but had never implemented edit distance before, so here goes: x,y=raw_input().split() d=range(99) for a in x: c=d;d=[d[0]+1] for b,p,q in ...

View answer
Calculate ISBN-13 check digit
1 votes

C, 80 79 characters The function modifies the string in place, but returns the original string pointer to satisfy the problem requirements. s;char*f(char*p){for(s=2;*p;s+=7**p++)s+=9**p++;*p++=48+s%...

View answer
C: Output "tomorrow's date"
0 votes

106 100 characters Another entry that breaks the year rule by supporting only the years 1 to 9999, and also implements correct leap year handling instead of following requirements. The code simply ...

View answer
First-n Fibonacci sequence elements
0 votes

C99, 58 characters The following function fills an array of integers with the first n values from the Fibonacci sequence starting with 0. void f(int*a,int n){for(int p=0,q=1;n--;q+=*a++)*a=p,p=q;} ...

View answer
Say "Hello" to the world in ASCII art
17 votes

Perl 5.10 - 195 198 202 203 characters Here's an entry that does not require any libraries beyond basic regexp matching. The encoded string is 131 characters, and the code to decode and print it ...

View answer
Display Peter's keyboard pattern
2 votes

C, 98 104 characters Since no one else has done so yet, I thought I would try actually generating the string on the fly, using some kind of run-length encoding for ascending and descending runs. ...

View answer
Write a function that returns past tense of given verb
2 votes

C - 120 119 characters In typical C style, the function f updates a string buffer in place, assuming that the caller has reserved enough space for up to three extra characters. The second argument ...

View answer
Generating guitar tabs?
3 votes

C99 - 231 characters The chords are given on the command line, one argument per chord, and of course there is no input validation of any kind. #include<stdio.h> int main(int c,char**v){for(...

View answer
Implement wc (word count) shortest code wins
1 votes

C - 164 chars This is based on dmckee's code with FUZxxl's improvements, but shortened further and converted to standard C. The code reads from standard input only. Any sequence of one or more ...

View answer