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 |
For challenges involving sequences, typically of numbers following some pattern.
15
votes
Find the largest banknote
Python 2, 39 bytes
f=lambda n:n>9and 10*f(n/10)or 5>>5/-~n
Try it online!
7
votes
Ones and Twos for days
Python 2, 24 bytes
lambda n:2-(-n%n**.5<.5)
Try it online!
Outputs the \$n\$'th value one-indexed.
We use an arithmetic expression to identify indices n that are either perfect square or one below a …
0
votes
Ones and Twos for days
Haskell, 31 bytes
do n<-[1..];show$div(100^n)9*11
Try it online!
32 bytes
show=<<iterate(\x->x*100+121)121
Try it online!
4
votes
Hardcoding the Cops and Robbers (Robbers)
Python 3, crashoz, 45 bytes
lambda n:int(60*math.sin(n/10-2))
import math
Try it online!
The expression x*60-x**3*10+x**5/2-x**7/84 is the Taylor series for \$\sin(x)\$ up to the \$x^7\$ term, multi …
6
votes
Sylvester's sequence
Haskell, 25 bytes
(iterate(\m->m*m-m+1)2!!)
3
votes
The sequence is too meta
Haskell, 67 bytes
0%j=2
i%j|d<-div i$f j=last$d+2:[(i-d-1)%(j+1)|d*f j<i]
f=(%1).pred
Try it online!
A recursive arithmetical solution that turned out basically the same method as Anders Kaseorg …
5
votes
Ordered sequence of ascending integer combinations
Python 2, 101 bytes
n=input()
for i in range(2**n):s='';m=n;exec"s=`m`+'+-'[i%2]+s;s*='-'in s;i/=2;m-=1;"*m;print s or'-'
Try it online!
6
votes
Print a booklet
Python 2, 46 bytes
lambda n:map(range(1,n+1).pop,n/4*[-1,0,0,-1])
Try it online!
Generates the range [1..n] and pops from the front and back in the repeating pattern back, front, front, back, .. …
2
votes
Interleaving Sequences
Haskell, 45 bytes
f l=max[[]][h:y|h:t<-l,y<-f$t:filter(/=h:t)l]
Try it online!
Adapted from Chas Brown's Python answer.
The max[[]] is a trick to give a base case of [[]] when the input only c …
3
votes
How many threes?
Haskell, 44 bytes
g.(*3).max 1
g 0=0
g n=0^mod n 3+g(div n 10)
Try it online!
Uses Delfad0r's observation that the output is the number of suffixes (equivalently, prefixes) of 3n that are multip …
2
votes
How many threes?
Python 2, 48 bytes
n=input()*3;p=n<1
while n:p+=n%3<1;n/=10
print p
Try it online!
Similar to ovs's answer, but takes the whole prefix mod 3 without accumulating rather than the last digit. Outp …
1
vote
New order #4: World
Haskell, 55 bytes
(1%[0]!!)
a%o|b<-div a 2=a:last(b:[3*a|elem b o])%(a:o)
Try it online!
Golfing user1472751's slick list-generation method.
Same length:
(1%[0]!!)
a%o=a:[x|x<-[div a 2,a*3], …
5
votes
List *all* the tuples!
Haskell, 50 bytes
f n=[l|k<-[0..],l<-mapM([0..k]<$f)[0..n],sum l==k]
Try it online!
Lists n-tuples sorted by sum. mapM does the heavy lifting to generate all n-tuples of numbers from 0 to k. The …
7
votes
Bit floating sequence
It turns out shorter to generate 2**n minus each term in the sequence for input n. …
5
votes
Progressing Two's
Uses a version of Bubbler's observation that the sequence alternates runs of consecutive odd numbers with an even number directly in between. …