Skip to main content
We’ve updated our Terms of Service. A new AI Addendum clarifies how Stack Overflow utilizes AI interactions.
Code Golf

Return to Answer

edited body
Source Link
absoluteAquarian
  • 2.8k
  • 1
  • 12
  • 23

TI-BASIC (TI-84), (削除) 30 (削除ここまで) 2223 bytes

Note: The byte count of a program is evaluated using the value in [MEM]>[2]>[7] (36 bytes) then subtracting the length of the program's name, CDGF2, (5 bytes) and an extra 98 bytes used for storing the program:

36 - 5 - 98 = 2223 bytes

TI-BASIC (TI-84), (削除) 30 (削除ここまで) 22 bytes

Note: The byte count of a program is evaluated using the value in [MEM]>[2]>[7] (36 bytes) then subtracting the length of the program's name, CDGF2, (5 bytes) and an extra 9 bytes used for storing the program:

36 - 5 - 9 = 22 bytes

TI-BASIC (TI-84), (削除) 30 (削除ここまで) 23 bytes

Note: The byte count of a program is evaluated using the value in [MEM]>[2]>[7] (36 bytes) then subtracting the length of the program's name, CDGF2, (5 bytes) and an extra 8 bytes used for storing the program:

36 - 5 - 8 = 23 bytes

edited body
Source Link
absoluteAquarian
  • 2.8k
  • 1
  • 12
  • 23

TI-BASIC (TI-84), (削除) 30 (削除ここまで) 2122 bytes

Note: The byte count of a program is evaluated using the value in [MEM]>[2]>[7] (3536 bytes) then subtracting the length of the program's name, CDGF2, (5 bytes) and an extra 9 bytes used for storing the program:

3536 - 5 - 9 = 2122 bytes

TI-BASIC (TI-84), (削除) 30 (削除ここまで) 21 bytes

Note: The byte count of a program is evaluated using the value in [MEM]>[2]>[7] (35 bytes) then subtracting the length of the program's name, CDGF2, (5 bytes) and an extra 9 bytes used for storing the program:

35 - 5 - 9 = 21 bytes

TI-BASIC (TI-84), (削除) 30 (削除ここまで) 22 bytes

Note: The byte count of a program is evaluated using the value in [MEM]>[2]>[7] (36 bytes) then subtracting the length of the program's name, CDGF2, (5 bytes) and an extra 9 bytes used for storing the program:

36 - 5 - 9 = 22 bytes

added 165 characters in body
Source Link
absoluteAquarian
  • 2.8k
  • 1
  • 12
  • 23

TI-BASIC (TI-84), 30(削除) 30 (削除ここまで) 21 bytes

:Ans→N:2Ans=sum(seq(NAns/Xnot(remainder(NAns,X)),X,1,NAns,1:2N=sum(Ans

Horribly inefficient, but it works(削除) Horribly inefficient, but it works. (削除ここまで)
Reducing the bytecount sped up the program by a lot.
Input is in Ans.
Output is in Ans and is automatically printed out when the program completes.

UngolfedExplanation:
(TI-BASIC doesn't have comments, so just assume that ; makes a comment)

:Ans→N
:2Ans=sum(seq(NAns/Xnot(remainder(NAns,X)),X,1,NAns ;Full program
 2Ans ;double the input
 seq( ;generate a list
 X, ;using the variable X,
 1, ;starting at 1,
:2N=sum Ans ;and ending at the input
 ;with an implied increment of 1
 Ans/X ;from the input divided by X
 not( ), ;multiplied by the negated result of
 remainder(Ans,X) ;the input modulo X
 ;(result: 0 or 1)
 sum( ;sum up the elements in the list
 = ;equal?
6
 6
prgmCDGF2
 1
7
 7
prgmCDGF2
 0

Explanation:

:Ans→N

Stores the input into N. Ans is affected by most commands run in the calculator, so we need to store the input for later.

:seq(N/Xnot(remainder(N,X)),X,1,N,1

seq( creates a list based on the expression, increment variable, start, end, and step provided.
N/X just divides N by the increment variable. not(remainder(N,X)) will return 0 if X is not a factor of N, 1 if it is. These two expressions are evaluated then multiplied. Thus the list for N=6 would be: {6,3,2,0,0,1}

:2N=sum(Ans

sum( takes a list as input and returns the sum of all of the elements within the list. Since seq( was the last thing evaluated, Ans will contain a list.
Using the example N=6, sum(Ans will return 12. (6 +たす 3 +たす 2 +たす 0 +たす 0 +たす 1 = 12)
The result of sum(Ans is checked against 2N. If they are equal, the program will return 1, 0 if not.
(2 * 6 = 121)

Note: The byte count of a program is evaluated using the value in [MEM]>[2]>[7] (4435 bytes) then subtracting the length of the program's name, CDGF2, (5 bytes) and an extra 9 bytes used for storing the program:

4435 - 5 - 9 = 3021 bytes

TI-BASIC (TI-84), 30 bytes

:Ans→N:seq(N/Xnot(remainder(N,X)),X,1,N,1:2N=sum(Ans

Horribly inefficient, but it works.
Input is in Ans.
Output is in Ans and is automatically printed out when the program completes.

Ungolfed:

:Ans→N
:seq(N/Xnot(remainder(N,X)),X,1,N,1
:2N=sum(Ans
6
 6
prgmCDGF2
 1
7
 7
prgmCDGF2
 0

Explanation:

:Ans→N

Stores the input into N. Ans is affected by most commands run in the calculator, so we need to store the input for later.

:seq(N/Xnot(remainder(N,X)),X,1,N,1

seq( creates a list based on the expression, increment variable, start, end, and step provided.
N/X just divides N by the increment variable. not(remainder(N,X)) will return 0 if X is not a factor of N, 1 if it is. These two expressions are evaluated then multiplied. Thus the list for N=6 would be: {6,3,2,0,0,1}

:2N=sum(Ans

sum( takes a list as input and returns the sum of all of the elements within the list. Since seq( was the last thing evaluated, Ans will contain a list.
Using the example N=6, sum(Ans will return 12. (6 +たす 3 +たす 2 +たす 0 +たす 0 +たす 1 = 12)
The result of sum(Ans is checked against 2N. If they are equal, the program will return 1, 0 if not.
(2 * 6 = 121)

Note: The byte count of a program is evaluated using the value in [MEM]>[2]>[7] (44 bytes) then subtracting the length of the program's name, CDGF2, (5 bytes) and an extra 9 bytes used for storing the program:

44 - 5 - 9 = 30 bytes

TI-BASIC (TI-84), (削除) 30 (削除ここまで) 21 bytes

:2Ans=sum(seq(Ans/Xnot(remainder(Ans,X)),X,1,Ans,1

(削除) Horribly inefficient, but it works. (削除ここまで)
Reducing the bytecount sped up the program by a lot.
Input is in Ans.
Output is in Ans and is automatically printed out when the program completes.

Explanation:
(TI-BASIC doesn't have comments, so just assume that ; makes a comment)

:2Ans=sum(seq(Ans/Xnot(remainder(Ans,X)),X,1,Ans ;Full program
 2Ans ;double the input
 seq( ;generate a list
 X, ;using the variable X,
 1, ;starting at 1,
 Ans ;and ending at the input
 ;with an implied increment of 1
 Ans/X ;from the input divided by X
 not( ), ;multiplied by the negated result of
 remainder(Ans,X) ;the input modulo X
 ;(result: 0 or 1)
 sum( ;sum up the elements in the list
 = ;equal?
6
 6
prgmCDGF2
 1
7
 7
prgmCDGF2
 0

Note: The byte count of a program is evaluated using the value in [MEM]>[2]>[7] (35 bytes) then subtracting the length of the program's name, CDGF2, (5 bytes) and an extra 9 bytes used for storing the program:

35 - 5 - 9 = 21 bytes

Source Link
absoluteAquarian
  • 2.8k
  • 1
  • 12
  • 23
Loading

AltStyle によって変換されたページ (->オリジナル) /