Skip to main content
Commonmark migration
Source Link

#Ti-Basic (TI-84 Plus CE), 48 41 bytes

Ti-Basic (TI-84 Plus CE), 48 41 bytes

Prompt X
For(K,1,0
For(M,-K+1,0
10^(K)-10^(-M
If 0=remainder(Ans,X
Return
End
End

Input is Prompt-ed during the program; output is stored in Ans.

Explanation:

Tries numbers of the form (10n)(10m-1) = 10k-10m, where m+n=k starts at 1 and increases, and for each value of k, it tries m=1,n=k-1; m=2,n=k-2; ... m=k,n=0; until it finds a multiple of X.

This works up to 16; 17 gives a domain error because remainder( can only accept dividends up to 9999999999999 (13 nines), and 17 should output 9999999999999999 (16 nines).

Prompt X               # 3 bytes, input number
For(K,1,0              # 7 bytes, k in the description above; until a match is found
For(M,-K+1,0           # 10 bytes, start with n=1, m=(k-n)=k-1;
                           # then n=2, m=(k-n)=k-2, up to n=k, m=(k-n)=0
                           # (M=-m because it saved one byte)
10^(K)-10^(-M           # 8 bytes, n=(k-m) nines followed by m zeroes → Ans
If not(remainder(Ans,X # 8 bytes, If X is a factor of Ans (remainder = 0)
Return                 # 2 bytes, End program, with Ans still there
End                    # 2 bytes,
End                    # 1 byte (no newline)

#Ti-Basic (TI-84 Plus CE), 48 41 bytes

Prompt X
For(K,1,0
For(M,-K+1,0
10^(K)-10^(-M
If 0=remainder(Ans,X
Return
End
End

Input is Prompt-ed during the program; output is stored in Ans.

Explanation:

Tries numbers of the form (10n)(10m-1) = 10k-10m, where m+n=k starts at 1 and increases, and for each value of k, it tries m=1,n=k-1; m=2,n=k-2; ... m=k,n=0; until it finds a multiple of X.

This works up to 16; 17 gives a domain error because remainder( can only accept dividends up to 9999999999999 (13 nines), and 17 should output 9999999999999999 (16 nines).

Prompt X               # 3 bytes, input number
For(K,1,0              # 7 bytes, k in the description above; until a match is found
For(M,-K+1,0           # 10 bytes, start with n=1, m=(k-n)=k-1;
                           # then n=2, m=(k-n)=k-2, up to n=k, m=(k-n)=0
                           # (M=-m because it saved one byte)
10^(K)-10^(-M           # 8 bytes, n=(k-m) nines followed by m zeroes → Ans
If not(remainder(Ans,X # 8 bytes, If X is a factor of Ans (remainder = 0)
Return                 # 2 bytes, End program, with Ans still there
End                    # 2 bytes,
End                    # 1 byte (no newline)

Ti-Basic (TI-84 Plus CE), 48 41 bytes

Prompt X
For(K,1,0
For(M,-K+1,0
10^(K)-10^(-M
If 0=remainder(Ans,X
Return
End
End

Input is Prompt-ed during the program; output is stored in Ans.

Explanation:

Tries numbers of the form (10n)(10m-1) = 10k-10m, where m+n=k starts at 1 and increases, and for each value of k, it tries m=1,n=k-1; m=2,n=k-2; ... m=k,n=0; until it finds a multiple of X.

This works up to 16; 17 gives a domain error because remainder( can only accept dividends up to 9999999999999 (13 nines), and 17 should output 9999999999999999 (16 nines).

Prompt X               # 3 bytes, input number
For(K,1,0              # 7 bytes, k in the description above; until a match is found
For(M,-K+1,0           # 10 bytes, start with n=1, m=(k-n)=k-1;
                           # then n=2, m=(k-n)=k-2, up to n=k, m=(k-n)=0
                           # (M=-m because it saved one byte)
10^(K)-10^(-M           # 8 bytes, n=(k-m) nines followed by m zeroes → Ans
If not(remainder(Ans,X # 8 bytes, If X is a factor of Ans (remainder = 0)
Return                 # 2 bytes, End program, with Ans still there
End                    # 2 bytes,
End                    # 1 byte (no newline)
added 5 characters in body
Source Link
pizzapants184
  • 3.5k
  • 15
  • 18

#Ti-Basic (TI-84 Plus CE), 4848 41 bytes

Prompt X
1→K
While For(K,1,0
For(NM,1-K+1,K0
10^(K-N)(-10^(N)-1M
If 0=remainder(Ans,X
Return
End
K+1→K
End

Input is Prompt-ed during the program; output is stored in Ans.

Explanation:

Tries numbers of the form (10n)(10m-1) = 10k-10m, where m+n=k starts at 1 and increases, and for each value of k, it tries m=1,n=k-1; m=2,n=k-2; ... m=k,n=0; until it finds a multiple of X.

This works up to 16; 17 gives a domain error because remainder( can only accept dividends up to 9999999999999 (13 nines), and 17 should output 9999999999999999 (16 nines).

Prompt X               # 3 bytes, input number
1→K      For(K,1,0              # 47 bytes, k in the description above
While 1                # 3 bytes,above; until a match is found
For(NM,1-K+1,K   0           # 710 bytes, start with n=1, m=(k-n)=k-1;
                           # then n=2, m=(k-n)=k-2, up to n=k, m=(k-n)=0
                           # (M=-m because it saved one byte)
10^(K-N)(-10^(N)-1M           # 128 bytes, Nn=(k-m) nines followed by K-Nm zeroes → Ans
If not(remainder(Ans,X # 8 bytes, If X is a factor of Ans (remainder = 0)
Return                 # 2 bytes, End program, with Ans still there
End                    # 2 bytes, 
K+1→K                  # 6 bytes, increment loop counter
End                    # 1 byte (no newline)

#Ti-Basic (TI-84 Plus CE), 48 bytes

Prompt X
1→K
While 1
For(N,1,K
10^(K-N)(10^(N)-1
If 0=remainder(Ans,X
Return
End
K+1→K
End

Input is Prompt-ed during the program; output is stored in Ans.

Explanation:

Tries numbers of the form (10n)(10m-1), where m+n=k starts at 1 and increases, and for each value of k, it tries m=1,n=k-1; m=2,n=k-2; ... m=k,n=0; until it finds a multiple of X.

This works up to 16; 17 gives a domain error because remainder( can only accept dividends up to 9999999999999 (13 nines), and 17 should output 9999999999999999 (16 nines).

Prompt X               # 3 bytes, input number
1→K                    # 4 bytes, k in the description above
While 1                # 3 bytes, until a match is found
For(N,1,K              # 7 bytes, start with n=1, m=(k-n)=k-1;
                           # then n=2, m=(k-n)=k-2, up to n=k, m=(k-n)=0
10^(K-N)(10^(N)-1       # 12 bytes, N nines followed by K-N zeroes → Ans
If not(remainder(Ans,X # 8 bytes, If X is a factor of Ans (remainder = 0)
Return                 # 2 bytes, End program, with Ans still there
End                    # 2 bytes, 
K+1→K                  # 6 bytes, increment loop counter
End                    # 1 byte (no newline)

#Ti-Basic (TI-84 Plus CE), 48 41 bytes

Prompt X
For(K,1,0
For(M,-K+1,0
10^(K)-10^(-M
If 0=remainder(Ans,X
Return
End
End

Input is Prompt-ed during the program; output is stored in Ans.

Explanation:

Tries numbers of the form (10n)(10m-1) = 10k-10m, where m+n=k starts at 1 and increases, and for each value of k, it tries m=1,n=k-1; m=2,n=k-2; ... m=k,n=0; until it finds a multiple of X.

This works up to 16; 17 gives a domain error because remainder( can only accept dividends up to 9999999999999 (13 nines), and 17 should output 9999999999999999 (16 nines).

Prompt X               # 3 bytes, input number
For(K,1,0              # 7 bytes, k in the description above; until a match is found
For(M,-K+1,0           # 10 bytes, start with n=1, m=(k-n)=k-1;
                           # then n=2, m=(k-n)=k-2, up to n=k, m=(k-n)=0
                           # (M=-m because it saved one byte)
10^(K)-10^(-M           # 8 bytes, n=(k-m) nines followed by m zeroes → Ans
If not(remainder(Ans,X # 8 bytes, If X is a factor of Ans (remainder = 0)
Return                 # 2 bytes, End program, with Ans still there
End                    # 2 bytes,
End                    # 1 byte (no newline)
Source Link
pizzapants184
  • 3.5k
  • 15
  • 18

#Ti-Basic (TI-84 Plus CE), 48 bytes

Prompt X
1→K
While 1
For(N,1,K
10^(K-N)(10^(N)-1
If 0=remainder(Ans,X
Return
End
K+1→K
End

Input is Prompt-ed during the program; output is stored in Ans.

Explanation:

Tries numbers of the form (10n)(10m-1), where m+n=k starts at 1 and increases, and for each value of k, it tries m=1,n=k-1; m=2,n=k-2; ... m=k,n=0; until it finds a multiple of X.

This works up to 16; 17 gives a domain error because remainder( can only accept dividends up to 9999999999999 (13 nines), and 17 should output 9999999999999999 (16 nines).

Prompt X               # 3 bytes, input number
1→K                    # 4 bytes, k in the description above
While 1                # 3 bytes, until a match is found
For(N,1,K              # 7 bytes, start with n=1, m=(k-n)=k-1;
                           # then n=2, m=(k-n)=k-2, up to n=k, m=(k-n)=0
10^(K-N)(10^(N)-1       # 12 bytes, N nines followed by K-N zeroes → Ans
If not(remainder(Ans,X # 8 bytes, If X is a factor of Ans (remainder = 0)
Return                 # 2 bytes, End program, with Ans still there
End                    # 2 bytes, 
K+1→K                  # 6 bytes, increment loop counter
End                    # 1 byte (no newline)