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 |
Code-golf is a competition to solve a particular problem in the fewest bytes of source code.
2
votes
From 0 to 2^n - 1 in POPCORN order
Husk, 8 bytes
ÖoΣḋŀ`^2
Try it online!
`^2 flip ^, partially applied, gets fully applied with implicit input, 2 ^ n
ŀ range from [0, n)
Ö sort by
o composed function
Σ …
1
vote
Add All Permutations of a Number
Husk, 4 bytes
ṁdPd
Try it online!
Explanation
ṁdPd
d digits of input
P get all permutations
ṁ (flat/concat/sum)-map
d interpret as digits
4
votes
Cartesian literal notation
Ruby, 98 87 bytes
p`dd`.gsub(/\d+-/,'*\00..').split(?/).flat_map{|x|eval"[%s].product([%s])"%x.split(?:)}
Try it online!
Explanation
`dd`.gsub(/\d+-/,'*\00..') # input and replace "nu …
2
votes
An ASCII self-referential sequence
Ruby, 40 bytes
->n{a=*5
n.times{a=(a*", ").bytes}
a[n]}
Try it online!
a lambda that returns the n-th element
1
vote
determine longest group of consecutive numbers
Husk, 7 bytes
▲mLgz-N
Try it online!
Explanation
▲mLgz-N
z N zip input and infinite list [1..]
- with '-'
g group adjacent equal values
mL map length
▲ maximum
2
votes
Swap every two elements in a list
Husk, 4 bytes
ṁ↔C2
Try it online!
Explanation
ṁ↔C2
C2 slices of length 2
ṁ↔ flatmap reverse
1
vote
Halve the falses
Husk, 6 bytes
σD;0;0
Try it online!
Explanation
σD;0;0
σ replace all with
D 2 copies of
;0 [0]
;0 …
1
vote
Divisible strings
Husk, 6 bytes
Λo¦L¹c
Try it online!
Explanation
Λo¦L¹c translates = Λo¦L⁰c⁰
Λ ⁰ all of input:
o c charcode
¦ divides
L⁰ length of input
1
vote
Largest rectangle in a skyline
Husk, 7 bytes
▲m§*▼LQ
Try it online!
Explanation
▲m§*▼LQ
m Q for each contiguous sublist
§* multiply it's
▼L minimum value by it's length
▲ maximum of that
2
votes
Smallest maximal rectangle in a skyline
Doesn't work as intended... yet
Husk, 16 bytes
▼M₁¹
*⁰▲mLfo=⁰▼Q
Try it online!
Explanation
▼M₁¹ translates to ▼M₁⁰⁰
M₁⁰⁰ for each number in the input, call the second line with (each number N …
3
votes
Lowest integer with no common digits between given bases
Ruby, 54 bytes
->a{(1..).find{|i|!a.flat_map{i.digits(_1)|[]}.uniq!}}
Try it online!
(with modifications to work on older versions)
6
votes
Count sum of all digits
Husk, 4 bytes
Σṁdḣ
Try it online!
ḣ makes a range from 1 to input
ṁd flatmap digits
Σ sum
2
votes
Count sum of all digits
Pyth, 6 bytes
ssMjkS
Try it online!
S create range from 1 to input
jk join on k (initially empty string)
sM map to number
s sum
2
votes
pwaS eht tirsf dna tasl setterl fo hace dorw
Husk, 10 bytes
wm§:→oṙ1hw
Try it online!
Explanation
wm§:→oṙ1hw
m w map over each word
§: concatenate the
→ last char
o h and the rest
ṙ1 rotated
w …
2
votes
Find the longest rep digit
Husk, 7 bytes
LḟEMBtN
Try it online!
Explanation
LḟEMBtN
tN on numbers 2,3,4...
MB map input to digits in base 2,3,4...
ḟE find first list that only has one unique element
L …