New answers tagged

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 ...
ais523 - high effort answers's user avatar
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, ...
thejonymyster's user avatar
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 ...
ToAskOrNotToAsk's user avatar
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 ...
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: ...
Neil's user avatar
  • 163k
5 votes

Convert numbers to dice patterns

JavaScript (ES7), 180 bytes Returns a binary matrix. ...
Arnauld's user avatar
  • 186k
0 votes

Output a random unary string

Volatile, 7 bytes ~(:-.~) Assumes that the . instruction is present in the interpreter. Prints a random length of ...
bluswimmer's user avatar
0 votes

Be big more often

MathGolf, 4 bytes ‼ww╙ Try it online. Port of @DominicVanEssen's second R answer. Explanation: ...
Kevin Cruijssen's user avatar
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Ω‚à ...
Kevin Cruijssen's user avatar
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
l4m2's user avatar
  • 19.1k
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 ...
Greg Martin's user avatar
  • 15.4k
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 (...
pxeger's user avatar
  • 23.2k
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.
Jo King's user avatar
  • 47k
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 ...
Jonathan Allan's user avatar
7 votes

Be big more often

Vyxal, 4 bytes ℅?℅∴ Try it Online! Return the highest of two random picks ...
Dominic van Essen's user avatar
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 ...
MarcMush's user avatar
  • 6,175
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, <...
chunes's user avatar
  • 20.9k
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.
G B's user avatar
  • 20.8k
14 votes

Be big more often

R, 27 bytes (Or 20 bytes in R>=4.1 using \ instead of function) ...
Dominic van Essen's user avatar
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 ...
MTN's user avatar
  • 761
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, ...
bsoelch's user avatar
  • 4,781
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: ...
infinitezero's user avatar
  • 1,637
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 ...
Jonah's user avatar
  • 32.5k
1 vote

Be big more often

Vyxal, 3 bytes øḊ℅ Try it Online! Explained ...
lyxal's user avatar
  • 31.5k
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, ...
Joyal Mathew's user avatar
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. <...
Neil's user avatar
  • 163k
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.
MTN's user avatar
  • 761
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 ...
Neil's user avatar
  • 163k
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 ...
loopy walt's user avatar
  • 15.6k
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 ...
Jonathan Allan's user avatar
0 votes

Prefix code generator

JavaScript (ES6), 115 bytes A simple but quite long algorithm. ...
Arnauld's user avatar
  • 186k

Top 50 recent answers are included