Post Reply 
Mini-challenge: MAX(factors of 2 or 5)
01-17-2018, 01:36 AM
Post: #2
RE: Mini-challenge: MAX(factors of 2 or 5)
The first thing that comes to mind is that the FACTORS output looks made for the SysRPL command Lookup. (For those not familiar with it, the command compares a given object with the first, third, etc. entry in a given list, returning the object after the first match.) Then maybe MAP or something similar to get rid of the code duplication... but that has some stack protection, so the FACTORS output has to be smuggled inside somehow. Let's use >HCOMP for that, a list doesn't change when eval'ed.
Resulting code:
Code:
::
  xFACTORS
  { Z2_ Z5_ }
  ' ::
    ' EQUAL SWAP Lookup
    NOT_IT DROP%0_
  ;
  ROT >HCOMP
  FPTR2 ^SECOEXEC (this is xMAP's internal part)
  INCOMPDROP %MAX
;
The speed is pretty much the same as your code, the biggest time sink is most likely FACTORS anyway. 59 bytes, checksum #FF3E.
Find all posts by this user
Quote this message in a reply
Post Reply 


Messages In This Thread
RE: Mini-challenge: MAX(factors of 2 or 5) - 3298 - 01-17-2018 01:36 AM



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