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 where an exact output is not required but some property must still be fulfilled.
15
votes
Implement any 10-ary truth function with cyclic symmetry
Python, 21 bytes
lambda s:"1011"in s*2
Try it online!
Checks whether the input contains 1011, reading left to right wrapping around. The reason for not testing with a shorter substring like "11" or …
16
votes
Print 4 billion if statements
Python 3, 70 bytes
print("def f(n):f",*range(2**33),sep="==n==print('eovdedn'[n&1::2]);")
Try it online (with 2**3 in place of 2**33)
If it's OK for the function to error out after printing, 1 byte …
1
vote
Output a 1-2-3 sequence
Haskell, 32 bytes
[n|n<-[1..],mod(gcd(6^n)n^2)7<2]
Try it online!
An adaptation of m90's method. Extracts the 2^a * 3^b component by taking the gcd with a large power of 6, and checks that modulo 7 …
6
votes
Generate all linked chains
Python 3, 59 bytes
*l,e='_-='
for s in l:e in s!=print(s);l+=s[0]+s,l[s>e]+e+s
Try it online!
Prints the sequence forever, sorted by number of non-= characters. Based on Ajax1234's generator. The id …
6
votes
Encode integers with some others
Haskell, 13 bytes
map=<<(+).sum
Try it online!
Decoder:
\r->[x-div(sum r)(1+length r)|x<-r]
The code is pointfree for f l=[x+sum l|x<-l], that is f l=map(+sum l)l. It increases each element by the …
14
votes
Encode integers with some others
Python, 29 bytes
lambda l:[x+max(l)for x in l]
Try it online!
Just adds the list maximum to each element, producing values greater than any in the original list. The max of the resulting list is dou …
2
votes
Infinite ordinals from a well-ordering
Python 2, \$\omega^{10}\$, 48 bytes
lambda*l:cmp(*[(sorted(`n`)[::-1],n)for n in l])
Try it online!
Outputs -1 for < and +1 for >
Takes each number and sorts its digits in descending order, then com …
4
votes
Infinite ordinals from a well-ordering
Haskell, \$ \omega \cdot 2\$, 22 bytes
(.q).(<).q
q=odd>>=(,)
Try it online!
Based off Grain Ghost's Haskell answers. The function q is pointfree for q x=(odd x,x). That is, we sort numbers by whet …
10
votes
Infinitely many ℕ
Haskell, 17 bytes
[[1..x]|x<-[1..]]
Try it online!
Since the challenge seems to allow non-flat output, we can simply generate a list of the lists [1],[1,2],[1,2,3,],..., as suggested by @AZTECCO.
H …
13
votes
Infinitely many ℕ
Python 2, 31 bytes
R=1,
while 1:print R;R+=len(R),
Try it online!
Thanks to @Danis for saving a byte here over R+=R[-1]+1,. This
Prints:
(1,)
(1, 1)
(1, 1, 2)
(1, 1, 2, 3)
(1, 1, 2, 3, 4)
(1, 1, 2, …
4
votes
Golf a bijection \$\mathbb{N}^n\to\mathbb{N}\$
Python 2, 38 bytes
f=lambda a,*l:l and(a-~a<<f(*l))-1or a
Try it online!
Takes input splatted like f(1,2,3).
Uses the pairing function \$p(a,b)=(2a+1)2^b\$. We use bit-shift <<b to shorten *2**b, an …
3
votes
Golf a bijection \$\mathbb{N}^n\to\mathbb{N}\$
Haskell, 27 bytes
foldr1(\a b->2^a*(2*b+1)-1)
Try it online!
Uses a different bijection from the Cantor pairing function. Every positive integer can be uniquely split into a power of 2 times an odd …
6
votes
Shortest total non-primitive recursive function
Haskell, 29 bytes
(+1)?(2?)
z?f=(iterate f z!!)
Try it online!
An Ackermann-like function. Starting the base numerical value at 2 makes for a simple base case. An annoying number of bytes are sp …
3
votes
An unknowably odd function
Haskell, 18 bytes
f(h:t)=h:reverse t
Try it online!
Based on Mitchell Spector's idea. Leaves the first digit in place and reverses the rest. Input and output are as strings.
2
votes
An unknowably odd function
Python, 22 bytes
lambda s:s[0]+s[:0:-1]
Try it online!
Based on Mitchell Spector's idea. Leaves the first digit in place and reverses the rest. Input and output are as strings.