Integer part and other little tricks (CASIO fx-50F)
|
02-14-2017, 11:53 PM
Post: #1
|
|||
|
|||
Integer part and other little tricks (CASIO fx-50F)
I found a little quiz on a Hungarian forum and I found my earlier solution to CASIO fx-602P. I decided that I will solve this tiny problem on my 50F - I did not think that it will cause many trouble for me.
The quiz: It is possible to add two square number to get the number of this year? A^2+B^2=2017 --> A,B=? OK, this is not a big deal, let's go from B=0 to B=INT(SQRT(2017/2))=31, and calculate A=SQRT(2017-B^2) and check A==INT(A) or not. If yes, we found a solution. How we can check a number is an integer or not? It is simple: if the fractional part of the number is greater than zero, the number is not an integer. This is OK for this calculator because on the 50F only two condition is available: x>0 and x<=M. The problem is that, on the 50F has no FRAC() function, but we can calculate it as FRAC(A)=A-INT(A), but on the 50F has no INT() also. First idea - FIX 0 and RND This is the obvious solution: use the FIX function and then round the number, but when you select FIX 0, the calculator rounds the display and you can not to check the fractional part of the 'A' is positive or not: Code:
After few trying with FIX and RND I can see that this is not a solution. I need something which use only integers. Maybe the BASE-N mode? Yesss...! Third idea (second doesn't count) - INT() with BASE-N Code:
Yes, slightly imperfect, just try it: if we has no solution this will never stops, because the program never checks the value of B>0? Unfortunately on the 50F if a condition is true the program restarted on the first step, so we need to check B<0 and stop if this is true, but if B>=0, we need to run the program. Fourth idea - how to make a condition with true AND false Code:
This is works as I want and stops with an error if you have no solution or you have a solution but the Year is not a square number, or stops with 0 on the display if the Year is a square number. Thanks for reading - I'm waiting for similar little tricks which are really useful during programming on a very limited memory. Csaba |
|||
02-15-2017, 02:52 PM
(This post was last modified: 02-15-2017 04:39 PM by xerxes.)
Post: #2
|
|||
|
|||
RE: Integer part and other little tricks (CASIO fx-50F)
Some of the CASIOs with this type of keystroke programming have no BASE-N mode, so here a solution for the FX-180P in 17 steps:
Code: 1 Input: Year in K1 and zero in K2 Output: A and B in K2 and K3 The program stops with 0, if a solution is found or gives an error, if not. Calculator Benchmark |
|||
02-15-2017, 08:45 PM
Post: #3
|
|||
|
|||
RE: Integer part and other little tricks (CASIO fx-50F)
OK, the two solution is not comparable, because you don't check the IP of the square root=0, you check the FP>0. This is works on the 50F also, but you can feel that FIX0+RND is works but this is a cheating
BTW checking the end of the loop with only one x>0 is more elegant and you do not need to decide the max value of loop counter - but you will get all the solutions twice. Thanks for this elegant, simplest and more portable code. If I collect my 50F codes into a short document can I share this version with your nick?! Have you got any other little code for these blind programmable calcs?! Csaba |
|||
02-16-2017, 09:00 AM
Post: #4
|
|||
|
|||
RE: Integer part and other little tricks (CASIO fx-50F)
I have most of the casios of that generation. i never understood why someone would want not a do-if-true or even skip-if-true, but a restart-if-true condition... combined with a very low number of storable steps and only two possible conditions (x>0 and x<=M), that 50f was a very quirky device.
|
|||
02-16-2017, 02:46 PM
Post: #5
|
|||
|
|||
RE: Integer part and other little tricks (CASIO fx-50F)
(02-15-2017 08:45 PM)Csaba Tizedes Wrote: OK, the two solution is not comparable, because you don't check the IP of the square root=0, you check the FP>0. This is works on the 50F also, but you can feel that FIX0+RND is works but this is a cheating The logic in the FX-180P version is, if there is a difference between X and ROUND(X), that saves one step. The combination of FIX0, RND und NORM is very useful and it can be seen as a programming trick, because it is not mentioned in any CASIO manual. A more obvious trick is using x^2 and SQRT, due to the missing ABS. A size optimized program for the greatest common divisor, that makes use of it: Code: 01 x<->y Usage example: 861 - - 615 P1 (02-15-2017 08:45 PM)Csaba Tizedes Wrote: Have you got any other little code for these blind programmable calcs?! Another one is Viète's formula on the FX-180P: Code: P1: Usage example: 10 P1 P2 or Fun with the Casio fx-180p / fx-3600p (02-15-2017 08:45 PM)Csaba Tizedes Wrote: If I collect my 50F codes into a short document can I share this version with your nick?! Yes,of course. Nice to see that you like the programming on this very limited devices. Calculator Benchmark |
|||
02-19-2017, 04:20 PM
Post: #6
|
|||
|
|||
RE: Integer part and other little tricks (CASIO fx-50F)
(02-16-2017 02:46 PM)xerxes Wrote: A size optimized program for the greatest common divisor, that makes use of it: Hello Xerxes! Please check your GCD routine above - is it works, are you sure?! Pls. clarify the Usage again! I need something similar, please read this: Inverse Fibonacci Sums (MoHPC). Your opinion?! Thanks! Csaba |
|||
02-19-2017, 05:27 PM
Post: #7
|
|||
|
|||
RE: Integer part and other little tricks (CASIO fx-50F)
Hi Csaba,
I've checked the code and it works like it should. If I type in "861 minus minus 615 P1", the output is 123. The trick is to use a pending operator in the program loop, if possible. I'll check the Inverse Fibonacci Sums on the FX-180P. Calculator Benchmark |
|||
02-20-2017, 09:01 AM
Post: #8
|
|||
|
|||
RE: Integer part and other little tricks (CASIO fx-50F)
(02-19-2017 05:27 PM)xerxes Wrote: "861 minus minus 615 P1", the output is 123.Uhh..., I have tested and that was a flash in my mind, when I pressed two times the [-] minus key and the 'K - Constant calculation' is lit on the LCD. I need to study this little program step by step... (02-19-2017 05:27 PM)xerxes Wrote: I'll check the Inverse Fibonacci Sums on the FX-180P.Thanks! Csaba |
|||
02-20-2017, 01:47 PM
Post: #9
|
|||
|
|||
RE: Integer part and other little tricks (CASIO fx-50F)
Another way is using the K vars, instead of the pending operator:
Code: 01 Kin-1 Usage example: 861 Kin1 615 P1 Calculator Benchmark |
|||
03-16-2017, 04:11 PM
(This post was last modified: 03-17-2017 01:08 PM by xerxes.)
Post: #10
|
|||
|
|||
RE: Integer part and other little tricks (CASIO fx-50F)
An interesting exercise from a french pocket and calculator forum is the Collatz conjecture, thats pretty simple to implement normally.
First I was not sure, if it's also possible on the very limited FX-180P, but it was. The real challenge however, was to reduce the steps to 29 bytes or less, to fit in the FX-50F too: Code: 01 2 Usage example: KAC Min 13 Kin1 P1 program stops with error Kout3 -> 9 (length) MR -> 40 (maximum) Calculator Benchmark |
|||
03-17-2017, 11:36 AM
Post: #11
|
|||
|
|||
RE: Integer part and other little tricks (CASIO fx-50F)
(03-16-2017 04:11 PM)xerxes Wrote: from a french pocket and calculator forum Thanks, can you share the link here?! (03-16-2017 04:11 PM)xerxes Wrote: Collatz conjecture, ... to reduce the steps to 29 bytes or less, to fit in the FX-50F: OK, I will check it - unfortunately RTN is not available on fx-50F Csaba |
|||
03-17-2017, 01:33 PM
Post: #12
|
|||
|
|||
RE: Integer part and other little tricks (CASIO fx-50F)
Hi Csaba,
I was able to optimize a litte for speed and size with 27 bytes now. You can replace the RTN with x>0. Can you please check the execution time on the FX-50F for 27? The FX-3900PV needs 11.3 seconds. The link to the discussion: http://www.silicium.org/forum/viewtopic....46&t=36995 Calculator Benchmark |
|||
03-17-2017, 11:02 PM
(This post was last modified: 03-18-2017 07:51 AM by Csaba Tizedes.)
Post: #13
|
|||
|
|||
RE: Integer part and other little tricks (CASIO fx-50F)
[edit]3400P added!
(03-17-2017 01:33 PM)xerxes Wrote: Can you please check the execution time on the FX-50F for 27? The FX-3900PV needs 11.3 seconds. The results: Code: CASIO fx-10F: 7.30s / 7.29s / 7.29s --> aver= 7.3s Thanks for the link! Csaba |
|||
03-18-2017, 12:50 PM
Post: #14
|
|||
|
|||
RE: Integer part and other little tricks (CASIO fx-50F)
Thank you for the results. If you like this CASIO series, you will love the FX-3900Pv or the FX-180P Plus.
These are much faster and you have 300 steps in 4 areas. Additionally they offer a nice editing mode, so it's not necessary to program in the blind any more. I assume, that your results are for 13 and not 27. If so, the FX-3900Pv needs about 0.9 seconds. Calculator Benchmark |
|||
03-20-2017, 09:43 PM
Post: #15
|
|||
|
|||
RE: Integer part and other little tricks (CASIO fx-50F)
(03-18-2017 12:50 PM)xerxes Wrote: Thank you for the results. If you like this CASIO series, you will love the FX-3900Pv or the FX-180P Plus.Yes, this was the 13 Kin1. The 27 was a little misunderstood, because the length of the program decreased to 27 steps and the example was 13. I'll check it with 27 Kin1 also. Csaba |
|||
03-23-2017, 09:22 AM
Post: #16
|
|||
|
|||
RE: Integer part and other little tricks (CASIO fx-50F)
On fx-50F:
Code: [KAC] [Min] 27 [Kin] 1 [P1] Csaba |
|||
03-06-2019, 10:22 PM
Post: #17
|
|||
|
|||
RE: Integer part and other little tricks (CASIO fx-50F)
Uhh, this was WTF - but I found why SD mode is required... Check in YT and read my comment below the video.
Csaba |
|||
« Next Oldest | Next Newest »
|
User(s) browsing this thread: 3 Guest(s)