Hot answers tagged

25 votes

American odds to probabilities

Python, 25 bytes lambda x:x/(~99-abs(x))%1 Attempt This Online! Thanks @Jonathan Allan for -1. Original Python, 26 bytes ...
loopy walt's user avatar
  • 15.6k
12 votes

American odds to probabilities

Jelly, 7 bytes ,³ṢAÄ÷/ Try it online! Function I/O only because lmao ³. (Replace with ȷ2 if ...
Unrelated String's user avatar
10 votes
Accepted

Add two really big numbers

Trivial Built-in Answers For languages where bignum addition is already supported. 05AB1E, Brachylog, Factor, J, Jelly, Julia, Nekomata, RProgN 2, Vyxal, 1 byte + ...
8 votes

Add two really big numbers

05AB1E, 13 9 bytes Dv+T‰Áø`À Try it online! No bigints. Takes both inputs as a reversed list of digits, padded to at least the length of the output, and outputs in ...
Command Master's user avatar
7 votes

Add two really big numbers

K (ngn/k), 13 bytes 10!(_0.1/,)\+ Try it online! Takes two lists of digits in reverse order padded to an equal length that is at least as long as the result. ...
Bubbler's user avatar
  • 73.1k
7 votes

American odds to probabilities

R, 24 bytes \(n)(-n/(100+abs(n)))%%1 Attempt This Online! Port of loopy walt's Python answer.
pajonk's user avatar
  • 14.9k
6 votes

Add two really big numbers

TypeScript's Type System, 211 193 bytes ...
noodle man's user avatar
  • 4,026
6 votes

American odds to probabilities

Python, 33 bytes lambda n:1/[1+n/100,1-100/n][n<0] Attempt This Online! Testing code from MTN's answer
AnttiP's user avatar
  • 7,670
6 votes
Accepted

Keep jumping till a cycle

Jelly, 9 bytes Ėṙ`ḢṪƊÐḶL A monadic Link that accepts a list of integers and yields the cycle length. Try it online! How? Keep a record of the original indices ...
Jonathan Allan's user avatar
5 votes

Add two really big numbers

Lua, 121 119 bytes load"A,B=...m=math.floor o=''c=0 for i=1,#A do L=#A-i+1O=A:sub(L,L)+c+B:sub(L,L)c=O/10 o=m(O%10)..o end return m(c)..o" Try it online!...
ATaco's user avatar
  • 10.2k
5 votes

Add two really big numbers

C (gcc), 62 bytes f(a,b)char*a,*b;{*a=*a?48+(*b+=f(a+1,b+1)+*a-96)%10:0;b=*b>9;} Try it online! Input two char* strings. ...
tsh's user avatar
  • 33.6k
5 votes

American odds to probabilities

Ruby, 29 26 bytes ->n{(n>0?100:n=-n)/n+=1e2} Attempt This Online! Saved 3 bytes thanks to @MTN and @G B. Ports Luis felipe De jesus Munoz’s JavaScript ...
noodle man's user avatar
  • 4,026
5 votes

Keep jumping till a cycle

R, 65 bytes \(a){while(!(T=(T+a[+T]-1)%%sum(a|1)+1)%in%F)F=c(T,F) match(T,F)} Attempt This Online!
Dominic van Essen's user avatar
5 votes

Find the longest permutations of integers from 1..k such that all neighbouring pairs sum to a square

R, 139 bytes \(n,f=\(a,b,i=which(!(a+b[1])^.5%%1))`if`(sum(i),unlist(Map(\(i)f(a[-i],c(a[i],b)),i),F),list(b)))(a=f(1:n,{},1:n))[(l=lengths(a))==max(l)] Attempt ...
Dominic van Essen's user avatar
4 votes

Add two really big numbers

Vyxal, 35 bitsv2, 4.375 bytes 02(?(› Try it Online! Doesn't use +, but does use addition of some sort (incrementing the top of ...
lyxal's user avatar
  • 31.4k
4 votes

Add two really big numbers

Factor, 39 31 43 bytes [ 0 -rot [ + + 10 /mod ] 2map swap suffix ] Try it online! Non-builtin counterpart to the + answer. ...
chunes's user avatar
  • 20.9k
4 votes

Add two really big numbers

ISO C23 (clang 16), 42 bytes _BitInt(constant) is a new C23 feature for fixed-width integers, wide or small. Implementations can have limits (...
Peter Cordes's user avatar
  • 4,708
4 votes

American odds to probabilities

Vyxal, 55 bitsv2, 6.875 bytes ₁"sȧ¦ƒ/ Try it Online! Port of Jelly.
MTN's user avatar
  • 761
4 votes

American odds to probabilities

Vyxal, 50 bitsv2, 6.25 bytes ȧ₁+/N1% Try it Online! Port of loopy walt's Python. It's longer in Jelly due to the argument order for division, but I intuited it ...
Unrelated String's user avatar
4 votes

Keep jumping till a cycle

Python, 62 bytes -4 bytes, thanks to loopy walt lambda L,i=0:len({*[i:=(i+L[i])%len(L)for _ in 2*L][len(L):]}) Attempt This Online! Explanation compute list of ...
bsoelch's user avatar
  • 4,723
3 votes

The Rien Number

Nekomata, 8 bytes RtƊjo1cɗ Attempt This Online! ...
alephalpha's user avatar
  • 45.6k
3 votes

Find the largest number that's adjacent to a zero

Nekomata, 7 bytes qᵗZđ+aṀ Attempt This Online! ...
alephalpha's user avatar
  • 45.6k
3 votes

Find the largest number that's adjacent to a zero

Jelly, 6 5 bytes SfµƝṀ Try it online! -1 remembering it's not a dyadic chain ...
Unrelated String's user avatar
3 votes

Is this number a prime?

TypeScript's Type System, 111 bytes ...
noodle man's user avatar
  • 4,026
3 votes

Fibonacci function or sequence

Dyalog APL, 17 characters (17 bytes SBCS) {({⍵,+/¯2↑⍵}⍣⍵)⍺} Try it online! The arguments are the initial sequence on the left, and the number of additional terms ...
greta_samsa's user avatar
3 votes

Add two really big numbers

Retina 0.8.2, 49 44 bytes O#$`. $.%` ¶ M!`.. . $* +`¶1{10} 1¶ %M`1 ¶ Try it online! Takes input on separate lines but link is to test suite that splits on ...
Neil's user avatar
  • 163k
3 votes

Add two really big numbers

C (clang), 73 69 58 bytes c;f(*a,*b,n){for(;n--;c/=10)a[n]=(c+=a[n]+b[n]-96)%10+48;} Try it online! Saved 4 bytes thanks to tsh Saved 11 bytes thanks to Peter ...
Noodle9's user avatar
  • 19.8k
3 votes

Add two really big numbers

Ruby, 78 67 59 49 bytes ->a,b{c=0;a.zip(b).map{s=_1+_2+c;c=s>9?1:0;s%10}} Attempt This Online! My first Ruby submission! This is probably a little golfable ...
noodle man's user avatar
  • 4,026
3 votes

Add two really big numbers

JavaScript (Node.js), 63 bytes f=(a,b,c=0)=>(c-=~a.pop()+~b.pop()+2)||a+b?f(a,b,c/10|0)+c%10:a Try it online! no bigint
l4m2's user avatar
  • 19.1k
3 votes

American odds to probabilities

Arturo, 34 bytes $->n[abs//(n<0)?->n[100]100+abs n] Try it!
chunes's user avatar
  • 20.9k

Only top scored, non community-wiki answers of a minimum length are eligible