# Tag Info

1

Pyth, 8 bytes ._eS.+aZ Try it online! Literal translation of James's MATL answer.

0

Branch, 38 bytes ^\4^%/;c1^>/0c45^?[.0]anc2^%/49c105^?. Try it on the online Branch interpreter! Explanation Implicit - the initial node's value is set to the first argument ^\4 Create a parent and sibling and set the right child to 4 % Modulo /; Go to the left child and copy the mod result c1 Go to the right child (automatically ...

2

Vim, 69 bytes V}JYu:sor!n V}JP:%s/^$$.*$$\n\1/m\r\1 :%s/\vm\n.*<(.+) \1.*/n :g/\d/d Try it online! This is vanilla vim (TIO supports V (vim), which is backwards compatible). Takes input as a list of integers, one per line. Outputs m for strictly monotonic, n for non-increasing, and empty string otherwise. V} " select everything J ...

0

Python 3, 113 bytes def f(L): z=0 for i in range(0,len(L)-1): if L[i]-L[i+1]<0: return 2 if L[i]-L[i+1]==0: z=1 return z Try it online! Could be shorter if there were a sign function. This outputs 0 for strictly decreasing, 1 for weakly decreasing and 2 for none of the above.

0

Branch, 2 bytes +# Try it on the online Branch interpreter! Explanation + adds the values of the children of the current node. If any nodes are missing, they are usually created with a value of 0; however, binary operations will instead read from STDIN (this usually gets 0 if the input is exhausted, but if the input was empty to begin with, feof doesn't ...

2

Yggdrasil, 4 bytes +__$Try it online! Yggdrasil automatically substitutes 2 characters for different values when turning the source code in a binary tree. % represents a null byte and _ represents a None value. Yggdrasil then traverses the tree and replaces Nones with sequential command line arguments (i.e. the first encountered, depth-first, is the first ... 1 Japt, 20 bytes No big shenanigans, just recursively calculates the result. §2?1:ßU-ßUÉ)+ßU-ßU-2 §2 // If the input is less than or equal to 2 ?1 // return 1, : // otherwise ß // recursively recall with U-ßUÉ // input minus recursive recall input minus one )+ ... 1 Husk, 17 bytes !¡λṁ!¹m≠→L¹↑_2)ḋ3 Try it online! Feels too long. I'll post something with fix soon. 1 V (vim), 93 bytes :s/1\n/a D@"i1 <esc> qqYplllA]<esc>0i[<esc>:s/$$\d\+$$ $$\d\+$$ /\1+\2,/g C<c-r>=<c-r>" <Esc><c-o>V}J0i <esc>@qq@qdd:s/ i1/1 Try it online! Special casing 1 for <c-o> was a bit annoying, but the rest plays out smoothly. Possible byte saves can be in the large regex, and maybe removing ... 2 Branch, 98 bytes \^//C//70/105/122Z/zc\/66/117/z/za1O[/ob3^%Vc/v?[./]b5^%Wc\w?[./]a/vbw^*/0bo^?[#0]a10.o}O/;b101^-] Try it on the online Branch interpreter! Explanation The first part basically loads "Fizz" and "Buzz" along the left branches of two trees, so it looks like: 0 / \ 0 0 /| / \ F 0 B ... 5 Jelly, 12 bytes :g/æl/;g/}ɗ/ Try it online! Takes input as [[list of numerators], [list of denominators]]. +2 bytes to take input as a list of [numerator, denominator] pairs How it works :g/æl/;g/}ɗ/ - Main link. Takes a pair of lists [N, D] on the left / - Columnwise reduce by: g - GCD : - Divide, reducing the fractions ... 0 Duocentehexaquinquagesimal, 6 bytes 5Q¬$†† Try it online!

0

Duocentehexaquinquagesimal, 5 bytes 3Σª;â Try it online!

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

2

Vyxal, d, 5 bytes 5vτ½⌈ Try it Online! A port of the Jelly answer which is a port of short husk answer. Explained 5vτ½⌈ 5vτ # convert each digit of the input to base 5 ½ # halve each item in that list (halving vectorises all the way down) ⌈ # ceiling each item in that list # -d deep sums the list and implicitly outputs

3

Charcoal, 13 bytes ＩΣ⭆Ｓ⭆↨Ｉι⁵Ｌ↨λ³ Try it online! Link is to verbose version of code. Explanation: Ｓ Convert input to a string ⭆ Map over characters and join ι Current character Ｉ Cast to integer ↨ ⁵ Convert to base 5 ⭆ Map over base 5 digits and join λ Current ...

2

Retina 0.8.2, 20 15 bytes . $*1, 1{5}|11? Try it online! Link includes test cases. Explanation: .$*1, Convert each digit to unary separately. 1{5}|11? Count the number of 5s, 2s and 1s needed to make each digit.

4

Python 2, 37 bytes f=lambda n:n and n/5%2-n%5/-2+f(n/10) Try it online! Uses a formula rather than a lookup table for each digit. n/5%2 counts the five-cent coin, and subtracting -n%5/-2 is equivalent to adding (n%5+1)/2 for the one- and two-cent coins. n%10 0 1 2 3 4 5 6 7 8 9 ----------------------------- n/5%2 0 0 0 0 0 1 1 1 1 1 0-n%5/-2 0 1 ...

4

Wolfram Language (Mathematica), 39 bytes ⌈.4#⌉-⌊#/5⌋&@*IntegerDigits/*Tr Try it online!

2

Grok, 19 bytes :Yp:Y%zp/Yp1%-I,Wzq This outputs remainder,division. Additionally, inputs must be passed through STDIN; it can't be piped from another command. Explanation: :Yp # Takes the first integer from STDIN and duplicates it. :Y # Takes the second integer from STDIN and duplicates it to the register. %z ...

3

Python 2, 48 bytes f=lambda x:x and int("0112212233"[x%10])+f(x/10) Try it online! 49 bytes in Python 3 because you'd need // for floor division.

14

Husk, 11 9 8 bytes Edit: -1 byte thanks to caird coinheringaahing ṁo⌈½ṁB5d Try it online! d # get the digits ṁB5 # convert them all to base-5 # (this gives a 1 for each 5-denomination coin needed, # as well as the leftover for each digit. # We'll need 2 more coins for those with leftover 3 or 4, # ...

5

05AB1E, 11 bytes S<•δ¬Èº•sèO Try it online! Same approach as my Jelly answer. How it works S<•δ¬Èº•sèO - Program. Input: n S - Cast n to digits < - Decrement •δ¬Èº• - Compressed integer: 1122122330 sè - Using n's digits, index into the digits of 1122122330 O - Sum Kudos to Kevin Cruijssen's excellent ...

8

R, 54 51 47 45 bytes Edit: converted to console input instead of a full function to try not to fall behind Robin Ryder's answer d=utf8ToInt(scan(,''))-48;sum(d>0,d>5,d%%5>2) Try it online!

14

JavaScript (ES7),  36  35 bytes Similar to other answers. Using a Black Magic formula instead of a lookup table. f=n=>n&&(n%10)**29%3571%4+f(n/10|0) Try it online! Here is a script that looks for $(p,m)$ pairs such that $(n^p\bmod m)\bmod 4=a_n$ for all $n\in[0..9]$. It's worth noting that this code takes IEEE-754 precision errors into ...

3

C (gcc), 39 bytes f(n){n=n?f(n/10)+""[n%10]:0;} Try it online! JavaScript (Node.js), 37 bytes f=n=>n&&+"0112212233"[n%10]+f(n/10|0) Try it online!

10

Haskell, 55…41 40 bytes -1 byte thanks to xnor, for using a string instead of the hard-coded list. a=0:tail[i+read[j]|i<-a,j<-"0112212233"] Try it online! a is the infinite sequence. How? It's not hard to find the recursive formula $$a(n)=a\left(\left\lfloor\frac{n}{10}\right\rfloor\right)+a(n \operatorname{mod} 10)$$ with the base cases ...

4

Husk, 23 bytes L◄Lfo=⁰Σ↑o≤⁰LṖƒ(+İ€m*10 Try it online! Extremely slow past 11. Explanation L◄Lfo=⁰Σ↑o≤⁰LṖƒ(+İ€m*10 ƒ( create an infinite list using: İ€ currency denomination builtin: [1,1/2,1/5,...200] + plus m*10 the input mapped to *10 this gives [1,1/...

7

R, 64 52 50 45 bytes sum(c(1,2,1:3)[.6*utf8ToInt(scan(,""))-28.4]) Try it online! Same strategy as Delfad0r's Haskell answer, which is nicely explained. First, scan(,"") reads in input as a string. Then, utf8ToInt(...)-48 takes a string of digits and converts it to a vector of integer digits. This works out shorter than taking input as ...

6

Jelly, 7 bytes Db5FHĊS Try it online! Steals Ports Dominic Van Essen's Husk answer, be sure to upvote that! How it works Db5FHĊS - Main link. Takes an integer n on the left D - Convert to digits b5 - Convert each digit to base 5 F - Flatten H - Halve each Ċ - Ceiling of each S - SUm Jelly, 11 bytes Dị“FȮŀO’D¤S Try it ...

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 maximum.(zipWith compare<*>(1/0:)) Try it online! Outputs LT,EQ,GT for strictly monotonic, non-increasing, and otherwise, respectively. Thanks to @xnor for pointing out that my previous version failed on singleton lists and suggesting this alternative. Takes the maximum of the sighn of the differences between adjacent pairs, ... 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! 0 Python 3, 230 bytes def f(n): s="1" while 2>1: if int(s)%n==0: return s if "0" in s: for j in range(0,len(s)): if s[j]=="0": q=j t=s[:q] for k in range(q,len(s)): t=t+str(1-int(s[k])) s=t else: s=str(10**len(s)) 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|... 6 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). 4 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! 4 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 ... 2 Excel, 59 bytes =LET(y,COLUMN(A:O),SUM((0&MID(SEQUENCE(A1),y,1))*10^(y-1))) Explanation =LET( y,COLUMN(A:O) 'y = [1..15] horz.; Excel is accurate to 15 places SUM((0&MID(SEQUENCE(A1),y,1))*10^(y-1)) 'final result SEQUENCE(A1) '[1..A1] vertical (0&... 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 ...

Top 50 recent answers are included