Search Results
Search type | Search syntax |
---|---|
Tags | [tag] |
Exact | "words here" |
Author |
user:1234 user:me (yours) |
Score |
score:3 (3+) score:0 (none) |
Answers |
answers:3 (3+) answers:0 (none) isaccepted:yes hasaccepted:no inquestion:1234 |
Views | views:250 |
Code | code:"if (foo != bar)" |
Sections |
title:apples body:"apples oranges" |
URL | url:"*.example.com" |
Saves | in:saves |
Status |
closed:yes duplicate:no migrated:no wiki:no |
Types |
is:question is:answer |
Exclude |
-[tag] -apples |
For more details on advanced search visit our help page |
Code-golf is a competition to solve a particular problem in the fewest bytes of source code.
6
votes
Display Sentence in Alphabetical Order
C, 121
This is quite long compared to other entries, but it does not rely on any built-in sorting or ToLower functions:
j;main(k){char s[99],*p=s;gets(s);while(*p){j=p-s-1;k=*p++;while(j>=0&&(s[j] …
6
votes
It's a rainy day
Processing, 94 - 20 = 74
void setup(){background(0);fill(0,0,255);}
void draw(){ellipse(random(0,99),random(0,99),3,3);}
(New line added for readability.)
Click here for an online demo.
1
vote
Add without addition (or any of the 4 basic arithmetic operators)
Perl, 23
Since the question does not specify input types and formats, we assume that the input will be natural numbers in the unary number system.
chop($s=<>);print $s.<>
For example, if we are to …
4
votes
The shifting dot
C, 86
Assuming that seeding the rand() function is not required.
k=30;main(i){i=rand()%k;while(k--){printf("%*c\n",i+=i==30?-1:i==1||rand()%2?1:-1,46);}}
Explanation:
In C, in "%*c" the * means t …
22
votes
Accepted
Pitch dark (Earth Hour remembrance)
Bash, 28 or 12
Assuming default installation of Ubuntu 12.04 LTS.
gnome-screensaver-command -a
Automatically starts the screensaver, which is a black screen by default.
Edit: As suggested by @Gle …
3
votes
Pitch dark (Earth Hour remembrance)
Bash, 31 (or 52)
On a TTY, use the following script (assuming your default TTY background is black, which is true at least for Ubuntu 12.04 LTS):
setterm -foreground black
clear
Your TTY would sti …
2
votes
Linear Function Solver from Two Points (x,y)
JavaScript, 62 48
Thanks to @Michael for golfing it down with ES 6.
L=(a,b)=>[s=(b[1]-a[1])/(b[0]-a[0]),a[1]-s*a[0]]
Old version:
function L(a,b){return[s=(b[1]-a[1])/(b[0]-a[0]),a[1]-s*a[0]]}
…
6
votes
Display Frames from .txt file
Bash, 82
IFS=
clear
for((;;)){
while read a;do
[ "$a" ]&&echo $a||(sleep 1;clear)
done<$1
}
Assumes the file name of the .txt file is provided as the first argument to the script.
Note that a trai …
6
votes
Minimal code CPU stress-tester…
C, 52
t;main(s){for(scanf("%d",&s),t=time();time()-t<s;);}
Press Ctrl+C to exit.
5
votes
Minimal code CPU stress-tester…
Perl, 32
for($i=<>,$t=time;time-$t<$i;){}
Now the embarrassing part: I foolishly put $t=time in front of $i=<> and was furiously trying to figure out why it exits a few seconds early.
Again, Ctrl+ …
6
votes
Shortest program that displays a red 3D cube
Sage, 17
Note: after some research I realised that this does not use OpenGL.
cube(color='red')
Output:
I can finally beat Mathematica!
It uses Jmol (which comes with the Sage installation) to …
5
votes
Shortest Pong, AI vs AI
Scratch, 1605 – 50 = 1555
I don't know how to count the score here and it doesn't meet the "resizing the window" rule... I just thought it was fun. Some unrealistic speed though, and one known bug: i …
5
votes
Hello, new world! again
Brainfuck + C (196+77)
Not a very golfy answer, but I just think it is fun
Brainfuck:
++++++++++[>+++++++>++++>++++++++++>+++<<<<-]>++.>>+.+++++++..+++.<++++.>>++.<-.---------.++++++++++++++++++.>. …
2
votes
Shortest method to implement the Pythagorean Theorem
C, 100 chars (beats the other C solution by 1!)
A ridiculously inefficient algorithm.
x;f(a,b){for(;x-a*a-b*b;x=rand());printf("The hypotenuse of this right triangle is %.3f",sqrt(x));}
1
vote
Convert from base 10 to base 2 without built-in base conversions
C, 81
char b[17];i=15;main(x){scanf("%d",&x);while(i+1)b[i--]=(x&1)+48,x>>=1;puts(b);}
The output has strictly 16 bits (including padding zeros)