Post Reply 
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:

Variables:
  K1: A (store 0 in K1 before writing the program into the calculator)
  K2: B (store 32 in K2 before writing the program into the calculator)
  K4: Year (D from Date - store 2017 in K1 before writing the program into the calculator)

LRN (MODE EXP)
------
  1
  Kin-2    // counting from 31 to 0
  Kout4
  -
  Kout2
  x^2
  =
  SQRT
  -
  RND
  Kin1
  =
  x>0?
  alpha A
  alpha B
  x>0?
------
LRN (MODE .)

FIX 0 for running
This won't works, because of rounding.

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:

LRN (MODE EXP)
------
  1
  Kin-2    // counting from 31 to 0
  Kout4
  -
  Kout2
  x^2
  =
  SQRT
  -
  MODE 1    // BASE-N mode makes integer part of the number
  MODE 0    // and back to COMP mode
  Kin1      // we need to store 'A' - the algebraic stack stores the substraction three steps earlier
  =
  x>0?
  alpha A
  alpha B
  x>0?
------
LRN (MODE .)

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:

LRN (MODE EXP)
------
  1
  Kin-2    // counting from 31 to 0
  Kout2    // preparing B<0 condition
  +        // we need to keep B=0 case for the Years which are square numbers, like Year 2025=45^2+0^2
  1
  =
  ln       // let's generate an error if B<0 and the program stops
  Kout4
  -
  Kout2
  x^2
  =
  SQRT
  -
  MODE 1    // BASE-N mode makes integer part of the number
  MODE 0    // and back to COMP mode
  Kin1      // we need to store 'A' - the algebraic stack stores the substraction three steps earlier
  =
  x>0?
  alpha A
  alpha B
  x>0?
------
LRN (MODE .)

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
Find all posts by this user
Quote this message in a reply
Post Reply 


Messages In This Thread
Integer part and other little tricks (CASIO fx-50F) - Csaba Tizedes - 02-14-2017 11:53 PM



User(s) browsing this thread: 1 Guest(s)