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
Example:
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 = 12 → 1)
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
- 2.8k
- 1
- 12
- 23