Find LCM of 2 numbers without using GCD
|
08-01-2018, 08:15 PM
(This post was last modified: 08-01-2018 08:22 PM by Dieter.)
Post: #21
|
|||
|
|||
RE: Find LCM of 2 numbers without using GCD
Albert Chan wrote:
Quote:Sorry if it look stupid ... This is my first HP-12C program (only HP calc I own) Great – I love stack-only programs. ;-) For the record: here's a complete program that directly returns the GCD. The initial lines have been optimized. Code: 01 ENTER Dieter |
|||
08-01-2018, 09:04 PM
(This post was last modified: 08-01-2018 11:28 PM by Albert Chan.)
Post: #22
|
|||
|
|||
RE: Find LCM of 2 numbers without using GCD
uh, did it miss a subtract on line 3 ? looks like Y pushed away
when X and Y are both negative, the mod will stay negative all the way to the end I still like the mod, and would like program to pull double duty. How about it only does the loop only if X was negative ? so, this will get the gcd 54321 CHS Enter 12345 CHS R/S --> -3 that will be awesome ... Edit: my mistake, it was CLX not LstX. That was a nice trick ... |
|||
08-02-2018, 01:25 AM
(This post was last modified: 08-02-2018 06:58 PM by Albert Chan.)
Post: #23
|
|||
|
|||
RE: Find LCM of 2 numbers without using GCD
Here is my revised Mod/Gcd program for HP-12C
If Y, X both negative, it does Gcd(Y, X) If Y, X both positive, it does Mod(Y, X) If X = 0, return Y Example: 54321 CHS Enter 12345 CHS R/S => -3 ; Gcd 54321 Enter 12345 R/S => 4941 ; Mod(54321, 12345) R/S => 2463 ; Mod(12345, 4941) R/S => 15 ; Mod(4941, 2463) R/S => 3 ; Mod(2463, 15) R/S => 0 ; Mod(15, 3) R/S => 3 ; Gcd Code: 01 X = 0 |
|||
08-02-2018, 01:03 PM
Post: #24
|
|||
|
|||
RE: Find LCM of 2 numbers without using GCD
Albert Chan wrote:
Quote:Here is my revised Mod/Gcd program for HP-12C Fine, so this can be used for calculating the GCD as well as a simple MOD. However, I'd suggest you use the common function names in your listings:
Dieter |
|||
08-02-2018, 01:26 PM
Post: #25
|
|||
|
|||
RE: Find LCM of 2 numbers without using GCD
Hi, Dieter.
Your suggestions added. Code fixed. BTW, I was trying to use your code as template, but this forum Quote not working. Where can I learn how to add non-ascii characters in post ? |
|||
08-02-2018, 03:52 PM
Post: #26
|
|||
|
|||
RE: Find LCM of 2 numbers without using GCD
(08-02-2018 01:26 PM)Albert Chan Wrote: BTW, I was trying to use your code as template, but this forum Quote not working. What do you mean? When I press the Quote button below a post, a Post a New Reply window opens, with the original post surrounded by quote and /quote tags. Does it behave differently in your browser? (08-02-2018 01:26 PM)Albert Chan Wrote: Where can I learn how to add non-ascii characters in post ? My preferred way is to type the characters in Free42 (i.e. enter them into the alpha register using the ALPHA menu) and then use Copy and Paste to copy them to the Post text box. Free42 and the Forum are both support Unicode, so that should work smoothly, but of course it is limited to the HP-42S character set. For really unusual characters, I google them by name and then use the first hit from http://www.fileformat.info, and copy and paste from there. For example, google "unicode black right pointing triangle" gets you the hit https://www.fileformat.info/info/unicode.../index.htm; scroll down to the Java Data section, and you can copy the character from string.toUpperCase() or string.toLowerCase(). |
|||
08-02-2018, 04:35 PM
Post: #27
|
|||
|
|||
RE: Find LCM of 2 numbers without using GCD
(08-02-2018 03:52 PM)Thomas Okken Wrote:(08-02-2018 01:26 PM)Albert Chan Wrote: BTW, I was trying to use your code as template, but this forum Quote not working. There was a problem with the "Quote" button and other forum functions. Obviously this has been fixed now (around noon UTC today it still was not working). Take a look at the "Forum Issues and Administration" forum for more details. (08-02-2018 03:52 PM)Thomas Okken Wrote:(08-02-2018 01:26 PM)Albert Chan Wrote: Where can I learn how to add non-ascii characters in post ? My method is a bit simpler: I have a textfile here that includes all the special characters that I often use: arrows, mathematical symbols, greek characters and some more. To prepare such a file I simply copied these characters from the Windows "charmap" utility. Service: here are some characters that you may directly copy into a textfile for later use. Code: ± Dieter |
|||
08-02-2018, 05:48 PM
Post: #28
|
|||
|
|||
RE: Find LCM of 2 numbers without using GCD
Thanks Thomas Okken,
Quote is working now :-) Thanks Dieter, charmap chars helps, as I am typing from an ipad. just discovered ipad keyboard have hidden gems, if I press the key a bit longer this pops out when a is pressed: æ ã å ā à á â ä |
|||
08-02-2018, 05:54 PM
Post: #29
|
|||
|
|||
RE: Find LCM of 2 numbers without using GCD
(08-02-2018 05:48 PM)Albert Chan Wrote: [...] typing from an ipad. You can also add additional keyboards, under Settings -> General -> Keyboard -> Keyboards. I keep a Greek keyboard in there, so I can type Greek letters in mathematical equations without having to copy and paste. (If you have multiple keyboards selected, you can switch between them by tapping or long-pressing the "globe" key left of the space bar.) |
|||
« Next Oldest | Next Newest »
|
User(s) browsing this thread: 2 Guest(s)