Thomas Eding
  • Member for 10 years, 6 months
  • Last seen more than a month ago
14 answers
6 votes
10k views
Implement wc (word count) shortest code wins
Accepted answer
11 votes

Haskell - 80 characters l=length main=interact$ \s->show$map($s)[l,l,l.lines,maximum.map l.lines,l.words]

View answer
9 answers
6 votes
5k views
ASCII Tux (Linux Penguin)
8 votes

Haskell - 14 characters main=putStr"." The penguin this program displays is in the far distance.

View answer
91 answers
159 votes
56k views
Tips for golfing in JavaScript
7 votes

Sometimes declaring a variable (or more) as function parameters can save some strokes by avoiding the var keyword. This use case is fairly rare though: function f(){var i} => function f(i){} Also ...

View answer
7 answers
15 votes
1k views
What comes next?
6 votes

Haskell, 276 261 259 257 243 characters Here is my inefficient solution. It works on unbounded (and bounded) integers. This solution happens to work correctly with non-exact division (eg: 5 / 2 = 2). ...

View answer
135 answers
131 votes
41k views
Obfuscated Hello World
5 votes

Haskell, 38 Constraints 1 and 3 followed. main=putStr$map succ"G\x64kkn\USVnqkc"

View answer
86 answers
39 votes
7k views
What's my name? Produce the name of the language indirectly
5 votes

Haskell, 47 data H=Haskell deriving Show main=print Haskell

View answer
40 answers
16 votes
2k views
Undulant numbers
3 votes

Haskell, 82 bytes c=cycle[(<),(>)] l!n=n>9&&and(zipWith3($)l(show n)$tail$show n) u n=c!n||((>):c)!n Try it online!

View answer
30 answers
15 votes
7k views
Jolly Jumper Sequence
3 votes

Haskell Easy 4 characters Returns a list of jolly integers if and only if a list of jolly integers is given as input. This is legal based on "Just a function that accepts arguments however and ...

View answer
47 answers
13 votes
3k views
Enumerate all palindromic numbers (in decimal) between 0 and n
3 votes

Haskell 66 characters main=do n<-readLn;mapM_ putStrLn[s|s<-map show[0..n],s==reverse s]

View answer
21 answers
44 votes
5k views
One Ring to rule them all. One String to contain them all
2 votes

Haskell, 75 bytes - 1002 output A sieve approach that returns a minimal solution. (\n->head.filter(\s->and[show k`isInfixOf`s|k<-[1..n]]).map show$[1..])1000 Note that this solution is ...

View answer
11 answers
6 votes
590 views
Find the largest value of power.
2 votes

Haskell, 63 56 characters Handles ℤ>0 (56 characters) main=do n<-readLn;print$last[p|p<-[0..n],b<-[0..n],b^p==n] Handles ℤ≥0 (58 characters) main=do n<-readLn;print$last[p|p<-[0..n+...

View answer
18 answers
6 votes
5k views
Check if number is a sum of consecutive numbers or not
2 votes

Haskell, 74 Felt like doing the brute force way. import List main=print.f=<<readLn f n=elem n$map sum$tails=<<inits[1..n-1]

View answer
28 answers
15 votes
3k views
Implement division
2 votes

Haskell, 96 characters main=getLine>>=print.d.map read.words d[x,y]=pred.snd.head.filter((>x).fst)$map(\n->(n*y,n))[0..] Input is on a single line. The code just searches for the answer ...

View answer
5 answers
14 votes
9k views
Free a Binary Tree
1 votes

C/C++/Objective-C 126 characters (includes required trailing newline) #define b(t)(t->left||t->right) void f(Node*r){while(r&&b(r)){Node**p=&r,*c=b(r);while(c)p=&c,c=b(c);free(*p)...

View answer
25 answers
5 votes
22k views
Program that determines whether an int is greater or lesser
1 votes

Haskell, 150 characters main=putStr.g.f.map read.words=<<getLine f[a,b]|b`elem`dropWhile(/=a)[(minBound::Int)..]="BA"|0<1="AB" g[x,y]="Integer "++x:" is ...

View answer
9 answers
-4 votes
338 views
Change a non-floating point number the largest step
1 votes

Haskell - 8 characters (Infinite difference) f=f.(+1) Use f on Integer.

View answer
9 answers
12 votes
2k views
Flag Semaphore Encoder
1 votes

Haskell 331 357 339 characters Golfed: import Data.Char t[x,y]=q[x,mod(y+1)8] q z@[x,y]|x==y=[x+1,y+2]|0<1=z x%y=[x,y] c 65=0%1 c 74=6%4 c 75=1%4 c 79=2%3 c 84=3%4 c 86=4%7 c 87=5%6 c 89=3%6 c 90=6%...

View answer
13 answers
4 votes
15k views
Count the number of times a function runs
1 votes

Primary answer: Does not use crazy macro expansion. Uses recursion and two 8 bit variables. The code works by recursing enough such that the first call to foo generates enough calls where the ...

View answer
9 answers
16 votes
881 views
Last k digits of Powers of 2
1 votes

Haskell, 115 characters import List main=readLn>>=print. \r->head$findIndices(all(`elem`"12").take r.(++cycle"0").reverse.show)$iterate(*2)1

View answer
11 answers
-4 votes
460 views
Text Statistics: Return a list/array of the number of occurrences of each character used in a text file, including spaces, tabs, and new lines
1 votes

Haskell, 2^6 characters import List f=fmap(map(\x->(x!!0,length x)).group.sort).readFile

View answer
71 answers
55 votes
8k views
How to randomize letters in a word
1 votes

Javascript, 202 characters function r(s){var s=s.split(""),h=[-1],n=s.length-1,t,i;h[-1]=s[0];for(i=0;++i<n;){do{t=Math.random()}while(t in h);h[t]=s[i];h[i]=t;}h.sort();for(i=0;i<n;++...

View answer
71 answers
55 votes
8k views
How to randomize letters in a word
1 votes

Java, 194 charcters String r(String s){String[]c=s.split("");if(c.length>2)java.util.Collections.shuffle(java.util.Arrays.asList(c).subList(2,c.length-1));return(""+java.util....

View answer
71 answers
55 votes
8k views
How to randomize letters in a word
1 votes

Haskell, 195 import Random import Data.List r l=fmap(f l.g l)newStdGen f l n=map snd$head$filter(\l->map fst l==n)$permutations$zip[0..]l g l=take(n+2).(0:).(++[n+1]).take n.nub.randomRs(1,n)where ...

View answer
13 answers
2 votes
1k views
position of the only 1 in a number in binary format
0 votes

Haskell 65 characters import List main=n<-readLn;print$findIndices(>n)[2^n|n<-[0..]]!!0

View answer
9 answers
14 votes
3k views
Write a function that returns past tense of given verb
0 votes

Poop - 72 characters f[s]s^6pow>4<<last&8*(/"ed""id""eid"/|out|flush)+rep'y'1-2-3"aeiou"ord#s

View answer
56 answers
22 votes
4k views
Chessboard pattern
0 votes

Haskell 89 74 charaters main=do n<-readLn;mapM_(putStrLn.take n).take n.cycle$map cycle["X "," X"]

View answer
5 answers
6 votes
2k views
Detect loops in a linked list
0 votes

Haskell Naive algorithm: import Data.Set (Set) import qualified Data.Set as Set type Id = Integer data Node a = Node { getValue :: a, getId :: Id } hasLoop :: [Node a] -> Bool hasLoop = hasLoop' ...

View answer
4 answers
1 votes
716 views
Tricky Median Question
0 votes

Haskell, 136 characters main=interact$show.n.q.map read.words n x=snd$minimum$map(\p@(a,b)->(sum$map(\(x,y)->max(abs$a-x)$abs$b-y)x,p))x q[]=[] q(x:y:z)=(x,y):q z

View answer
86 answers
39 votes
7k views
What's my name? Produce the name of the language indirectly
0 votes

Haskell, 52 main=putStr$map(enumFrom 'G'!!)[1,26,44,36,30,37,37] Could be shorter if the answer can be case insensitive. I chose to start at 'G' because Haskell has no G's in its name, and 'G' comes ...

View answer
6 answers
13 votes
894 views
Comparing powers.
-2 votes

Haskell, 44 characters n True=1 n _=1-2 g a b c d e f=n$a^b^c>d^e^f Runs under a second for all the test examples on my machine.

View answer