idivis inWP34s
|
11-28-2015, 12:14 AM
(This post was last modified: 11-28-2015 05:43 AM by Thomas Klemm.)
Post: #7
|
|||
|
|||
RE: idivis inWP34s
We can write a little function in Python:
Code: def idivis(n): Code: >>> idivis(28) Yay, it works! So let's use the Python to FOCAL Compiler to translate it: Code: LBL "IDIVIS" We can remove a few RDN commands here and there and LBLs we don't really need. We have to replace MOD by RMDR and only use 3 letters for the label. And then we have to fix the AVIEW command as we want to display register 01 instead. Code: LBL'IDV' Next thing we can do is replace these lines Code: RCL 01 ; i Code: INC 01 ; i We can compare X directly with a register or 0. And then we notice that we don't really need to jump to label 01 to exit the program but can use RTN directly. Code: LBL'IDV' As you can see I've added a PSE instruction to wait a little between displaying the factors. We can get rid of the label using the BACK command. And let's use a fancy way to write the constant 0. Code: LBL'IDV' If we want to get rid of the registers and only use the stack we have to be careful as we modify it. Thus RCL Y can refer to i or n. And then we notice one of the drawbacks that the comparison function X≠0? doesn't consume the operand: we can't just return in the loop but have to clean up the stack. But since we have to do this in both cases we can just skip 2 lines. Just make sure to adjust the BACK command. Code: LBL'IDV' Cheers Thomas PS: Did you notice where I cheated a little? |
|||
« Next Oldest | Next Newest »
|
Messages In This Thread |
idivis inWP34s - ggauny@live.fr - 11-27-2015, 07:26 PM
RE: idivis inWP34s - Dieter - 11-27-2015, 08:24 PM
RE: idivis in WP 34S - walter b - 11-27-2015, 08:34 PM
RE: idivis inWP34s - Dieter - 11-27-2015, 08:53 PM
RE: idivis inWP34s - walter b - 11-27-2015, 10:27 PM
RE: idivis inWP34s - Dieter - 11-27-2015, 11:12 PM
RE: idivis inWP34s - Marcus von Cube - 11-28-2015, 11:14 AM
RE: idivis inWP34s - walter b - 11-28-2015, 12:01 PM
RE: idivis inWP34s - Thomas Klemm - 11-28-2015 12:14 AM
RE: idivis inWP34s - ggauny@live.fr - 11-28-2015, 06:30 AM
RE: idivis inWP34s - Dieter - 11-28-2015, 07:35 PM
RE: idivis inWP34s - ggauny@live.fr - 11-28-2015, 07:28 AM
RE: idivis inWP34s - Thomas Klemm - 11-28-2015, 11:25 AM
RE: idivis inWP34s - Didier Lachieze - 11-29-2015, 12:25 PM
RE: idivis inWP34s - ggauny@live.fr - 03-27-2016, 09:34 AM
RE: idivis inWP34s - ggauny@live.fr - 11-29-2015, 12:34 PM
RE: idivis inWP34s - ggauny@live.fr - 11-29-2015, 12:47 PM
RE: idivis inWP34s - Paul Dale - 03-27-2016, 10:26 AM
RE: idivis inWP34s - ggauny@live.fr - 03-27-2016, 10:43 AM
RE: idivis inWP34s - Didier Lachieze - 03-27-2016, 11:17 AM
RE: idivis inWP34s - Paul Dale - 03-27-2016, 11:14 AM
RE: idivis inWP34s - ggauny@live.fr - 03-27-2016, 12:00 PM
|
User(s) browsing this thread: 1 Guest(s)