Hot answers tagged

10 votes
Accepted

Weighted coin flip strings

05AB1E, 40 39 18 17 bytes Brute-force approach: 0Lα1ݲãʒγOà³@}èPO Byte-count more than halved by porting @JonathanAllan's Jelly answer, which uses a similar ...
user avatar
9 votes

Implement Binary Exponentiation

Vyxal, 6 bytes d‡½⌊İe Try it Online! Takes inputs in reverse order. Explanation ...
user avatar
  • 6,660
8 votes

Print the power set of the power set ... of an empty set

Burlesque, 8 bytes {}1qR@C~ Try it online! ...
user avatar
8 votes
Accepted

Print the power set of the power set ... of an empty set

Jelly, 3 bytes ŒP¡ Attempt This Online! Using standard I/O rules; takes input from STDIN Explanation: ...
user avatar
  • 21.5k
7 votes

Weighted coin flip strings

Jelly,  19  15 bytes Ø.ṗṣ1ZṫɗƇ_⁵AP€S A full program accepting n, k, and ...
user avatar
7 votes

Weighted coin flip strings

Python, 66 bytes (-1 @xnor) f=lambda n,k,p:n>=k and(1-p*(n>k))*(1-f(n+~k,k,p))*p**k+f(n-1,k,p) Attempt This Online! Adapted from my answer to a similar challenge. Note that I add memoization in ...
user avatar
  • 6,930
6 votes

Print the power set of the power set ... of an empty set

Wolfram Language (Mathematica), 19 bytes Nest[Subsets,{},#]& Try it online! In the notebook interface, the results are printed without spaces. But in TIO or ...
user avatar
6 votes

Print the power set of the power set ... of an empty set

Vyxal, 4 bytes or 12 ¾?(ṗ Explanation ...
user avatar
  • 4,453
6 votes

Print the power set of the power set ... of an empty set

Python, 96 bytes from itertools import* f=lambda n:n and(chain(*(combinations(f(n-1),r)for r in range(n+1))))or() Attempt This Online!
user avatar
  • 2,436
5 votes

Print the power set of the power set ... of an empty set

Haskell, 53 bytes f=(!!)$iterate(\l->init l++[','|l/="{}"]++l++"}")"{}" Try it online! My first golf. Nothing particularly clever,...
user avatar
5 votes

Weighted coin flip strings

R, 129 122 116 bytes Edit: -2 bytes thanks to pajonk (which led to -4 more...) ...
user avatar
4 votes

Is this polynomial a square?

Vyxal, 33 32 bytes h√d£0¾ȦλȮḂÞ•-¥/J;RI÷?₂J†^¥J:⌊=JA Try it Online! –1 per emanresu A. How? We find the square root of the polynomial using its power series, ...
user avatar
  • 1,221
4 votes

Print the power set of the power set ... of an empty set

Pyth, 3 or 17 11 bytes yFY Try it online! F - Repeat Q times, where Q is the implicit input: ...
user avatar
  • 6,977
4 votes

Divide by an odd number, 2-adically

Python, 45 bytes lambda a,b,n:(a-~a)*pow(b-~b,-1,2<<n)//2%2**n Attempt This Online! Beginning with Python 3.8 the builtin pow can directly compute the modular ...
user avatar
  • 6,930
4 votes

Weighted coin flip strings

JavaScript (ES7), 106 bytes Quickly computes the probability, using the formula found by Kevin Cruijssen. ...
user avatar
  • 168k
4 votes

Weighted coin flip strings

Vyxal , 23 bytes 2$ÞẊ'2€vLG›¹>;⁰⌐⁰"$İvΠ∑ Try it Online! Port of Jelly. Really slow. Previous answer (much faster): ...
user avatar
  • 6,660
4 votes

Weighted coin flip strings

PARI/GP, 53 bytes k->p->g(n)=if(n>=k,p^k*(1-p*(n>k))*(1-g(n---k))+g(n)) Attempt This Online! A port of loopy walt's Python answer. Takes input in the ...
user avatar
3 votes

Finite Field Multiplication

Jelly, 22 bytes Bæc/ḣ-64æcB}ʋƬUSḣ64UḂḄ Try it online! Works either as a function or a full program. This takes two arguments: a 2-element list ...
3 votes

One OEIS after another

373. Idris, 907 bytes, A000170 ...
user avatar
  • 62.9k
3 votes

Landau logarithm

Haskell, 68 67 bytes k%n=sum[1+k?n%n|k?n>k] k?n=maximum$k:[lcm x$k?(n-x)|x<-[1..n]] (1%) Try it online! Golfs 2 bytes ...
user avatar
  • 88.8k
3 votes

Semidivisibility

Vyxal v2.6.0+, 6 bytes ġ/₀KḢc Takes its input as \$k\$ followed by \$n\$. Try it Online! This uses the same algorithm as my regex answer, which is similar to the ...
user avatar
  • 7,059
3 votes

Is this polynomial a square?

Wolfram Language (Mathematica), 58 68 64 55 bytes thanks @Steffan for the byte correction, and the suggestions thanks @alephalpha ...
user avatar
  • 653
3 votes

Print the power set of the power set ... of an empty set

05AB1E (legacy), 4 or 17 bytes Regular I/O using [] instead of {} and spaces after the commas would be 4 bytes: ...
user avatar
3 votes

Divide by an odd number, 2-adically

PARI/GP, 32 bytes f(a,b,n)=(2*a+1)/(2*b+1)%2^n++\2 Attempt This Online! PARI/GP has a built-in p-adic type, but using the % ...
user avatar
3 votes

Divide by an odd number, 2-adically

C (gcc), 48 bytes c;i;f(a,b){for(i=32;i;--i)c=a-b-2*b*c;return c;} Try it online! Explanation: since \$(2b+1) (2c+1) = 2(2bc+b+c)+1\$ should end up equal to \$2a+...
user avatar
3 votes

Not-Roman-Numeral Addition

Vyxal, 21 bytes ƛ`.0*`Ẏ⌊øṘṅøṘ;∑øṘvøṘṅ Try it Online! How? ...
user avatar
  • 6,660
3 votes

Weighted coin flip strings

PARI-GP, 75 bytes Port of below solution (can run n ~ 1000000000, k ~ 150) f(n,k,p)=(matrix(k++,k,a,b,(a-1==b)*p+(a<2)*(b<k)*(1-p)+(a+b==k+k))^n)[k,1] Python ...
user avatar
  • 183
3 votes

Implement Binary Exponentiation

PARI/GP, 34 bytes f(x,n)=[x^m\=2|i<-binary(m=2*n+1)] Attempt This Online! PARI/GP, 29 bytes f(a,n)=if(n,f(a,n\2)*x+a^n,1) ...
user avatar
3 votes

Implement Binary Exponentiation

05AB1E, 7 bytes bη0šÙCm Try it online! ...
user avatar
3 votes

Implement Binary Exponentiation

Jelly, 5 bytes :Ƭ2*@ Try it online! Takes n on the left, and x on the right. Based on ...
user avatar

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