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 ...


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, # ...


14

Python 2, 37 bytes Outputs a flattened \$ n \times n \$ latin square. lambda n:((range(n)*-~n)[1:]*n)[::~n] Try it online!


11

05AB1E, 3 bytes ΔÒJ Try it online! Δ run until the output doesn't change: Ò prime factors including duplicates J join into an integer


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 ...


10

Haskell, 15 bytes a#b=b++b#(a++b) Try it online! Takes strings a and b as input, returns the whole infinite Fibonacci word, as is usually allowed in sequence challenges. How? Not much to say. This answer relies on the identity $$ F(a,b)=b+F(b,a+b), $$ where \$F(a,b)\$ is the infinite Fibonacci word with starting words \$a\$ and \$b\$.


10

Python 2, 87 80 68 bytes f=lambda x:x>1and min((y%10)**6%305%3+f(y/10*x/y)for y in[x,-x])or x Try it online! -7 bytes thanks to @tsh, and -12 bytes thanks to @dingledooper. Thanks to everyone else for their own golf suggestions. Instead of tearing down the banknotes in the top-down way, this solution builds up the answer from the bottom. Since the ...


9

Python 3, 36 bytes f=lambda a,b,i:b[i:i+1]or f(b,b+a,i) Try it online! -8 bytes thanks to dingledooper Not a particularly creative approach. In fact, basically this is just what l4m2 did but Python will error when accessing out of bounds instead of returning undefined. Using b[i:i+1] returns b[i] (for strings) if it's in range, but doesn't error and ...


9

Jelly, 6 5 bytes ⁹;¡⁵ị Try it online! Uses 1 indexing -1 byte thanks to Jonathan Allan, noticing that we could avoid ⁵ becoming the right argument to ;¡ by forcing ;¡ into a nilad-dyad pair with ⁹! Dyadic ¡ is essentially Jelly's generalised Fibonacci operator How it works ⁹;¡⁵ị - Main link. Takes A on the left, B on the right and I as the third argument ⁹ ...


9

APL (Dyalog Unicode), 17 bytes ≢⍉↑⊆⍨∨/≠/∨⍀⎕a∘.=⎕ Try it online!


9

Jelly, 3 bytes RṙⱮ Try it online! Explanation RṙⱮ Monadic link, takes an argument z R [1, 2, ..., z-1, z] Ɱ For each on right argument (z, defaults to loop over range) ṙ Rotate the left list by the right amount Alternative solution: +þ%. Generates the \$n\times n\$ addition table and then applies modulo to bring the elements into range.


9

APL (dzaima/APL), 4 bytes ⌽ᐵ⍨⍳ ⌽ rotate ᐵ each left, apply each left element to the entire right argument ⍨ apply to both arguments ⍳ range Try it online!


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


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!


8

APL(Dyalog Unicode), 8 6 bytes SBCS /⍨∘~∘≠ Try it on APLgolf! A function submission which takes L1 on the left and L2 on the right. -2 bytes from Bubbler. Explanation /⍨∘~∘≠ /⍨ remove elements from L! identified by: ~ the bitwise negation of ≠ unique mask of L2


8

Python 2, 49 bytes A cool new approach from @kops, which outputs by modifying the input. def f(a,b): while b:b.pop()in b or a.pop(len(b)) Try it online! Python 2, 51 bytes lambda a,b:[x for x in a[::-1]if b.pop()in b][::-1] Try it online! We can determine whether an element stays in L1 by whether the corresponding element in L2 is its first occurrence. ...


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 ...


7

JavaScript (Node.js), 26 bytes n=>g=a=>b=>b[n]||g(b)(b+a) Try it online! Thank tsh for -1 Byte


7

JavaScript (ES6),  58  55 bytes f=n=>n-(g=d=>q=n>1?n%d?g(d+1):d+g(d,n/=d):'')(2)?f(q):q Try it online! Commented f = n => // f is a recursive function taking the input n n - ( // subtract from n the result of a call to ... g = d => // ... g: a recursive function taking a divisor d q = ...


7

Haskell, 65 52 51 bytes f[] f z(a:s)(b:t)=[a|b`elem`z]++f(b:z)s t f _[]_=[] Try it online! The solution is the anonymous function which calls f applied to the empty list: f[]. f keeps track of which elements of L2 we've seen already and only adds the corresponding element of L1 to the result if we haven't seen L2's head yet. import Data.List for the ...


8

Jelly, 7 bytes 1ṭVẒɗ1# Try it online! How it works 1ṭVẒɗ1# - Main link. Takes n on the left ɗ - Define a dyad f(k, n) from the previous 3 links: ṭ - Tack; Yield [n, k] V - Eval; Smash together into a single integer Ẓ - Is prime? 1 1# - Starting from k = 1, find the first k such that f(k, n) is true


7

R, 30 bytes n=scan();outer(1:n,1:n,`+`)%%n Try it online!


7

Haskell, 32 bytes f n=[[x..n]++[1..x-1]|x<-[1..n]] Try it online! A kind-of boring approach, just concatenates the ranges. 34 bytes f n=[mod(k+div(-k)n)n|k<-[1..n*n]] Try it online! Outputs a flat list, zero-indexed, using the method from my Python answer. A slight adaptation is needing to make it work for [1..n*n] instead of [0..n*n-1].


7

APL (Dyalog Unicode), 6 bytes ⍳⌽,⍨⍴⍳ Try it online! There's already a nice 4-byter in dzaima/APL by rak1507, but I wanted to share a non-trivial short one in vanilla Dyalog. It is shorter than a modulo addition table ⊢|⍳∘.+⍳ and ties with the trivial port of rak's ⍳⌽¨∘⊂⍳. Takes n and creates a flat matrix of numbers. ⍳⌽,⍨⍴⍳ ⍝ Input: n ,⍨ ⍝ [n, n] ...


8

Jelly, 5 bytes :Æṣ’$ : integer divide Æṣ’$ the decremented divisor sum This uses \$\lfloor\frac{n}{\sigma(n)-n-1}\rfloor\$ instead of \$\frac{n-1}{\sigma(n)-n-1}\$, but it still works because \$\frac{1}{\sigma(n)-n-1}\$ can never be greater than or equal to 1. Try it online!


7

J, 24 23 20 bytes <.@%1<:@#.[:I.0=i.|] Try it online! -3 thanks to rak's rounding down trick Let n be the input. <.@% round down n divided by 1<:@#. 1 minus the sum of [:I. the indexes where 0= 0 is equal to the remainder when i. the list 0..n-1 | is divided elementwise into ] n.


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 ...


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' ...


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 ...


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!


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