# Tag Info

1

K (oK), 28 33 bytes {$[^o:1+(x{x!y*10}[x]\10)?1;0;o]} Try it online! If it's okay to return nulls (0N) instead of "any non-positive integer", 4 bytes can be saved by shortening the code to: {o*~^o:1+(x{x!y*10}[x]\10)?1} K (ngn/k), 16 23 bytes {1+(x{x!y*10}[x]\10)?1} As suggested by @traws. Adapted to work with long patterns. 1 Wolfram Language (Mathematica), 45 41 39 bytes n_:>Lookup[Mod[10^#,n]->#&~Array~n,1,0] Try it online! Defined as a delayed rule that can be applied to any integer. 1 Python 3, 50 bytes f=lambda n,i=1:i*(10**i%n==1)or~(i<n and~f(n,i+1)) Try it online! 2 GolfScript, 20 19 bytes ~:x,{10\?x%1=},0+1= Try it online! ~:x # Assign the input to x 13 , # Make an array from 0 to x-1 [0 1 2 3 4 5 6 7 8 9 10 11 12] { }, # Find all numbers that pass this test 10\?x% # (10^k)%x [1 10 9 12 3 4 1 ... 2 Perl 5 (-p -Mbigint), 31 bytes$_=++$i<$_?9x$i*1%$_?redo:$i:-1 Try it online! 2 Husk, 8 bytes €1m%¹↑İ⁰ Try it online! Same approach as Bubbler's answer. €1m%¹↑İ⁰ €1 # index of first '1' in m # list of results of applying %¹ # MOD n ↑ # to first n elements of İ⁰ # series of powers of 10 (starting at 10) 0 Batch, 91 bytes @set/ap=1,k=0 :g @set/ak=-~k%%%1,p=p*10%%%1 @if %k% neq 0 if %p% neq 1 goto g @echo %k% Explanation: Repeatedly increments the answer and multiplies the power by 10 until (modulo the input) the answer wraps around to zero or the power reduces to 1. 0 Charcoal, 13 bytes ＮθＩ⊕⌕﹪Ｘχ…¹θθ¹ Try it online! Link is to verbose version of code. Basically a port of @Bubbler's answer, except that my range goes from 1 to n-1. Explanation: Ｎθ Take input as a number … Exclusive range ¹ From literal 1 θ To input number Ｘ Vectorised raise to power ... 0 Retina, 68 bytes .+[1379]$ _,$&*_,; \d+ 0 {; ;_ \G_ 10* +(_+,)\1 ,$1 ^_,.+;(_+) $.1 Try it online! Link includes faster test cases. Explanation: .+[1379]$ _,\$&*_,; If the number is coprime to 10, then create a work area with the values p=1, n and k=0 (in unary). \d+ 0 But if it is not coprime to 10 then set the answer to 0 immediately. {` ...

3

05AB1E, 7 6 bytes L.Δ°I% Port of @Bubbler's Jelly answer, so make sure to upvote him! -1 byte thanks to @ovs. Outputs -1 if it's non-repeating. Try it online or verify all test cases (times out for the final test case). Explanation: L # Push a list in the range [1, (implicit) input-integer] .Δ # Find the first value in this list which is truthy ...

1

C (gcc), 55 52 bytes Saved 3 bytes thanks to the man himself Arnauld!!! i;m;f(n){for(i=m=1;(m*=10)%n&&m%n-1;++i);m=m%n?i:0;} Try it online! Returns either the length of repeated pattern of $\frac{1}{\space n \space}$ or $0$ for no repeated pattern.

3

JavaScript (Node.js), 39 bytes Expects a BigInt. Returns $0$ if there's no repeating pattern. f=(n,k=1n)=>10n**(k%=n)%n-1n?f(n,-~k):k Try it online!

14

Jelly, 6 bytes R⁵*%i1 Try it online! Basically compute 10**[1..n] % n and get the 1-based index of 1.

2

Jelly, 21 bytes R⁵*’ḍ@¹TṂȧ@⁸g10¤’¬¤o- Try it online! This is probably very suboptimal (edit yes it is, i don't know why i didn't think to combine the two checks together cuz that would've given Bubbler's algorithm which is pretty smart).

2

Husk, 3 bytes →…0 Try it online! Takes a range … from 0 toward the input, then gets its last element →. For a positive input this goes like 3.3; [0,1,2,3]; 3. For a negative input this goes like -3.3; [0,-1,-2,-3]; -3.

1

Husk, 8 bytes ḟo=⁰ΣṖİ\ Try it online! Larger denominators take very long, as we are calculating the powerset of an infinite list. Takes input as a fraction a/b. Explanation ḟo=⁰ΣṖİ\ İ\ Infinite list [1,1/2,1/3...] Ṗ Powerset ḟo first sublist which satisfies: Σ sum =⁰ equals input?

2

Husk, 4 bytes ←x'. Try it online! Splits the string on '.' and takes the first segment.

1

Husk, 13 bytes ṁz*İ1zR:1İ2İ½ Try it online! Abuses the built in sequences to the fullest. Outputs an infinite list. Explanation ṁz*İ1zR:1İ2İ½ İ½ powers of ½ :1İ2 powers of 2, with 1 prepended zR zip replicate the second by the first z* then zip multiply that with: İ1 odd numbers ṁ map to each ...

Top 50 recent answers are included