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 3171

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

0 votes

Print a Christmas Tree

R, 68 characters s=sprintf;cat(s('%10s','*'),s('% *s%0*d',9:1,'',1:9*2-1,0),sep='\n') And here's a parameterized version: n=12 # Tree height (without star) s=sprintf;cat(s('%*s',n+1,'*'),s('% *s%0 …
Tommy's user avatar
  • 931
0 votes

Playing the Name Game

R, 189 chars x=scan(,'');f=function(b)if(grepl(b,x))sub('.','',x)else tolower(sub('^[^aoueiy]*',b,x,i=T));cat(sprintf('%s, %1$s, bo-%s\nBanana-fana fo-%s\nFee-fi-mo-%s\n%1$s!\n',x,f('B'),f('F'),f('M' …
Tommy's user avatar
  • 931
4 votes

Check if a string is a shuffle of twins

R, 113 chars l=length(x<-charToRaw(scan(,'')));max(apply(combn(l,l/2),2,function(i)if(all(x[i]==x[-i]))rawToChar(x[i])else 0)) Ungolfed (and instead a function that takes the string): untwin <- fu …
Tommy's user avatar
  • 931
55 votes
Accepted

Tips for golfing in R

Some tips: In R, it's recommended to use <- over =. For golfing, the opposite holds since = is shorter... If you call a function more than once, it is often beneficial to define a short alias for it …
Tommy's user avatar
  • 931