Skip to main content
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
Results tagged with
Search options not deleted user 2248

Code-golf is a competition to solve a particular problem in the fewest bytes of source code.

9 votes
4 answers
2k views

Generate Friedman numbers

A Friedman number is a number that can be expressed by applying basic mathematical operations(^,/,*,+,-) to all it's digits. The operations need not be applied to each individual digit, but all the di …
elssar's user avatar
  • 599
1 vote

Build a readability index

Python 380 characters import re def t(p): q=lambda e: e!='' w=filter(q,re.split('[ ,\n\t]',p)) s=filter(q,re.split('[.?!]',p)) c=len(w)*1.0 f=c/len(s) return w,f,c def s(w): c= len(re.findall(r …
elssar's user avatar
  • 599
2 votes

First-n Fibonacci sequence elements

Python (78 chars) I used Binet's formula to calculate the fibonacci numbers - [(1+sqrt(5))^n-(1-sqrt(5)^n]/[(2^n)sqrt(5)] It's not as small some of the other answers here, but boy it's fast n …
elssar's user avatar
  • 599
0 votes

add commas to Numbers without String manipulation

Python 2.6.5, 65 94 chars n=input() s='' while n: s=','+str(x)+s if x else','+'000'+s n/=1000 print s[1:] Just used the string to store the output. *Now preserves zeros
elssar's user avatar
  • 599
0 votes

Day of the week for a given date of this year. Do not use any date tools

Python (130 chars) d=raw_input().split() n=int(d[0])+sum([31,29,31,30,31,30,31,31,30,31,30,31][:int(d[1])-1])-1 print 'SMTWTFSuouehranneduit'[n%7::7] It's rather longish for Python, but I like it.
elssar's user avatar
  • 599
0 votes

It's fun to stay at the Y.M.C.A

Python2.6 (82)(214)(219)(196)(185)(152) Fixed. Ran against the video & seems accurate. Saved quiet a few characters by reducing the precision from 3 to 2 in most of the cases(thanks for the tip @JPvd …
elssar's user avatar
  • 599
1 vote

determine longest group of consecutive numbers

Python def s(n): l=0 t=1 for i in range(0,9): if n[i]+1==n[i+1]: t+=1 else: if l<t: l=t t=1 return l
elssar's user avatar
  • 599
0 votes

Print the amount of ones in a binary number without using bitwise operators

Python (48 without spaces, 65 with) x = int(raw_input()) s = 0 while x: if x%2: s+=1 x/=2 print s
elssar's user avatar
  • 599
1 vote

Hello World 0.0!

Python 272 chars s=ord('O') a=len('0') b=a+a c=b+a d=c+a e=d+a f=e+a g=f+a h=g+a print chr(s-g)+chr(s+g*c+a)+chr(s+g*d+a)+chr(s+g*d+a)+chr(s+h*d)+chr(s-h*f+a)+chr(s+h)+chr(s+h*d)+chr(s+g*e)+chr(s+g*d …
elssar's user avatar
  • 599
1 vote

Find random images from http://i.imgur.com/

Python, 153 chars import string as s,random as w,requests as r while 1: t='http://i.imgur.com/%s.png'%''.join(w.sample(s.letters,5)) if'not'not in r.get(t).text:print t While this works, it is bl …
elssar's user avatar
  • 599
4 votes

Divide a number by 3 without using *, /, +, -, % operators

Python2.6 (29)(71)(57)(52)(43) z=len(range(2,abs(x),3)) print (z,-z)[x<0] print len(range(2,input(),3)) Edit - Just realized that we have to handle negative integers too. Will fix that later …
elssar's user avatar
  • 599
1 vote

Fibonacci function or sequence

Python (56 chars) n=input() x=5**0.5 print ((1+x)**n-(1-x)**n)/((2**n)*x) And for the sequence n=input() i=1 x=5**0.5 while i<=n: print ((1+x)**i-(1-x)**i)/((2**i)*x) i+=1
elssar's user avatar
  • 599