# Tag Info

## New answers tagged math

2

349. Kotlin, 774 bytes, A000607 val primes = mutableListOf<Int> (2) val prev = mutableListOf<Double>(1.0) fun sequence(n: Int): Double { if (n < prev.size) return prev.get(n) var sum = 0.0 for (k in (primes.last() + 1)..n) { var prime = true for (p in primes) if (k % p == 0) { ...

0

Scratch, 327 bytes (Illegitimate) Try it online! I was really excited to submit this answer, but then I read the first rule, stating that my program must generate all 36 numbers before I can submit. However, this rule makes hard-coding the only viable option, which is not optimal. I decided to circumvent the several millennia necessary to satisfy this rule, ...

0

05AB1E, 32 bytes ∞ʒDg6-sηε2.£}¦D€SP.ι3Ý3*>è2ä€ËP* Try it online! Link includes a header and footer to increase efficiency by making it start looking from $1,000,000$, but works (extremely slowly) without them. The program will not terminate after finding all $900$ Meeker numbers. ∞ʒDg6-sηε2.£}¦D€SP.ι3Ý3*>è2ä€ËP* # full program ʒ ...

0

Jelly, 20 bytes DḌ,PƊƝFḊm3⁼2/Ạ ȷ6Ç#Ṫ A monadic Link accepting $n$ that yields the $n^\text{th}$ Meeker number Try it online! Very slow so will probably time out for $n \gt 36$. How? ȷ6Ç#Ṫ - Main Link: integer, n ȷ6 - 10^6 # - find the first n integers starting at 10^6 for which: Ç - call Link 1 Ṫ - tail DḌ,PƊƝFḊm3⁼2/Ạ - Link 1: ...

0

Python 3, 56 bytes def f(n): k=1 for i in range(2,n+1): k=k*i return k Try it online!

2

JavaScript, 572 (?) bytes _=>@r>=V6R=bWn3s*Ch=%{Fg>QNM' |c6SMH>wF=* IElopM2Mw=?-,Knb7bW{\\=\rH3j=N9.3l*jm6Y(.wJP| tFR7vmvt/))*D.F) . n}Hk18KTn0a{E6 w1z0]\\o.jV"ytga25d+~VNP{0v:zq[d) |.]d,t6P5:;:*?9m[8sI>\\R"' wG*<#[^L/HFzAISvBDnmuy;+JNQj_n{[*d6D H#Ht sLt}\T+DX3T6/17 guv,\\d8G!\\9;Wug[78\\Iw]5" r!~ZqN96Y\\99-g ...

1

Perl 5, 58 bytes /(.)(.)(.(.))(.)/,$1*$2==$3&&$5*$4==$'&&say for 1e6..1e7-1 Try it online! Outputs the entire list of Meeker numbers.

1

Scala, 103 bytes Stream from 1 map "".+filter{x=>x.size==7&&x.map(_-48).sliding(4,3).forall{x=>x(0)*x(1)==10*x(2)+x(3)}} Try it in Scastie! A pretty straightforward answer. You can treat it like a function giving the nth Meeker number (0-indexed) or as a list of all Meeker numbers.

4

R, 101 91 bytes [=for;a[1:9,b[0:9,e[0:9,show(paste0(a,b,if(a*b<10)0,d<-a*b,e,if((f=d%%10*e)<10)0,f))]]] Try it online! Inspired by and taking a similar approach to Manish Kundu's answer. This is a horrible piece of R hackery that redefines square brackets '[]', normally used for indexing, to be a short alias for the for looping function. The ...

0

Scratch, 62 bytes when gf clicked ask()and wait say(round((answer)/([sqrt v]of(2

5

Haskell, 252… 203 bytes minimum.map g.permutations.nub g[]=0 g(p:q:r)=1+g(snd$span(p#q$r!!0)r) g _=1 (a#b)c d|t<-c!a?j(b!a)=t!!1/=0&&b!d?t?j(c!d)!!1==0 j[x,y]=[x,-y] [x,y]?[z,t]=[x*z-y*t,x*t+y*z] (!)=zipWith(-) import Data.List Try it online! The relevant function is minimum.map g.permutations.nub, which takes a list of points as input (each ...

1

Pyth, 58 bytes A(/%Q100T+1/Q100)A(*GH*%*GHT%QT)s[+T/QT*"0"<GTG%QT*"0"<HTH Try it online! Same as my Python solution. A assigns the two provided elements to the variables G and H respectively. Q is the input (zero-indexed).

3

C (clang), 107 99 bytes Saved 8 bytes thanks to the man himself Arnauld!!! a;b;p;q;f(){for(a=0;9/++a;)for(b=0;b<100;)printf("%d%d%02d%d%02d ",a,p=b/10,p*=a,q=b++%10,p%10*q);} Try it online! Prints them all.

1

JavaScript (SpiderMonkey), 78 bytes g=x=>x<10?'0'+x:x for(i=99;i<999;print(a+b+g(a*=b)+e+g(a%10*e)))[a,b,e]=++i+'' Try it online!

4

Python 2, 121 115 98 bytes def f(n,t=10):p,q=n%100/t,1+n/100;r=p*q;s=n%t*(r%t);printt+n/t+'0'*(r<t)+r+n%t+'0'*(s<t)+s Try it online! On noticing the digits, I observed a pattern and got this constant time solution. Takes n as input (0-indexed) and prints n'th meeker number. For example, the first 2 digits follow the pattern: 10, 11, 12, ... ...

1

Charcoal, 33 bytes Ｆ…χ¹⁰⁰Ｆχ⟦⪫⟦ι﹪%02dΠικ﹪%02d×﹪Πιχκ⟧ω Try it online! Link is to verbose version of code. Prints all 900 Meeker numbers. Explanation: Ｆ…χ¹⁰⁰ Loop over all possible first pairs of digits. Ｆχ Loop over all possible fifth digits. ⟦⪫⟦...⟧ω Print the following items on one line and then move to the next line. ι The first two digits. ﹪%02dΠι ...

1

Haskell, 82 80 76 bytes -6 bytes thanks to kops, for rearranging things and proposing a better interpretation of the rules :P [n|n<-show<$>[1..],[a,b,c,d,e,f,g]<-[read.pure<$>n],a*b==10*c+d,d*e==10*f+g] Try it online! The list of all Meeker numbers, represented as strings. Haskell, 80 bytes [n>>=show|n@[a,b,c,d,e,f,g]<-mapM([0.....

2

Haskell, 60 bytes f q|(a,~(_:t))<-span(>24)q=sum[1|x<-a,x>29,take 4a<a]>2||f t Try it online! This combines some ideas from previous Haskell answers in a new form along with exit by error code to come out ahead. How? (a,~(_:t))<-span(>24)q puts the prefix of the list which is entirely >24 into a, and then tries to match the ...

4

APL (Dyalog Extended), 45 bytes (SBCS) Full program. Prints all meeker numbers. Requires 0-based indexing (⎕IO←0). 1e6+⍸{(×⌿i⊇⍵)≡10⊥⍵[2+i←0 1,⍪3 4]}¨10⊤¨1e6…1e7 Try it online! (limited to upper bound of 2 000 000 ― above code works offline) 1e6…1e7 numbers 1 000 000 through 10 000 000 10⊤¨ base-10 representation of each (splits digits of numbers into lists ...

3

Husk, 27 bytes föΛo§=oΠ←od→C2§e←→X4dfo=7LN Try it online! returns the list of all meeker numbers. It's horribly inefficient, so here's a version which starts from 1e7, and shows the first n values. EDIT: corrected the answer after Dominic Van Essen found a bug.

3

JavaScript (Node.js), 86 bytes _=>[...Array(1e7).keys()].filter(x=>(s=x+'')[0]*s[1]==s[2]+s[3]&&s[3]*s[4]==s[5]+s[6]) Try it online! I feel like this is too long. Explanation Basically, this gets all numbers from 0 to 9999999, coerces each to a string and checks character-wise. One of Javascript's quirks is that multiplied strings are coerced ...

1

Husk, 11 10 bytes Se≠¹÷2+¹←= Try it online! Se≠¹÷2+¹←= # full program: Se≠⁰÷2+⁰←=²⁰ # here with implicit final arguments added for clarity; +⁰ # add to n: ← # one less than =²⁰ # 1 if n==m # (in other words, subtract 1 from n if n==m), ÷2 # now integer divide by 2, Se # ...

6

JavaScript (Node.js), 25 bytes m=>n=>[a=n/2+(n<m)|0,n-a] Try it online! JavaScript (Node.js), 24 bytes m=>n=>[b=n-(n<m)>>1,n-b] Try it online!

4

JavaScript (ES6), 28 bytes Expects (nmax)(n). Returns [B,A]. (This is based on my current understanding of the task.) m=>n=>[b=n/2-(n<m&~n)|0,n-b] Try it online!

3

Python, 266 63 bytes And we're down to less than half one-third one-quarter two-sevenths one-quarter of my original, so a lot less scuffed than anything I've put out, but it's a first answer: def a(b,c): m=(b<c)*(1-.5*(b%2)) return int(b/2+m),int(b/2-m) Takes advantage of the fact that $\frac {a+1} {b+1} < \frac a b$, if $a > b$: after that, ...

0

M4, 49 bytes define(f,ifelse($1,0,1,eval($1*f(decr($1)))')') Try it online! Usage f(n)dnl where n is an integer. 3 Haskell, 34 bytes signum.minimum.(zipWith(-)<*>tail) Try it online! Outputs 1,0,-1 for strictly monotonic, non-increasing, and otherwise, respectively. Takes the sign of the minimum of the differences between adjacent pairs. (zipWith(-)<*>tail applied to l computes l - tail l elementwise). This is competitive with the existing Haskell answers ... 0 Vyxal, 6 5 bytes ‡Ė+ḭƒ Try it Online! I added foldr lol. Explained ‡Ė+ḭƒ ‡Ė+ # lambda x, y: 1 / x + y ḭ # reduce input by ↑, going right-to-left ƒ # fractionify the result 1 Husk, 4 bytes Ḟ·+\ Try it online! pretty simple with TNum being a rational type. 2 Wolfram Language (Mathematica), 57 56 bytes MaximalBy[Range@#-1,#>9&&1+#0@@Times@@@RealDigits@#&,1]& Try it online! Returns the value wrapped in a list. Since MaximalBy chooses the maximum based on Mathematica's internal ordering, choosing a value for the base case (when n≤9) isn't necessary. 1 C (gcc), 95 94 bytes Saved a byte thanks to ceilingcat!!! a;b;c;d;r;f(n){for(b=0;n--;r=c>=b?b=c,n:r)for(c=0,d=n;a=d,d=d>9;++c)for(;a;a/=10)d*=a%10;d=r;} Try it online! 3 Haskell, 82 bytes f n=snd$minimum$((,)=<<p)<$>[0..n-1] p n|n>9=p(product$read.pure<$>show n)-1 p n=0 Try it online! Golfing Delfad0r's solution by using the decorate-sort-undecorate idiom to find the maximizing value. It's easier to see how it works in this slightly longer version. 83 bytes f n=snd$minimum[(-p i,i)|i<-[0..n-1]] p n|... 5 Python 2, 70 bytes lambda n:max(range(n),key=g) g=lambda x:x<10or-~g(eval('*'.join(x))) Try it online! The helper function g recursively computes multiplicative persistence, and the main function in the top line finds value that maximizes g among the half-open range from 0 to n. It works out that max chooses the earlier element in case of a tie for ... 3 Retina, 60 bytes .+ * L$. $. +/\d.+/_~(.$&$* )^ .+¶#$$.( . # D#+ ¶* ¶ Try it online! Link includes test cases. Explanation: .+ * L. . List the numbers up to n. +/\d.+/_ Repeat while there are numbers of at least two digits... ~(. &* )^ .+¶#$$.( ... convert the numbers into Retina expressions that calculate their digital product ... 4 Scratch, 454 bytes Try it online! This one was fun to make! It takes 13 seconds to process the first 100,000 numbers. Alternatively, 48 blocks. when gf clicked set[H v]to( set[M v]to( set[N v]to(-1 ask()and wait repeat(answer change(N)by(1 set[C v]to( delete all of[B v repeat(length of(N change[C v]by(1 add(letter(C)of(N))to[B v end set[P v]to( repeat until&... 4 Befunge-98 (FBBI), 107 105 108 bytes +3 for a bugfix with the tiebreaks. Definitely some golfing left to do... < v:-1_;#$ <;v#:& e:p1 9;jN' <^;#1p4 ;\0:<v; +1:$<^ +\1\v>:9! #^_\1 >$$^ @.N'< ^#::<X'*%ap55/a_ Try it online! The code contains two null bytes, indicated by N above How? slightly outdated Product of the ... 2 R, 59 55 bytes Edit: -2 bytes thanks to Giuseppe, quickly superseded by -4 bytes (a different way) thanks to Robin Ryder n=scan();while(print(n)>9)n=prod(utf8ToInt(c(n,""))-48) Try it online! A different method to Giuseppe's answer for the same number of bytes, here as a full recursive function instead of the (often-shorter) approach of taking ... 1 Befunge-98 (FBBI), 43 42 bytes &;1\v>#;:.:9!#@_; >$$ ^ ^#::< '*%ap25/a_ Try it online! The first line takes input, prints the values and runs until a value <=9 is reached. The third line computes the product of digits of an integer (26 bytes on its own). 3 JavaScript (Node.js), 68 bytes g=n=>n>9&&-~g(eval([...n+''].join*));f=n=>n--?g(h=f(n))<g(n)?n:h:0 Try it online! 5 Julia 0.7, 58 54 bytes n->findmax(.!(0:n-1))[2]-1 !n=n>9?!prod(digits(n))+1:0 Try it online! 3 Charcoal, 18 bytes ＦＮ⊞υ∧›ι⁹⊕§υΠιＩ⌕υ⌈υ Try it online! Link is to verbose version of code. Explanation: ＦＮ Loop over the range 0..n-1. ⊞υ Push to the predefined list... ∧›ι⁹ ... zero if the current index is less than 10, otherwise... ⊕§υΠι ... increment the previously calculated persistence of the digital product of the current index. Ｉ⌕υ⌈υ Print the ... 6 R, 94 91 87 bytes Edit: thanks to Kirill L. for spotting 2 (!) bugs, and also saving 3 bytes, and -4 more bytes thanks to Robin Ryder which.max(Map(f<-function(x)if(x>9,1+f(prod(utf8ToInt(c(x,""))-48)),0),1:scan()-1))-1 Try it online! Started as a rather unimaginative construction based around Giuseppe's 'Multiplicative persistence' ... 3 Haskell, 86 85 84 bytes -1 byte thanks to xnor for removing the f 1=0 case. f n|n>1,x<-f$n-1,p x>=p(n-1)=x f n=n-1 p n|n>9=1+p(product$read.pure<$>show n) p n=1 Try it online!

6

Jelly, 10 bytes ḶDP$ƬL$ÐṀḢ Try it online! Jelly, 10 bytes ḶDP$Ƭ€ẈMḢ’ Try it online! How they work ḶDP$ƬL$ÐṀḢ - Main link. Takes n on the left Ḷ - Unlength; [0, 1, 2, ..., n-1]$ÐṀ - Return the maximal elements under the previous 2 links: $Ƭ - Iterate the previous 2 links until reaching a fixed point, collecting all steps: D ... 4 PowerShell, 110 bytes param($n)filter f{$_ if($_-gt9){("$_"|% t*y)-join'*'|iex|f}} ($k=0..$n|%{($_|f).count}).indexof((\$k|sort)[-1]) Try it online! Thanks to @mazzy for the function and -24 bytes

4

Vyxal, mM, 9 bytes ƛ⁽Π↔L;:Gḟ Try it Online! Never have I had to use both m and M flags in the same challenge. Explained ƛ⁽Π↔L;:Gḟ ƛ # over the range [0, input) - managed by the m and M flags ⁽Π↔ # get the iterations of the multiplicative persistance - repeatedly take the product of the digits of each number in the range, collecting results ...

8

Husk, 10 bytes ►ȯLU¡oΠd↔ŀ Try it online! Explanation ►ȯLU¡oΠd↔ŀ ↔ŀ reverse the range 0..n-1 ►ȯ max-by, returning the last maximal element for the following: ¡o create an infinite list using: Πd product of digits. U longest unique prefix L take its length

3

Python 2, 85 bytes d=[] for x in range(input()):d+=x<10or-~d[eval('*'.join(x))], print d.index(max(d)) Try it online! Using a function to calculate the persistence came in at 87 bytes, but there might be way to do everything in a single function.

4

JavaScript (ES6), 77 bytes f=(n,m)=>n--?f(n,m>(g=n=>v=n>9&&-~g(eval([...n+''].join*)))(n)?m:(x=n,v)):x Try it online!

3

05AB1E, 12 bytes L<ε.ΓSP}g]Zk Try it online! Commented: L< # push [1 .. input] - 1 ε } # map over each integer: .Γ } # cumulative fixed-point: # run until the result doesn't change and collect results SP # take the product (P) of the digits (S) g # get the length of the ...

Top 50 recent answers are included