New answers tagged open-ended-function
7
votes
Turing-Complete Language Interpreter
Turing machine (finitely initialized, halts) implementing an encoding of Grill Tag, 2 states, 14 symbols, 232 bytes
We've had a few answers implementing Turing machines in various languages. Time to ...
0
votes
Transform characters of your choice into "Hello, world!"
Headascii, 45 bytes
-----[]]]]]--[]]]][U-]()R-:-()R--:--()R-:R;P!
Takes a character and prints it, except for m, ...
6
votes
Convert numbers to dice patterns
Python 3 (194 199 210 bytes) -16 (- 5 thanks to Kevin)
My First golf!
Returns a int, array, where len(arr) == side ** 2
...
7
votes
Turing-Complete Language Interpreter
Jelly → Couplet 2C variant, 3 bytes (infinite loop) or 4 bytes (halting)
ṃVß
ṃV¥Ƭ
Try it online!
Takes the initial string from the left-hand argument, and the ...
Community wiki
2
votes
Convert numbers to dice patterns
Charcoal, 50 bytes
NθF﹪θ²POW⁻θLKA«↙≔ⅉηF⁸«P✳&⁶κ×O⌊⟦η÷⁺ιI§4062κ⁸⟧Mη✳&⁶κ
Try it online! Link is to verbose version of code. Explanation:
...
5
votes
0
votes
Output a random unary string
Volatile, 7 bytes
~(:-.~)
Assumes that the . instruction is present in the interpreter. Prints a random length of ...
0
votes
Be big more often
MathGolf, 4 bytes
‼ww╙
Try it online.
Port of @DominicVanEssen's second R answer.
Explanation:
...
0
votes
Be big more often
05AB1E, 5 bytes
{.s˜Ω
Try it online.
Or alternatively, a port of @DominicVanEssen's second R answer is 5 bytes as well:
ΩIΩ‚à
...
0
votes
Be big more often
JavaScript (V8), 53 bytes
a=>Math.max(...a.map(_=>a[a.length*Math.random()|0]))
Try it online!
Not best now though
4
votes
Be big more often
Wolfram Language (Mathematica), 19 bytes
RandomChoice[#->#]&
Try it online! Like other languages, the builtin can use weights, so the input can serve as the ...
4
votes
Be big more often
Jelly, 3 bytes
X»X
Attempt This Online!
Distribution over 1000 runs: Attempt This Online!
Uses Dominic van Essen's insight: pick a random element (...
4
votes
Be big more often
Raku, 13 bytes
*.roll(2).max
Attempt This Online!
Picks two elements independently and returns the max of the two.
3
votes
Be big more often
Jelly, 4 bytes
ṢxJX
A monadic Link that accepts a list of distinct floats and outputs a random one.
Try it online! Or see the results of 10,000 runs.
How?
Weights ...
7
votes
Be big more often
Vyxal, 4 bytes
℅?℅∴
Try it Online!
Return the highest of two random picks
...
3
votes
Be big more often
Julia, 37 bytes
!l=rand([fill.(sort(l),keys(l))...;])
Attempt This Online!
sort the list and repeat each element by their index before randomly choosing a number
...
3
votes
Be big more often
Factor, 35 bytes
[ [ dup <array> ] map-flat random ]
Attempt This Online!
Create n copies of each n, and select one at random (uniformly).
For instance, <...
5
votes
Be big more often
Ruby, 32 24 bytes
->l{(l+l).sample(2).max}
Try it online!
Thanks to Dominic van Essen for -4 bytes and the idea to get to -8.
14
votes
7
votes
Be big more often
JavaScript (Node.js), 41 bytes
a=>a.sort()[a.length*Math.random()**.5|0]
Try it online! or run it 100000 times
Takes an ...
11
votes
Be big more often
Python, 64 bytes (also supports negative numbers)
lambda l:sorted(l)[int(len(l)*random()**.5)]
from random import*
Attempt This Online!
Explanation
Sort the list, ...
6
votes
Be big more often
WolframLanguage, 63 48 bytes
Thanks to att for shaving of 15
Sort[#][[Floor@Log2[Random[](2^Tr[1^#]2-3)+2]]]&
Original answer:
...
8
votes
Be big more often
J, 8 bytes
#~{~1?+/
Attempt This Online!
1?+/ Sum the numbers and then choose a random index between 0 and the sum
...
1
vote
4
votes
Be big more often
JavaScript (Node.js), 58 bytes
a=>a.sort((a,b)=>b-a).filter(_=>Math.random()<.5)[0]||a[0]
Try it online!
Sorts the numbers, filters them randomly, ...
4
votes
Be big more often
Charcoal, 10 bytes
FAFι⊞υιI‽υ
Try it online! Link is to verbose version of code. Explanation:
FA
Loop over the input numbers.
<...
25
votes
Be big more often
Python, 41 bytes
lambda l:choices(l,l)
from random import*
Attempt This Online! or run it 100000 times
Uses the list itself as the weights.
0
votes
Prefix code generator
Charcoal, 30 bytes
→F⊕⌈θ«F⌕Aθι«§≔θκΦ⍘ⅈ²μ→»Mⅈ→»θ
Try it online! Link is to verbose version of code. Explanation:
→
Start with a ...
1
vote
Prefix code generator
Python, 88 bytes
lambda s,k=0,r=2:{j:bin(r:=(r<<-k+(k:=i))-1)[3:]for i,j in sorted(zip(s,range(len(s))))}
Attempt This Online!
Takes a list of integers and ...
3
votes
Prefix code generator
Jelly, 18 bytes
eƤ€`Ḅ=QƑẠ
Ø.ṗŒpÇƇṪ
A monadic Link that accepts the lengths and yields a list of prefix-codes in the same order.
Try it online!
Save a byte by ...
0
votes
Top 50 recent answers are included
Related Tags
open-ended-function × 99code-golf × 92
math × 29
number × 15
sequence × 12
string × 7
code-challenge × 7
kolmogorov-complexity × 7
array × 6
integer × 5
random × 5
busy-beaver × 5
combinatorics × 4
binary × 4
set-theory × 4
number-theory × 3
permutations × 3
rational-numbers × 3
restricted-complexity × 3
abstract-algebra × 3
ragged-list × 3
ascii-art × 2
decision-problem × 2
arithmetic × 2
restricted-source × 2