Tripartite Palindromic Partition of Integer (HP 50g) Challenge
|
02-19-2023, 09:49 PM
(This post was last modified: 03-05-2023 01:55 PM by peruna.)
Post: #14
|
|||
|
|||
RE: Tripartite Palindromic Partition of Integer (HP 50g) Challenge
Some programs involving palindromic numbers. (Note: ± is char 177 from the CHARS menu.)
'P?' # 2979h 22. Test if number is palindromic Code: « →STR DUP ± == 1331 P? → 1 1332 P? → 0 '±' # 7F80h 48. Reverse string or list Code: « DUP SIZE { DUP HEAD SWAP TAIL ± SWAP + } IFT "1234" ± → "4321" 'LP' # DDF0h 24.5 Make long palindrome Code: « →STR DUP ± + OBJ→ 1234 LP → 12344321 'SP' # 366Dh 30. Make short palindrome Code: « →STR DUP ± TAIL + OBJ→ 1234 SP → 1234321 '→P' # 5274h 85. Make starting palindrome Code: « DUP →STR DUP SIZE 2 IDIV2 DUP 4. ROLLD + 1. SWAP SUB SWAP :: SP :: LP IFTE 1728 →P → 1661 1728 153 →P → 151 153 'P↓' # B893h 133.5 Next smaller palindrome Code: « DUP XPON { DUP 1 - DUP XPON ALOG ≠ { →STR DUP SIZE 2 IDIV2 DUP 4. ROLLD + 1001 P↓ → 999 1771 P↓ → 1661 2002 P↓ → 1991 'P2' # 3947h 94. Check if number is sum of 2 palindromes Code: « →P 1553 P2 → { 1551 2 } 1771 P2 → 0. 4354 P2 → 0. 4355 P2 → { 4224 131 } 'P3' # C894h 88.5 Integer as sum of 3 positive palindromes [code]« 3 OVER > :: NOT {→P DO DUP2 - P2 DUP TYPE :: + { SWAP P↓ } IFTE UNTIL SWAP END } IFTE » 58194227 P3 → { 58188185 5335 707 } 808182838485868788 P3 → { 80812837738281808 744232447 3354533 } 11 P3 → {9 1 1 } |
|||
« Next Oldest | Next Newest »
|
User(s) browsing this thread: