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
...
12
votes
American odds to probabilities
Jelly, 7 bytes
,³ṢAÄ÷/
Try it online!
Function I/O only because lmao ³. (Replace with ȷ2 if ...
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
+
...
Community wiki
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 ...
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.
...
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.
6
votes
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
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 ...
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!...
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. ...
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 ...
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!
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 ...
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 ...
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. ...
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 (...
4
votes
American odds to probabilities
Vyxal, 55 bitsv2, 6.875 bytes
₁"sȧ¦ƒ/
Try it Online!
Port of Jelly.
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 ...
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 ...
3
votes
3
votes
Find the largest number that's adjacent to a zero
Nekomata, 7 bytes
qᵗZđ+aṀ
Attempt This Online!
...
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
...
3
votes
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 ...
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 ...
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 ...
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 ...
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
3
votes
Only top scored, non community-wiki answers of a minimum length are eligible
Related Tags
number × 1292code-golf × 1201
math × 293
sequence × 240
arithmetic × 150
integer × 116
string × 103
number-theory × 98
decision-problem × 95
array × 87
primes × 66
base-conversion × 54
code-challenge × 46
binary × 40
ascii-art × 35
kolmogorov-complexity × 32
combinatorics × 28
random × 23
fibonacci × 22
matrix × 21
restricted-source × 19
rational-numbers × 19
sorting × 18
permutations × 18
fastest-code × 17