Skip to main content

New answers tagged

2 votes

Generate a subgroup of a free group

Haskell + hgl, 79 bytes f w=nn>~(m(rF(#)[]<fo)<mM(p$ap[id,rv<m(*(-1))]w)<ef 0) a#(h:t)| -h==a=t a#b=a:b Attempt This Online! Takes positive and ...
corvus_192's user avatar
  • 5,532
1 vote

Smallest Harmonic number greater than N

Vyxal, 6 bytes ↵ʀĖ¦⌈ḟ Try it Online! You know me, gotta be posting the most stupid and inefficent answers. Goes slow for inputs that make \$10^x\$ very large. 1-...
lyxal's user avatar
  • 33.6k
1 vote

Smallest Harmonic number greater than N

PHP, 51 bytes function f($n,$k=0){return$n<1?$k:f($n-1/++$k,$k);} Try it online!
LucianDex's user avatar
  • 159
1 vote

Display numbers lacking 2's

><>, 40 33 bytes 0v o>1+:::a%:2=@-a,2=+?!n:b9*)?;0 Try it online! Or watch the execution in real time with this interpreter All the numbers are output, ...
mbomb007's user avatar
  • 23.4k
3 votes

Generate a subgroup of a free group

Jelly, 18 17 bytes UN;ƊL⁹ḃịƲF;Ṗ+Ṫ¥?/ Try it online! -1 thanks to Jonathan Allan Takes the words as positive and negative integers on the left, and a 1-index on the ...
Unrelated String's user avatar
0 votes

Display numbers lacking 2's

Scratch 3, 10 blocks / 97 bytes Try it online! ScratchBlocks Syntax ...
lyxal's user avatar
  • 33.6k
1 vote

Display numbers lacking 2's

Uiua SBCS, 20 bytes ≡&p▽∵◇/↧⊸≠@2°⋕+1⇡100 Try it! Explanation ...
chunes's user avatar
  • 24.6k
2 votes

Generate a subgroup of a free group

Charcoal, 54 bytes ⊞υωWS«⊞υι⊞υ⭆⮌ι⎇№ακ↧κ↥κ»≔⍘NυθWΦE⪫υω⁺κ⎇№ακ↧κ↥κ№θκ≔⁻θ⌊ιθθ Try it online! Link is to verbose version of code. Takes a newline-terminated list of ...
Neil's user avatar
  • 172k
6 votes

Smallest Harmonic number greater than N

Octave, 34 bytes f=@(n)find(cumsum(1./(1:4^n))>n,1) Try it Online! Explanation Vectorization + cumulative sum. Can evaluate ...
Ka Wa Yip's user avatar
  • 181
3 votes

Generate a subgroup of a free group

Pyth, 25 bytes #jmu?s>2K+GHKPGsdYy=+m__M Try it online! Words are lists of non-zero integers where inversing is done by negation. Generates output infinitely ...
CursorCoercer's user avatar
6 votes

Smallest Harmonic number greater than N

Python 3, 34 bytes f=lambda n,k=2:n<1or-~f(n-1/k,k+1) A recursive function that accepts \$n\$ (0-indexed) and returns the required number of terms. Try it ...
Jonathan Allan's user avatar
2 votes

Smallest Harmonic number greater than N

Ruby, 28 27 bytes ->n{(1..).find{0>n-=1r/_1}} Attempt This Online!
G B's user avatar
  • 22.1k
5 votes

Generate a subgroup of a free group

Jelly,  24  23 bytes FµŻSƝaSƝTị UN;ƊṗⱮẎÇÐL€ḣ A dyadic Link that accepts the list of words on the left, and a non-negative integer, \$n\$, on the right and yields a ...
Jonathan Allan's user avatar
5 votes

Smallest Harmonic number greater than N

R, 36 bytes \(n){k=0;while(F<=n)F=F+1/(k=k+1);k} Try it online! Minus 2 bytes thanks to @pajonk's suggestion in comment.
Rui Barradas's user avatar
3 votes

Smallest Harmonic number greater than N

Desmos, 43 bytes f(n)=g(n,1) g(n,k)=\{n<0:0,g(n-1/k,k+1)+1\} Port of xnor's Python answer. Try It On Desmos! Try It On Desmos! - Prettified
Aiden Chow's user avatar
  • 13.6k
3 votes

Smallest Harmonic number greater than N

05AB1E, 7 bytes ∞.ΔLzO‹ Given a 0-based \$n\$, outputs the \$n^{th}\$ value. Try it online or verify the infinite list. Explanation: ...
Kevin Cruijssen's user avatar
1 vote

Output the missing integer

R, 31 bytes \(S)(0:9)[!mapply(grepl,0:9,S)] Attempt This Online! I think it's very easy: the range 0..9 is subset by a ...
int 21h Glory to Ukraine's user avatar
2 votes

Smallest Harmonic number greater than N

Brachylog, 11 bytes ≤.⟦₁/₁ᵐ+>?∧ Try it online! Takes n as input. Explanation ...
Fatalize's user avatar
  • 38.9k
3 votes

Smallest Harmonic number greater than N

Wolfram Language (Mathematica), 43 bytes Ceiling@*InverseFunction[HarmonicNumber]@*N Try it online! (for some reason TIO returns ...
Greg Martin's user avatar
  • 15.8k
4 votes

Smallest Harmonic number greater than N

Google Sheets, 57 bytes Expects \$n\$ in A1 (\$0\$-indexed) =LET(R,LAMBDA(R,s,i,IF(s>A1,i-1,R(R,s+1/i,i+1))),R(R,,1)) Reaches calc limit starting from \$n=10\$ (...
z..'s user avatar
  • 751
4 votes

Smallest Harmonic number greater than N

cQuents, 13 12 bytes $0:#$<bN ;/$ Try it online! -1 because I remembered I had added a unary / for reciprocal Explanation ...
Stephen's user avatar
  • 14k
2 votes

Smallest Harmonic number greater than N

MATL, 11 bytes `1@:/sG>~}@ Inputs n, outputs a(n). Try it online! How it works ...
Luis Mendo's user avatar
  • 105k
3 votes

Smallest Harmonic number greater than N

PowerShell Core, 37 bytes for(){if(($s+=1/++$d)-gt$c){$d $c++}} Try it online! Outputs the sequence indefinitely
Julian's user avatar
  • 3,118
4 votes

Smallest Harmonic number greater than N

Jelly, 7 bytes İ€S>ð1# A monadic Link that accepts a non-negative integer and yields a singleton list containing a positive integer. Or a full program that ...
Jonathan Allan's user avatar
4 votes

Smallest Harmonic number greater than N

Arturo, 41 bytes g:$[n k][(n<1)?->k->g n-1//<=k+1]$=>[g&1] Try it! A port of Arnauld's JavaScript answer. Arturo doesn't have default arguments, ...
chunes's user avatar
  • 24.6k
6 votes

Smallest Harmonic number greater than N

Python 3, 36 bytes f=lambda n,k=1:n>=0and-~f(n-1/k,k+1) Try it online! Outputs zero-indexed, which is how the OEIS is defined. 43 bytes ...
xnor's user avatar
  • 145k
2 votes

Smallest Harmonic number greater than N

Python, 41 bytes f=lambda n,k=0:n<1and k or f(n-1/-~k,-~k) A port of @Arnauld's answer. Attempt This Online!
corvus_192's user avatar
  • 5,532
2 votes

Smallest Harmonic number greater than N

Charcoal, 18 bytes NθW¬‹θ⁰«→≧⁻∕¹ⅈθ»Iⅈ Try it online! Based on @Arnauld's answer but I chose to make mine 0-indexed. Explanation:...
Neil's user avatar
  • 172k
4 votes

Smallest Harmonic number greater than N

Haskell, 31 bytes (0!) k!n|n<1=k|k<-1+k=k!(n-1/k) Ungolfed: ...
corvus_192's user avatar
  • 5,532
5 votes

Smallest Harmonic number greater than N

JavaScript (ES6), 29 bytes Returns the \$n\$-th term, 1-indexed. f=(n,k=0)=>n<1?k:f(n-1/++k,k) Try it online!
Arnauld's user avatar
  • 193k
4 votes

Smallest Harmonic number greater than N

Vyxal 3, 8 bytes λɾė∑⁰>}“ Try it Online! ...
RubenVerg's user avatar
  • 842
0 votes

Output the inventory sequence

Python 3, 59 bytes i=0;a=[0]*99 while 1:print(n:=a[i]);a[n]+=1;i=[i+1,0][n==0] This is a mostly straightforward golfing of OP's program, with ...
dan04's user avatar
  • 6,571
2 votes

A bit of a digital XOR

R, 51 bytes \(n,`+`=\(b)n%/%b^rev(0:log(n,b))%%b)(+2*+10)[+2>0] Attempt This Online!
pajonk's user avatar
  • 16.7k
1 vote

A bit of a digital XOR

Pip, 11 bytes a@_X BMETBa Attempt This Online! Explanation ...
DLosc's user avatar
  • 39.7k
2 votes

A bit of a digital XOR

R, 75 bytes \(x,b=bitwAnd(x,e<-2^((log(x,2)%/%1):0))/e)(utf8ToInt(c(x,""))-48+0*b)[!!b] Attempt This Online! A function which inputs a number \$x\$ ...
int 21h Glory to Ukraine's user avatar
2 votes

Output the inventory sequence

Retina 0.8.2, 65 bytes .+ $*_ smr{1`(^0((¶)|.)*?¶)?_ $1$#3¶_ (((^\4$)|.)*)(\d+)¶_ $1$#3¶ Try it online! Outputs the first N ...
Neil's user avatar
  • 172k
2 votes

Output the inventory sequence

Haskell, 60 bytes g[]0 g a i|let c=sum[1|x<-a,x==i]=c:g(c:a)(last$0:[i+1|c>0]) Prints the sequence indefinitely. Attempt This Online!
corvus_192's user avatar
  • 5,532
3 votes

Output the inventory sequence

Bash, 53 bytes -21 bytes by @12431234123412341234123 and myself: By removing the loop condition (and run infinitely, which I had feelings about), I also get to use ...
Themoonisacheese's user avatar
3 votes

Output the inventory sequence

Perl 5, 45 bytes {{$a[$_=$a[$i++]|0]++;say;$_&&redo}$i=0;redo} Try it online!
Xcali's user avatar
  • 15.3k
4 votes

Output the inventory sequence

Brainfuck, 135 Byte ...
12431234123412341234123's user avatar
2 votes

Output the inventory sequence

Charcoal, 12 bytes FN⊞υ№υ⌕⮌υ⁰Iυ Try it online! Link is to verbose version of code. Outputs the first N terms. Explanation: Port ...
Neil's user avatar
  • 172k
4 votes

Output the inventory sequence

05AB1E, 11 7 bytes 0λλÂ0k¢ -4 bytes porting @JonathanAllan's Jelly approach, so make sure to upvote that answer as well! Outputs the infinite sequence. Try it ...
Kevin Cruijssen's user avatar
3 votes

Output the inventory sequence

Python 3.8 (pre-release), 54 bytes i,*a=0, while[print(x:=a.count(i))]:i,*a=x and-~i,*a,x Try it online! Full program that prints indefinitely Python 3.8 (pre-...
Jitse's user avatar
  • 7,324
2 votes

Output the inventory sequence

Uiua, 42 37 chars, 72 59 bytes ◌:∧(⊂:⟜(:⟨-.:|+1:⟩±)/+=,,°□◌)⇡250□[]0 Try it I've literally never written program in Uiua before so it's probably nowhere near ...
mousetail's user avatar
  • 12.7k
4 votes

Output the inventory sequence

Google Sheets, 90 bytes =LET(R,LAMBDA(R,l,v,i,LET(c,COUNTIF(l,v),IF(i=250,l,R(R,{l;c},(c>0)*(v+1),i+1)))),R(R,,,)) Commented ...
z..'s user avatar
  • 751
4 votes

Output the inventory sequence

Ruby, 44 38 bytes $*<<B while$_=0<(B=p$*.count$_)?$_+1:0 Try it online! thanks to @Dingus for saving 6 Bytes
AZTECCO's user avatar
  • 10.8k
2 votes

Output the inventory sequence

PowerShell Core, 44 bytes for($s=@{}){($l=+$s.($i=++$i*!!$l)) $s.$l++} Try it online! Outputs the sequence indefinitely ...
Julian's user avatar
  • 3,118
3 votes

Output the inventory sequence

R, 56 52 bytes N={};repeat{show(x<-sum(F==N));N=c(N,x);F=(F+1)*!!x} Attempt This Online! R, 60 56 52 bytes -4 bytes thanks to the pajonk's suggestion ...
int 21h Glory to Ukraine's user avatar
4 votes

Output the inventory sequence

R (lower than version 4.1), 50 bytes p={} repeat F="if"(p<-c(print(sum(p==F)),p),F+1,0) Try it online! Prints indefinitely (or until R runs out of ...
Giuseppe's user avatar
  • 28.6k
6 votes

Output the inventory sequence

Jelly, 10 bytes Ṛi0’ċ@ṭµ¡Ḋ Try it online! A monadic Link accepting the number of terms, N, to produce and yielding a list of the first N terms. How? ...
Jonathan Allan's user avatar

Top 50 recent answers are included