19
votes
The shortest way to find one unique value when all other values are the same
Python 3, 27 bytes
lambda x:min(x,key=x.count)
Try it online!
15
votes
14
votes
The shortest way to find one unique value when all other values are the same
R, 24 bytes
a=scan();a[a!=median(a)]
Try it online!
11
votes
Automate the OEIS
Bash + coreutils + w3m, 51 45 42 bytes
w3m oeis.org/b${1:1}.txt|sed "s/^$2 //p;d"
Thanks to @EamonOlive for golfing off 3 bytes!
Example run
...
11
votes
Remove submatrices
APL (Dyalog Unicode), 20 bytes
Anonymous infix lambda taking a and b as left and right argument. Requires 0-based indexing.
<...
9
votes
9
votes
The shortest way to find one unique value when all other values are the same
JavaScript (ES6), 32 27 bytes
Saved 5 bytes thanks to @xnor
a=>a.sort()[0]+a.pop()-a[1]
Try it online!
How?
a.sort() ...
9
votes
The shortest way to find one unique value when all other values are the same
x86-16 machine code, 14 bytes
Binary:
00000000: 498d 7c01 f3a6 e305 4ea6 7401 4ec3 I.|.....N.t.N.
Listing:
...
8
votes
Reverse odd runs
Python 2, 75 68 63 bytes
5 bytes thanks to Dennis.
And I have outgolfed Dennis.
Credits to Byeonggon Lee for the core of the algorithm.
...
8
votes
Un-hash the Java Hash
C#, 1.052 × 1010
The idea is to do the hash function in reverse to get all possible un-hashed strings from the given number. Integer overflow of the 32-bit hash value is also emulated in reverse by ...
8
votes
Finding your partner
Japt, 6 bytes
Works with strings or integers.
æøV kV
Test it
Explanation
Implicit input of array U and string/integer ...
8
votes
Finding your partner
Haskell, 33 bytes
x!((a,b):c)|x==a=b|x==b=a|1<2=x!c
Try it online!
Defines a binary operator !, which takes as its left ...
8
votes
The shortest way to find one unique value when all other values are the same
Haskell, 32 bytes
f(x:y)|[e]<-filter(/=x)y=e|1<3=x
Try it online!
Explanation
The code, expanded with variables renamed to be more descriptive.
...
8
votes
Remove submatrices
MATLAB/Octave with Image Processing Toolbox/Package, 78 bytes
@(A,B)A.*~conv2(reshape(all(im2col(A,size(B))==B(:),1),size(A)-size(B)+1),B>0)
Try it online!
...
7
votes
Un-hash the Java Hash
Scala
One "useful" characteristic of Java's String.hashCode method is that if you have a string z with ...
7
votes
Find X in a partially sorted Array
JavaScript (E6) 97.5 (39*5*0.5)
(O(n), linear search, the array can be scrambled again and again)
The function accepts (and ignores) a third parameter
...
7
votes
My [sub] strings are hiding!
JavaScript (ES6), 77 bytes
(s,t)=>t&&[...t.slice(0,s.length)].sort()+''==[...s].sort()|f(s,t.slice(1))
Returns 1 or 0.
Snippet
...
7
votes
The Spain license plates game
05AB1E, 10 8 bytes
Saved 2 bytes thanks to Leo
ʒæså}éR`
Try it online!
Explanation
...
7
votes
The shortest way to find one unique value when all other values are the same
APL (Dyalog Extended), 5 bytes
⍸1=¯⍸
Try it online!
Regular Dyalog APL 18.0 has ⍸⍣¯1, but it doesn't work here because it ...
7
votes
The shortest way to find one unique value when all other values are the same
05AB1E, 2 bytes
ʒ¢
Try it online!
Since 1 is the only truthy integer in 05AB1E, we can just filter (...
6
votes
Accepted
6
votes
Reverse odd runs
APL, 21 20 bytes
{∊⌽¨⍵⊂⍨e⍲¯1↓0,e←2|⍵}
Try it || All test cases
Explanation:
...
6
votes
Reverse odd runs
Haskell, 46 44 bytes
h%p|(l,r)<-span(odd.(h*))p=l++h:r
foldr(%)[]
Thanks to @xnor for recognizing a fold and saving two bytes.
6
votes
My [sub] strings are hiding!
05AB1E, 3 bytes
όZ
Try it online!
-1 byte thanks to Emigna.
Explanation:
...
6
votes
My [sub] strings are hiding!
Python 2, 67 66 bytes
Takes input as two strings, substring first.
a=sorted
lambda s,S:a(s)in[a(S[n:n+len(s)])for n in range(len(S))]
6
votes
The Spain license plates game
PHP, 111 bytes
$y=array_map(str_split,preg_grep("#".chunk_split($_GET[1],1,".*")."#",$_GET[0]));sort($y);echo join($y[0]??[]);
Try it online!
6
votes
The Spain license plates game
MATL, 30 29 bytes
xtog!s2$S"1G!'.*'Yc!@gwXXn?@.
Try it online!
Explanation
...
6
votes
Count the contiguous submatrices
Brachylog (v2), 10 bytes
{{s\s\}ᵈ}ᶜ
Try it online!
I like how clear and straightforward this program is in Brachylog; unfortunately, it's not that short byte-...
Community wiki
6
votes
Solving the water bucket riddle!
Python 3, 243 239 bytes
-4 bytes thanks to @JonathanFrech!
...
Only top scored, non community-wiki answers of a minimum length are eligible
Related Tags
search × 27code-golf × 23
string × 6
array × 4
restricted-source × 2
matrix × 2
graph-theory × 2
fastest-code × 2
optimization × 2
internet × 2
number × 1
code-challenge × 1
sequence × 1
kolmogorov-complexity × 1
number-theory × 1
integer × 1
geometry × 1
combinatorics × 1
game × 1
date × 1
quine × 1
sorting × 1
path-finding × 1
natural-language × 1
subsequence × 1