Skip to main content
turned into qalc answer and only mention TI-Basic at the end
Source Link

qalc/Qalculate, 138 bytes

If reading from any variable is allowed:

(p-1)!²%p 

Otherwise 12 bytes:

ans−1)!²%ans 

Example usage in Bash for the "ans" case:

echo "5" | qalc -t -f - "(ans−1"ans−1)! ²%ans" 

The tricky part was readingReading the number in in qalc is difficult. It'sIt has a system of variables, but I haven't figured out how to set those in the CLI yet. In the GUI it's pretty easy to insert. That's one of the main reasons why I also provided a solution with "ans".

Inserting the number into the formula two times, but that would mean modifying the "program", which is surely not allowed. 

There seems to also be no way to execute multiple expressions non-interactively with qalc, except by reading in a file. In this case, I used - as a "file", which is StdIn, and used that only to store the input in ans, which is implicitly done by qalc. You could also use an actual file and use the number in that file as input. Or you could even say that ans is already the input of the "program", in which case the program is simply the 1312 bytes seen at the top. It could also be stored inabove, or even any other variable, in which casethen the 8 byte solution could be shortened by 4 bytes.

qalc/Qalculate, 13 bytes

(ans−1)!²%ans 

Example usage in Bash:

echo "5" | qalc -t -f - "(ans−1)! ²%ans" 

The tricky part was reading the number in. It's pretty easy to insert the number into the formula two times, but that would mean modifying the "program", which is surely not allowed. There seems to also be no way to execute multiple expressions non-interactively with qalc, except by reading in a file. In this case, I used - as a "file", which is StdIn, and used that only to store the input in ans, which is implicitly done by qalc. You could also say that ans is the input of the "program", in which case the program is simply the 13 bytes seen at the top. It could also be stored in any other variable, in which case the solution could be shortened by 4 bytes.

qalc/Qalculate, 8 bytes

If reading from any variable is allowed:

p-1)!²%p 

Otherwise 12 bytes:

ans−1)!²%ans 

Example usage in Bash for the "ans" case:

echo "5" | qalc -t -f - "ans−1)! ²%ans" 

Reading the number in in qalc is difficult. It has a system of variables, but I haven't figured out how to set those in the CLI yet. In the GUI it's pretty easy. That's one of the main reasons why I also provided a solution with "ans".

Inserting the number into the formula two times would mean modifying the "program", which is surely not allowed. 

There seems to be no way to execute multiple expressions non-interactively with qalc, except by reading in a file. In this case, I used - as a "file", which is StdIn, and used that only to store the input in ans, which is implicitly done by qalc. You could also use an actual file and use the number in that file as input. Or you could even say that ans is already the input of the "program", in which case the program is simply the 12 bytes seen above, or even any variable, then the 8 byte solution.

turned into qalc answer and only mention TI-Basic at the end
Source Link

TI-Basicqalc/Qalculate, 1013 bytes

fPart((Ans-1ans−1)!²/Ans²%ans 

This outputs 0 for non-prime numbers and something in the range 0 < number < 1 for prime numbers.* If you want a proper 1 for prime numbers, prepend either not(not( or 0≠ for a 12 byte solution. But this is not actually required for a "truthy" value, because for example If .5 executes the "Then" statement.

This solution is based on this Labyrinth answer, but theThe great thing about programming on"programming" in a calculator is that you can basically just enter formulas directly. The only part of

Example usage in Bash:

echo "5" | qalc -t -f - "(ans−1)! ²%ans" 

Note that formula that's not a builtin is a%b. I hadadded a space after the exclamation mark only because Bash otherwise tries to use interpret "fPart(a/b)" as an "event". It's not actually required by qalc, which is the fractional part of the division. Newer calculator models and maybe even newer operating systemscan be seen by for example creating this onefile:

5 (ans−1)!²%ans 

…and then executing it with (I'm using 2.43, 2qalc -t -f test.txt.55 is available, but horrendously laggy and counterintuitive)

Other consoles or other ways of calling qalc than Bash might not have a modulo builtin, so this program would probably be one byte shorter with thoseproblem.

The program reads from and writes to the variable "calculation can also be entered in "interactive mode" by simply running Ansqalc -t", which is basicallyentering the StdInnumber and StdOut ofthen entering the TI-84+ calculatorexpression on the next input. IfThis also works in the last instruction of aGUI program results"Qalculate".

Meta explanation:

The output is 0 for non-prime numbers and a positive integer for prime numbers. I let this run in a numberloop for all numbers up to 10000 and it was always 1 for prime numbers, thenbut I haven't checked whether that number is automatically printedguaranteed yet. But you can also

This solution is based on this Labyrinth answer. I essentially just runfound something (qalc) that linehas all the parts of the formula as an instruction inbuiltins instead of having to program all the regular calculator viewparts myself on a lower level.

As a program with the name "The P-t", argument hides the file is 20 bytes largeinterpreted calculation, of which one byte is the file name and nine bytes are metadata etc. I'm not quite sure whetherso that counts as part of the byte count foroutput of the answer, but since it can also be executed as a simple calculation statement, I would rather not count it. Writing a program is not actually required to executeexample command looks like this.:

Breakdown:

fPart((Ans-1)!²/Ans5  Ans the previous output, handled just like any variable1  Ans 

…instead of like this:

5 = same5  rem( factorial(ans - 1) subtract one^2, of course ! builtin factorial function ² builtin square/second power function fPart(  fractional part of a decimal (internally actually complexans) number fPart((Ans-= 1)!²/Ans 

A closing bracket atThe tricky part was reading the endnumber in. It's pretty easy to insert the number into the formula two times, but that would mean modifying the "program", which is actuallysurely not needed, TIallowed. There seems to also be no way to execute multiple expressions non-Basic understands it anywayinteractively with qalc, except by reading in a file.
The optional In this case, I used not(- I mentioned returns 1 for an input of 0as a "file", which is StdIn, and 0 otherwise. Applyingused that twice leaves 0 unchanged and turns everything else into 1only to store the input in ans, which is implicitly done by qalc. You could also say that 0≠ans acts exactlyis the sameinput of the "program", in which case the program is simply the 13 bytes seen at the top. It could also be stored in any other variable, in which case the solution could be shortened by 4 bytes.

 

For the first few prime numbers, the result of that modulo operation is always 1. That might be random or it might be guaranteed, I haven't checked that yet.
If it's guaranteed, you can also prepend Ans for an 11 byte solution with an output of 1originally wrote this answer for prime numbers (because b·fPart(a/b) is the same as a%b).TI-Basic:

The catch

fPart((Ans-1)!²/Ans 

*This program has one big issue, however: Due to imprecisionsThat's just 10 bytes, this program only correctly identifiesbut it fails on the prime numbers up to 11input 13 already, afterwards it claims everythingdue to be a non-prime number. Everything above 42 even causes an overflow error, because 42floating point imprecisions in those large numbers (12!² is bigger than 10¹⁰⁰²=229442532802560000). So the check for 9 is actually the only one within the working range that differs from a check fordifference to an even/odd numbers.


Alternatively, this formula can be used inchecker within the command line calculator "qalc" thatworking range is often preinstalled on Linux9 and init does not fulfil the GUI equivalent "Qalculate":

(42−1)!²%42 returns 0.
(13-1)!²%13 returns 1criterion to work up to 255.
(100000007-1)!²%100000007 takes a while and then returns For inputs above 42 it even crashed from an overflow 1.

But I wouldn't call inserting that number there a "programming language". Variables could be defined before the execution and then used in the calculation, which might make that a valid solution, but I haven't played around with that much yet(42!²>10¹⁰⁰).

TI-Basic, 10 bytes

fPart((Ans-1)!²/Ans 

This outputs 0 for non-prime numbers and something in the range 0 < number < 1 for prime numbers.* If you want a proper 1 for prime numbers, prepend either not(not( or 0≠ for a 12 byte solution. But this is not actually required for a "truthy" value, because for example If .5 executes the "Then" statement.

This solution is based on this Labyrinth answer, but the great thing about programming on a calculator is that you can basically just enter formulas directly. The only part of that formula that's not a builtin is a%b. I had to use fPart(a/b), which is the fractional part of the division. Newer calculator models and maybe even newer operating systems for this one (I'm using 2.43, 2.55 is available, but horrendously laggy and counterintuitive) have a modulo builtin, so this program would probably be one byte shorter with those.

The program reads from and writes to the variable "Ans", which is basically the StdIn and StdOut of the TI-84+ calculator. If the last instruction of a program results in a number, then that number is automatically printed. But you can also just run that line as an instruction in the regular calculator view.

As a program with the name "P", the file is 20 bytes large, of which one byte is the file name and nine bytes are metadata etc. I'm not quite sure whether that counts as part of the byte count for the answer, but since it can also be executed as a simple calculation statement, I would rather not count it. Writing a program is not actually required to execute this.

Breakdown:

fPart((Ans-1)!²/Ans  Ans the previous output, handled just like any variable  Ans  same  (  -1) subtract one, of course ! builtin factorial function ² builtin square/second power function fPart(  fractional part of a decimal (internally actually complex) number fPart((Ans-1)!²/Ans 

A closing bracket at the end is actually not needed, TI-Basic understands it anyway.
The optional not( I mentioned returns 1 for an input of 0 and 0 otherwise. Applying that twice leaves 0 unchanged and turns everything else into 1. 0≠ acts exactly the same.

For the first few prime numbers, the result of that modulo operation is always 1. That might be random or it might be guaranteed, I haven't checked that yet.
If it's guaranteed, you can also prepend Ans for an 11 byte solution with an output of 1 for prime numbers (because b·fPart(a/b) is the same as a%b).

The catch

*This program has one big issue, however: Due to imprecisions, this program only correctly identifies the prime numbers up to 11, afterwards it claims everything to be a non-prime number. Everything above 42 even causes an overflow error, because 42!² is bigger than 10¹⁰⁰. So the check for 9 is actually the only one within the working range that differs from a check for even/odd numbers.


Alternatively, this formula can be used in the command line calculator "qalc" that is often preinstalled on Linux and in the GUI equivalent "Qalculate":

(42−1)!²%42 returns 0.
(13-1)!²%13 returns 1.
(100000007-1)!²%100000007 takes a while and then returns 1.

But I wouldn't call inserting that number there a "programming language". Variables could be defined before the execution and then used in the calculation, which might make that a valid solution, but I haven't played around with that much yet.

qalc/Qalculate, 13 bytes

(ans−1)!²%ans 

The great thing about "programming" in a calculator is that you can basically just enter formulas directly.

Example usage in Bash:

echo "5" | qalc -t -f - "(ans−1)! ²%ans" 

Note that I added a space after the exclamation mark only because Bash otherwise tries to interpret "" as an "event". It's not actually required by qalc, which can be seen by for example creating this file:

5 (ans−1)!²%ans 

…and then executing it with qalc -t -f test.txt.

Other consoles or other ways of calling qalc than Bash might not have this problem.

The calculation can also be entered in "interactive mode" by simply running qalc -t, entering the number and then entering the expression on the next input. This also works in the GUI program "Qalculate".

Meta explanation:

The output is 0 for non-prime numbers and a positive integer for prime numbers. I let this run in a loop for all numbers up to 10000 and it was always 1 for prime numbers, but I haven't checked whether that is guaranteed yet.

This solution is based on this Labyrinth answer. I essentially just found something (qalc) that has all the parts of the formula as builtins instead of having to program all the parts myself on a lower level.

The -t argument hides the interpreted calculation, so that the output of the example command looks like this:

5 1 

…instead of like this:

5 = 5 rem(factorial(ans - 1)^2, ans) = 1 

The tricky part was reading the number in. It's pretty easy to insert the number into the formula two times, but that would mean modifying the "program", which is surely not allowed. There seems to also be no way to execute multiple expressions non-interactively with qalc, except by reading in a file. In this case, I used - as a "file", which is StdIn, and used that only to store the input in ans, which is implicitly done by qalc. You could also say that ans is the input of the "program", in which case the program is simply the 13 bytes seen at the top. It could also be stored in any other variable, in which case the solution could be shortened by 4 bytes.

 

I originally wrote this answer for TI-Basic:

fPart((Ans-1)!²/Ans 

That's just 10 bytes, but it fails on the input 13 already, due to floating point imprecisions in those large numbers (12!²=229442532802560000). So the only difference to an even/odd checker within the working range is 9 and it does not fulfil the criterion to work up to 255. For inputs above 42 it even crashed from an overflow (42!²>10¹⁰⁰).

Source Link

TI-Basic, 10 bytes

fPart((Ans-1)!²/Ans 

This outputs 0 for non-prime numbers and something in the range 0 < number < 1 for prime numbers.* If you want a proper 1 for prime numbers, prepend either not(not( or 0≠ for a 12 byte solution. But this is not actually required for a "truthy" value, because for example If .5 executes the "Then" statement.

This solution is based on this Labyrinth answer, but the great thing about programming on a calculator is that you can basically just enter formulas directly. The only part of that formula that's not a builtin is a%b. I had to use fPart(a/b), which is the fractional part of the division. Newer calculator models and maybe even newer operating systems for this one (I'm using 2.43, 2.55 is available, but horrendously laggy and counterintuitive) have a modulo builtin, so this program would probably be one byte shorter with those.

The program reads from and writes to the variable "Ans", which is basically the StdIn and StdOut of the TI-84+ calculator. If the last instruction of a program results in a number, then that number is automatically printed. But you can also just run that line as an instruction in the regular calculator view.

As a program with the name "P", the file is 20 bytes large, of which one byte is the file name and nine bytes are metadata etc. I'm not quite sure whether that counts as part of the byte count for the answer, but since it can also be executed as a simple calculation statement, I would rather not count it. Writing a program is not actually required to execute this.

Breakdown:

fPart((Ans-1)!²/Ans Ans the previous output, handled just like any variable Ans same ( -1) subtract one, of course ! builtin factorial function ² builtin square/second power function fPart( fractional part of a decimal (internally actually complex) number fPart((Ans-1)!²/Ans 

A closing bracket at the end is actually not needed, TI-Basic understands it anyway.
The optional not( I mentioned returns 1 for an input of 0 and 0 otherwise. Applying that twice leaves 0 unchanged and turns everything else into 1. 0≠ acts exactly the same.

Algorithm explanation:

The Wikipedia article linked in the Labyrinth answer looks pretty confusing, but the principle is easy:

(6-1)!²%6 = 1·1·2·2·3·3·4·4·5·5%6 = 1·1· 6 · 6 ·4·4·5·5%6 = 6 · something %6 = 0 

This works because every non-prime number is the product of at least two factors that are smaller than that number. Prime numbers aren't, which leads to something like this:

(5-1)!²%5 = 1·1·2·2·3·3·4·4%5 = 1·1·2·2·3·3·4·4%5 (no multiplication of those factors results in anything divisible by 5) = 1 

The squaring is necessary in case there is only one prime factor and that occurs twice:

(9-1)!²%9 = 1·1·2·2·3·3·4·4·5·5·6·6·7·7·8·8%9 = 1·1·2·2· 9 ·4·4·5·5·6·6·7·7·8·8%9 = 9 · something %9 = 0 

For the first few prime numbers, the result of that modulo operation is always 1. That might be random or it might be guaranteed, I haven't checked that yet.
If it's guaranteed, you can also prepend Ans for an 11 byte solution with an output of 1 for prime numbers (because b·fPart(a/b) is the same as a%b).

The catch

*This program has one big issue, however: Due to imprecisions, this program only correctly identifies the prime numbers up to 11, afterwards it claims everything to be a non-prime number. Everything above 42 even causes an overflow error, because 42!² is bigger than 10¹⁰⁰. So the check for 9 is actually the only one within the working range that differs from a check for even/odd numbers.


Alternatively, this formula can be used in the command line calculator "qalc" that is often preinstalled on Linux and in the GUI equivalent "Qalculate":

(42−1)!²%42 returns 0.
(13-1)!²%13 returns 1.
(100000007-1)!²%100000007 takes a while and then returns 1.

But I wouldn't call inserting that number there a "programming language". Variables could be defined before the execution and then used in the calculation, which might make that a valid solution, but I haven't played around with that much yet.