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.
7
votes
Next Greater Number
Husk, 6 bytes
ḟoΛ≤d→
Try it online!
Explanation
ḟoΛ≤d→
ḟ find the first integer
→ starting from input incremented
o such that composed function
Λ d every digit
≤ is less t …
6
votes
Even sum subarrays
Husk, 8 7 bytes
#ȯ¬%2ΣQ
Try it online!
Explanation
Q # consecutive subsequences
# # count elements by
ȯ # composed function
¬ # not
Σ # sum
%2 # mod 2
-1 byt …
6
votes
Iterate your way to a fraction
Ruby, 45 bytes
f=->n,d{n==0?"":n/d<0??g+f[-d,n]:?f+f[n-d,d]}
Try it online!
Use as f[n,d]
basically a port of loopy walt's python answer
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
5
votes
Hexadecimal -> Binary Art
Perl 5, -p 30 bytes
$_=sprintf"%08b
",hex;y/01/ X/
Pretty much identical to Jordan's Ruby answer
Try it online!
5
votes
Hexadecimal -> Binary Art
sed 4.2.2, -E 178 141 bytes
s/./&FEDCBA9876543210:/g
s/(\w)\w*\1//g
s/\w/ /g
s/ +/&&&&/
s/ +/&&&&/
s/://
:
s/^(.+)\1:/\1: /
s/^ (.*)\1:/\1:X/
t
s/://
:z
s/^.{,7}$/ &/
tz
Takes newline-separated input …
5
votes
Remove odd indices and double the even indices
Husk, 5 bytes
Ṙ2Ċ2t
Try it online!
Explanation
Ṙ2Ċ2t
t drop first char
Ċ2 take every 2-nd char
Ṙ2 repeat each char 2 times
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 …
4
votes
Hexadecimal -> Binary Art
Husk, 34 31 28 bytes
mȯötm!"X "ḋ+256B16m€f□…"1F"w
Try it online!
Takes input as a space-separated argument
Husk is missing some useful functions such as pad and hex which makes this answer so long, o …
4
votes
Sort the unique numbers in a multiplication table
Husk, 6 bytes
OumΠπ2
Try it online!
Explanation
OumΠπ2
π2 cartesian square
mΠ map product
u unique
O sort
3
votes
Compute minimax of an array
Husk, 4 bytes
▼m▲X
Try it online!
Explanation
▼m▲X
X each consecutive slice of length
m▲ maximum of each
▼ minimum
3
votes
Create an array with repeated numbers
Husk, 4 bytes * 0.5 = 2
Σ↔ḣṫ
Try it online!
Explanation
Σ↔ḣṫ
ṫ range from input to 1, [5,4,3,2,1]
ḣ prefixes, [[5],[5,4],[5,4,3]...]
↔ reverse, [[5,4,3,2,1],[5,4,3,2]...]
Σ c …
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)
3
votes
Minimum difference between cartesian product of 3 elements that add up to a certain number
Husk, 14 13 bytes
-1 byte thanks to Dominic van Essen
◄§-▼▲fo=▲¹Σπ3
Try it online!
Explanation
◄§-▼▲fo=▲¹Σπ3
π3 cartesian product of 3 * input
fo filter by composed funct …
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
Σ …