EduCALC HP48 Programming Class Student Challenges Simple but interesting programming challenges are generated during the HP48 Programming Class held almost every Friday at EduCALC. (Some of them are generated, and solved, over breakfast afterwards at Denny's, like in the old PPC days!) I know you'll enjoy tackling one or more of these recent brain teasers. The "winner" of a challenge is sometimes the smallest program (fewest bytes) and sometimes the fastest (fewest ticks). Size is calculated with program delimiters but without the name. Speed is timed with a modified version of Jim Donnelly's XTIME that subtracts its own overhead. Only native User RPL is allowed, unless you're a total hacker and can't help yourself. SYSEVAL *is* allowed. The class's winning solutions follow the challenges, but don't peek until you've written your own! Have fun. -jkh- ----- Challenge #1: Write a program that sorts levels 1 & 2 into order (the greater number going on level 2). Winner: size. Challenge #2: Write a program that outputs all the Friday the 13ths of any given year between 1583 and 9999. Winner: speed. Challenge #3: Write a program that takes a list of variables and calculates the differences between all the elements, then does that again, and again, until only a single algebraic remains, which is then returned as the output. Winner: speed. Challenge #4: Write a program that inputs a 7-letter (or mixture of letters and digits) telephone number mnemonic (like "COLLECT" in the new 1-800-COLLECT phone number, or "4ABUICK" in the Buick advertisements), and outputs it as a normal phone number, with a radix after the first three digits (like 227.7387). Assume "Q" and "Z" are a 1. Winner: size. Challenge #5: Write an HP48 ** G/GX ** program that inputs a date in standard format (like 8.191955) and outputs the *full* English day of week, like "Friday". Winner: size. Challenge #6: Write a program that inputs a string and outputs the same string with the case of all the letters toggled (e.g. "This Is a Test" becomes "tHIS iS A tEST") and no other changes made. Accented letters need not be handled. Winner: size. ----- Winning solutions. Don't peek until you've tried! Post your solution if you beat one listed here, and we'll discuss your solution at the next class. #1: ---------- \<< MAX LASTARG MIN \>> (17.5 bytes) but that assumes that LASTARG is enabled; if you think that makes it a bad solution, then try this: \<< DUP2 < { SWAP } IFT \>> (25 bytes). #2: ---------- %%HP: T(3)F(.); \<< 1000000 / 1.13 + 13 FOR d 6.133 d DDAYS 7 MOD NOT { d } IFT NEXT \>> @ takes 0.146 seconds for 1998 on a GX. #3: ---------- %%HP: T(3); \<< OBJ\-> 1 - \-> n \<< 0 0 n FOR j n 2 + j - ROLL n j COMB SWAP * -1 n j - ^ * + NEXT \>> \>> @ takes 1 second to process { A B C D E F G H I J } #4: ---------- %%HP: T(3); \<< 0 1 7 FOR j 10 * " QZ1ABC2DEF3GHI4JKL5MNO6PRS7TUV8WXY9" 3 PICK j DUP SUB POS 4 / CEIL + NEXT SWAP DROP 1 % 1 % \>> @ 123 bytes #5: ---------- %%HP: T(3)F(.); \<< 1.0119 SWAP DDAYS 7 MOD # BC15h + # 5A03h SYSEVAL # 4D87h SYSEVAL \>> @ 77 bytes #6: ---------- %%HP: T(3); \<< "" 1 3 PICK SIZE FOR x OVER x DUP SUB DUP DUP2 "A" \>= SWAP "Z" \<= AND SWAP "a" \>= ROT "z" \<= AND OR 32 * CHR + NEXT XOR \>> @ 121 bytes