Skip to main content
Share Your Experience: Take the 2024 Developer Survey
8 votes

Divisor chain counts (1 3 3 7 ...)

Jelly, 10 9 7 bytes ÆḌƬFLḤ’ Try it online! ...
Unrelated String's user avatar
8 votes

Divisor chain counts (1 3 3 7 ...)

Python 3, 45 bytes f=lambda n,d=1:d//n or-~f(d)*(n%d<1)+f(n,d+1) Try it online! 51 bytes ...
xnor's user avatar
  • 145k
6 votes

Divisor chain counts (1 3 3 7 ...)

Nekomata + -n, 6 bytes ĎSᵉti¦ Attempt This Online! ...
alephalpha's user avatar
  • 48.2k
6 votes

Divisor chain counts (1 3 3 7 ...)

R, 44 bytes `?`=\(n,d=1)`if`(d<n,(n?d+1)+(1+?d)*!n%%d,1) Attempt This Online! Port of @xnor's Python answer.
pajonk's user avatar
  • 16.4k
5 votes

Divisor chain counts (1 3 3 7 ...)

05AB1E, 10 bytes ÑæʒRüÖP}g< Try it online! ...
Command Master's user avatar
5 votes

Divisor chain counts (1 3 3 7 ...)

Rust, 63 54 bytes (#2) Thanks to @att for the massive –9 bytes! fn f(n:i64)->i64{(1..n).fold(1,|a,d|a-(1>>n%d)*!f(d))} Attempt This Online! Rust, 63 bytes ...
leo848's user avatar
  • 637
5 votes

Divmod continuously until the remainder is 1 or 0, then get the remainder

Nekomata, 4 bytes ʷ{Ƶþ ...
alephalpha's user avatar
  • 48.2k
4 votes

Implement the divisibility-by-7 rule

GCC, x86, No optimization, 30 bytes f(i){i=i<70?i:f(i/10-i%10*2);} Try it online! Written to Read ...
l3akwire's user avatar
4 votes

Divisor chain counts (1 3 3 7 ...)

JavaScript (ES6), 35 bytes -11 bytes thanks to @Neil! Returns the \$n\$-th term. f=(n,d=n)=>d--&&f(n,d)-!(n%d)*~f(d) Try it online! Or try a faster ...
Arnauld's user avatar
  • 193k
4 votes

Divisor chain counts (1 3 3 7 ...)

JavaScript (Node.js), 37 bytes f=(n,p=n)=>--p?f(n,p)+!(n%p)*-~f(p):1 Try it online! Found independent, I'd just leave it here
l4m2's user avatar
  • 24.4k
4 votes

Divisor chain counts (1 3 3 7 ...)

Uiua, 18 bytes ∧+1+1∵(|1↬2)⊚=0◿⇡. Try it online! ...
Bubbler's user avatar
  • 76.8k
3 votes

Division and remainder

TypeScript's Type System, 78 bytes //@ts-ignore type M<A,B,T=[]>=A extends[...B,...infer I]?M<I,B,[...T,1]>:[T,A] Try it at the TypeScript Playground! ...
noodle man's user avatar
  • 7,133
3 votes

Division and remainder

Thunno 2, 3 bytes 禌 Try it online! ç: Apply two commands parallelly: ¦: swapped integer ...
The Thonnu's user avatar
  • 18.1k
3 votes

Divisor chain counts (1 3 3 7 ...)

Retina 0.8.2, 34 bytes .+ $* +%M!&`^|(1+$)(?<=^\1\1+)|$ ¶ Try it online! Link includes test cases. Explanation: .+ $* ...
Neil's user avatar
  • 171k
3 votes

Divmod continuously until the remainder is 1 or 0, then get the remainder

JavaScript (ES6), 27 bytes f=(p,q)=>q>1?f(p/q|0,p%q):q Try it online! Or 25 bytes with BigInts.
Arnauld's user avatar
  • 193k
3 votes

Divmod continuously until the remainder is 1 or 0, then get the remainder

Python 2, 35 bytes f=lambda a,b:f(a/b,a%b)if b>1else b Try it online!
enzo's user avatar
  • 2,093
3 votes

Divmod continuously until the remainder is 1 or 0, then get the remainder

R, 33 bytes f=\(x,y)`if`(y>1,f(x%/%y,x%%y),y) Attempt This Online! A recursive function taking two arguments and returning 1 or 0.
Nick Kennedy's user avatar
  • 21.1k
3 votes

Divmod continuously until the remainder is 1 or 0, then get the remainder

C (gcc), 27 bytes f(a,b){a=b>1?f(a/b,a%b):b;} Try it online!
G. Sliepen's user avatar
3 votes

Divmod continuously until the remainder is 1 or 0, then get the remainder

x86-32 machine code, 9 bytes x86-64 machine code, 10 bytes, same asm source Args in EAX (dividend), ECX (divisor), return value in ECX (0 or 1 final remainder). To call from C, ...
Peter Cordes's user avatar
  • 4,837
2 votes

How even is a number?

C, 23 bytes f(x){x=x&1?0:f(x/2)+1;} Essentially just counts leading 0s recursively.
Zoey's user avatar
  • 111
2 votes

Implement the divisibility-by-7 rule

Uiua, 16 bytes ⍢(⌊-×2⊃◿÷10|>70) Try it in the pad! Explanation ...
Joao-3's user avatar
  • 1,163
2 votes

Implement the divisibility-by-7 rule

Google Sheets, 84 bytes =LET(n,A1,f,LAMBDA(self,n,IF(n<71,n,self(self,INT(n/10)-(n-INT(n/10)*10)*2))),f(f,n) This implements the division-by-7-rule recursively ...
Patric's user avatar
  • 303
2 votes

Proper Divisor mash-up

Thunno 2 -S, 5 bytes ı⁺FṫG Try it online! Explanation ...
The Thonnu's user avatar
  • 18.1k
2 votes

Division and remainder

Uiua, 4 bytes ⌊⊃÷◿ Try it! ...
chunes's user avatar
  • 24.3k
2 votes

Modulus Summation

K (ngn/k), 13 12 bytes -1 byte from @ovs' improvement +/1_!'/|1!:\ Try it online! |1!:\ generate a two-item list containing <...
coltim's user avatar
  • 5,903
2 votes

Divisor chain counts (1 3 3 7 ...)

Ruby, 79 38 bytes f=->n{1+(1...n).sum{|r|1[n%r]*-~f[r]}} Try it online!
G B's user avatar
  • 22.1k
2 votes

Proper Divisor mash-up

Arturo, 32 bytes $=>[∑map..2&=>[x:do factors&]] Try it!
chunes's user avatar
  • 24.3k
2 votes

Divisibility Streak

Thunno 2, 5 bytes Ƙ+n⁺% Try it online! Explanation ...
The Thonnu's user avatar
  • 18.1k
2 votes

Divisor chain counts (1 3 3 7 ...)

Charcoal, 21 bytes FN⊞υ↨Eι∧¬∧κ﹪ικ⊕§υκ¹Iυ Try it online! Link is to verbose version of code. Outputs the first \$ n \$ values starting at \$ N=0 \$ whose value is ...
Neil's user avatar
  • 171k
2 votes

Divisor chain counts (1 3 3 7 ...)

PARI/GP, 31 bytes f(n)=sumdiv(n,d,1+if(d<n,f(d))) Attempt This Online!
alephalpha's user avatar
  • 48.2k

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