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.
1
vote
2
answers
479
views
Keep track of a Roulette game [closed]
You're writing a program for a new automated roulette croupier to be installed in a major casino. Unfortunately, the last guy bailed out on the company and published buggy software. You're stuck with …
9
votes
6
answers
619
views
Work out change [closed]
You are writing a program for an automatic cash register. The user needs change with the least number of coins used. Write a program which takes an amount (say $1.53) and gives change in US denominati …
3
votes
Reimplementing square root
return 1.f/InvSqrt(x);
InvSqrt of course courtesy of Quake.
What, you mean you wanted an accurate result?
2
votes
196 algorithm code golf
Python. 85 characters:
s,i=str,int;rs=lambda q:s(q)[::-1];n=i(input());
while rs(n)!=s(n):n+=i(rs(n));print n
If you don't want output on each iteration:
s,i=str,int;rs=lambda q:s(q)[::-1];n=i(inp …
2
votes
Reverse Polish notation
Python, 161 characters:
from operator import*;s=[];i=raw_input().split(' ')
q="*+-/";o=[mul,add,0,sub,0,div]
for c in i:
if c in q:s=[o[ord(c)-42](*s[1::-1])]+s
else:s=[float(c)]+s
print(s[0])
0
votes
Split a word into parts with equal scores
My solution is below. It is an almost anti-golf in its size, but it works very well. It supports n-way splits (although computational time becomes very long for any more than about 3 splits) and it su …
16
votes
Reverse stdin and place on stdout
Python, 41 40 bytes
import sys;print sys.stdin.read()[::-1]
41 -> 40 - removed semicolon at end of program.
Probably could be optimised!
3
votes
5
answers
465
views
Generate cyclic numbers in decimal
The formula on the wiki article for cyclic numbers can be used to generate cyclic numbers in any base. Using this formula, or any other appropriate formula, compute the first ten cyclic numbers in bas …
9
votes
9
answers
878
views
Split a word into parts with equal scores
Assuming A=1, B=2... Z=26, and the value of a word is the sum of these letter values, it is possible to split some words into two pieces such that they have equal values.
For example, "wordsplit" can …
14
votes
6
answers
7k
views
Calculate the last digits of Graham's Number
Graham's number ends in a 7. It is a massive number, in theory requiring more information to store than the size of the universe itself. However it is possible to calculate the last few digits of Grah …
68
votes
140
answers
12k
views
Reverse stdin and place on stdout
Requirements:
Take an input on stdin including new lines / carriage returns of unlimited length (only bounded by system memory; that is, there is no inherent limit in the program.)
Output the revers …
11
votes
18
answers
774
views
Output nearby primes
Write a program which takes an input (which may or may not be prime), and lists the immediate prime following and preceding it.
Example input:
1259
Example output:
1249 1277
Shortest program wi …
20
votes
5
answers
1k
views
Fix a broken random function
A friend has an add-on card in their computer which generates a perfectly random number from 1 to 5 inclusive. Unfortunately, they spilt cola on it somehow, and it now generates only 2's for all numbe …
7
votes
17
answers
4k
views
Multiply without multiply [closed]
Write the fastest (best big-O) and smallest multiplication algorithm for positive integers, without using multiplication operators. You are only allowed addition, subtraction, logical functions (AND, …
6
votes
3
answers
779
views
Word guessing game
A program should take an input on stdin, and guess what a word might be. It should run as a session. One example session is shown below. Characters are fed to it, with a * for a letter not revealed; i …