The following warnings occurred:
Warning [2] count(): Parameter must be an array or an object that implements Countable - Line: 795 - File: showthread.php PHP 7.4.33 (FreeBSD)
File Line Function
/showthread.php 795 errorHandler->error





Post Reply 
Mini-challenge: MAX(factors of 2 or 5)
01-16-2018, 10:52 PM
Post: #1
Mini-challenge: MAX(factors of 2 or 5)
This mini-challenge is really is a cry for help improving a painfully inelegant-looking routine.

Suppose an integer X contains prime factors of 2^Y and 5^Z. What is MAX(Y,Z)?

Example: 2000 = 2^4 * 5^3, so Y=4 and Z=3, so MAX(Y,Z)=4.

The following ugly HP 50g routine takes X as its input and outputs MAX(Y,Z):

Code:
<< FACTORS DUPDUP
IF 2 POS DUP THEN 1. + GET ELSE NIP END SWAP DUP
IF 5 POS DUP THEN 1. + GET ELSE NIP END MAX >>

Input: 31250 (which = 2*5^6)
Output: 6 in 0.114 seconds

Input: 2^555
Output: 555 in 0.97 seconds

Input: 3^175
Output: 0 in 0.87 seconds

It works and it's fast enough, but it looks like a brutally hamfisted approach. It hurts my eyes. There MUST be a simple and elegant way of doing this. Thanks for any insights you can share!

<0|ΙΈ|0>
-Joe-
Visit this user's website Find all posts by this user
Quote this message in a reply
Post Reply 


Messages In This Thread
Mini-challenge: MAX(factors of 2 or 5) - Joe Horn - 01-16-2018 10:52 PM



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