HP 50g: Programming Problem: Integer Partition in Palindromic Integers - Gerald H - 01-26-2018 03:50 PM
Every integer can be written as the sum of palindromic integers, eg
542 = 535 + 7
& in fact 49 palindromes are sufficient to express any integer, as proven here
https://arxiv.org/pdf/1508.04721.pdf
The task I'm interested in is producing a stand alone User RPL programme for the 50g that will decompose any positive integer into a sum of palindromes, the fewer the better.
For example the number
407374883553280653444058251937
can be decomposed in 120 palindromes:
Code:
:120:{
99999999999999999999999999999
99999999999999999999999999999
99999999999999999999999999999
99999999999999999999999999999
999999999999999999999999999
999999999999999999999999999
999999999999999999999999999
999999999999999999999999999
999999999999999999999999999
999999999999999999999999999
999999999999999999999999999
99999999999999999999999999
99999999999999999999999999
99999999999999999999999999
9999999999999999999999999
9999999999999999999999999
9999999999999999999999999
9999999999999999999999999
9999999999999999999999999
9999999999999999999999999
9999999999999999999999999
999999999999999999999999
999999999999999999999999
999999999999999999999999
999999999999999999999999
99999999999999999999999
99999999999999999999999
99999999999999999999999
99999999999999999999999
99999999999999999999999
99999999999999999999999
99999999999999999999999
99999999999999999999999
9999999999999999999999
9999999999999999999999
9999999999999999999999
9999999999999999999999
9999999999999999999999
9999999999999999999999
9999999999999999999999
9999999999999999999999
999999999999999999999
999999999999999999999
999999999999999999999
99999999999999999999
99999999999999999999
99999999999999999999
99999999999999999999
99999999999999999999
9999999999999999999
9999999999999999999
9999999999999999999
9999999999999999999
9999999999999999999
999999999999999999
999999999999999999
999999999999999999
99999999999999999
99999999999999999
9999999999999999
9999999999999999
9999999999999999
9999999999999999
9999999999999999
9999999999999999
9999999999999999
9999999999999999
99999999999999
99999999999999
99999999999999
99999999999999
99999999999999
99999999999999
9999999999999
9999999999999
9999999999999
9999999999999
9999999999999
999999999999
999999999999
999999999999
99999999999
99999999999
99999999999
99999999999
9999999999 9999999999
9999999999 9999999999
999999999 999999999
999999999 999999999
9999999 9999999
9999999 9999999
9999999 999999 999999
999999 999999 999999
999999 999999 999999
99999 99999 9999 9999
9999 9999 9999 999
999 22 11 9 9 1 }
& in 6
Code:
:6:{
407374883553280082355388473704
571088666880175
2897982 66 9 1 }
& in 5
Code:
:5:{
407374883553280082355388473704
571088646880175
22888822 9229 7 }
which may be minimal.
The programme should produce a list ordered by decreasing magnitude & tagged with the number of elements.
Smaller & faster programmes are desirable but the critical characteristic is lowest number of elements in the decomposition.
As a standard test for the programme I suggest input of
13^1313
a 1,463 digit integer, correct decompositions being the target & least number of elements deciding the winner.
RE: HP 50g: Programming Problem: Integer Partition in Palindromic Integers - Gerald H - 02-01-2018 11:20 AM
Edited to "39g programme" from "38G programme" - sorry for the error.
Well, not much progress made on this, unless members are keeping their solutions secret.
Meanwhile I have produced a complete solution for the 39g, although I do not claim that the partitions share the characteristic of having a minimum number of elements in the respective palindromic partition.
The 39g programme has one sub programme, N2DS, which for natural number input Ans produces a list of digits in list L2, eg for input
23405
L2 will contain
{5,0,4,3,2}
which may in itself be useful.
Code:
N2DS
Ans►T:
CLRVAR L2:
FOR I=1 TO INT(LOG(T)+1) STEP 1;
T MOD 10:
CONCAT(L2,{Ans})►L2:
INT(T/10)►T:
END:
The main programme, P24U, which for natural number input Ans produces a list of the palindromic partition members in descending order in list L1. eg For input
987654321678
L1 will contain
Code:
{899999999998,79999999997,6999999996,599999995,49999994,3999993,299992,19991,999,595,66,9,8,8,7,6,5,5,4,4,3,2,1}
Code:
P24U
Ans►N:
IF Ans<10
THEN
{N}►L1:
ELSE
N:
RUN N2DS:
{L2(1)}►L1:
SUB L2;L2;2;12:
FOR I=1 TO SIZE(L2) STEP 1;
L2(I):
Ans►H:
IF H
THEN
IF H>1
THEN
11-H:
END:
CONCAT(L1,{Ans,10^I*H-Ans})►L1:
END:
END:
END:
REVERSE(SORT(L1))►L1:
As the 39g is limited to 12 digit integers, the above programme solves the problem completely on that machine.
However, as the algorithm produces two elements of the partition for each digit, the method becomes impractical on the 49G for , say, 6,000 digit numbers.
I again encourage members to apply themselves to this interesting, if unimportant, problem.
RE: HP 50g: Programming Problem: Integer Partition in Palindromic Integers - Gerald H - 02-02-2018 08:21 AM
A slightly modified version of the programme to remove the occurrence of 0 in the partition if the input ends in 0:
Code:
P24U
Ans►N:
IF Ans<10
THEN
{N}►L1:
ELSE
N:
RUN N2DS:
L2(1):
IF Ans
THEN
{Ans}►L1:
ELSE
CLRVAR L1:
END:
SUB L2;L2;2;12:
FOR I=1 TO SIZE(L2) STEP 1;
L2(I):
Ans►H:
IF H
THEN
IF H>1
THEN
11-H:
END:
CONCAT(L1,{Ans,10^I*H-Ans})►L1:
END:
END:
END:
REVERSE(SORT(L1))►L1:
RE: HP 50g: Programming Problem: Integer Partition in Palindromic Integers - Gerald H - 02-04-2018 08:13 AM
Here a corrected version for the 38G:
Code:
N2DS
Ans►T:
SYSEVAL 532278:
FOR I=1 TO INT(LOG(T)+1) STEP 1;
T MOD 10:
CONCAT(L2,{Ans})►L2:
INT(T/10)►T:
END:
P24U
Ans►N:
IF Ans<10
THEN
{N}►L1:
ELSE
N:
RUN N2DS:
L2(1):
IF Ans
THEN
{Ans}►L1:
ELSE
SYSEVAL 532268:
END:
SUB L2;L2;2;12:
FOR I=1 TO SIZE(L2) STEP 1;
L2(I):
Ans►H:
IF H
THEN
IF H>1
THEN
11-H:
END:
CONCAT(L1,{Ans,10^I*H-Ans})►L1:
END:
END:
END:
REVERSE(SORT(L1))►L1:
RE: HP 50g: Programming Problem: Integer Partition in Palindromic Integers - Juan14 - 02-05-2018 12:22 AM
This program returns the Palindromic Integers of an integer's partition to the stack. The idea is simple, but the program got somehow complicated.
«
WHILE DUP 10 >
REPEAT
DUP →STR DUPDUP SIZE 2 / SWAP 1 PICK3 SUB
DUPDUP 1 5 PICK FLOOR SUB SREV +
4 ROLL OVER <
{ DROP DUP OBJ→ 1 - →STR DUP ROT SIZE SWAP SIZE
‹ -.5 * ROT + OVER 1 ROT FLOOR SUB SREV + }
{ NIP NIP } IFTE OBJ→ SWAP OVER -
END DUP 10 == { DROP 9 1} IFT
»
RE: HP 50g: Programming Problem: Integer Partition in Palindromic Integers - Gerald H - 02-05-2018 06:03 AM
Very nice & short, Juan14, well done!
& the number of elements in the partition is at most log2(SIZE(N)), so a 6,000 digit number requires about 12 palindromes, sadly the programme does not work correctly for all 6,000 digit numbers.
RE: HP 50g: Programming Problem: Integer Partition in Palindromic Integers - Gerald H - 02-05-2018 06:22 AM
Your programme, Juan14, works correctly for 13^1313 but not for the 6,000 digit number
Code:
668198125478294158910366586815548046466164478727862555826704455704418886847236053799016108003756517340227007193843219028656970976373874455727196843116706375052199239667522851896442043515465907397273648461935739704478199943218426705969942235257401744714720022737847016166580492233397131969116917288306140472383198752577990692700198497236330156353925076218807377030763724449363780675399365191167476169582818053343351137655276699778055322226035412321402822796233524437885844787133529911477653623327402902741552130823845142361524831430264356748988343250998688669161263344972666859723003039823015196359813329339690077780617656841850940344919334019421035083624243355546620757187435600466389666990363417499401360899828287607335669726440353875187096561026914473983983534761826735072045358790315646491636936152856919017054578117826469134909002800612633256328067256466736936238197585549566008406917733980492004752909340316527394417311071086756506579045704238946939409788312392491561495625038585507818736506777378108348021334935236466772696809505524893229634923284107070596542491968651192695696249524403650755313439788728053447656294952816412454117636015843597566697158474977436106830825672580482395909146817031001108311402077516036802115024264461604241242509287730425483329533779574494651766891299876331933901772645861983579836818227130806924003714546218222563808705804221009511110330306812204844221558747846243269750021472775798982630622906376248313683675609587650152860455630716344049472503213237525279327817978675277798730646877895985307550544728222988608864276566024696634319019583966008732738114716425919524707516927735083438439217030892775252006139144190437583838609457355057812415897351844060074106035847428182000847599383628681419758435295022725301828502238187523222522747714466622081095472801468221667981184110629903731391171237577507329191937197273663088873296701640062546882138496337487179941654001888791324033168251061004441374172652807874502642263334216137965038267152483353636535902717437281043105257109355741923503795733842703667952889420273043745470540325137860946005956322899257844329271673089919157421732978253815984880718473138186583017267153585000799272139130305270439316546139496867672913997834059143273664316209093898597315617101856381676217102460227272202760591381928653767121266487661071879163786558383410937042288004727311791273435353384053585786992253382341007285157441257411847716724043322994843840483423771733091455518841971778031692277246882036347594753042801392719473234356393305206960289783665712579887171699116221670864655690158632964665790415576797550618555464794929668107690428755575626138835308735087403117312342389020064334211381438398798264042144488612377121549934776554167717369854823949181643485171299632176126680510764662698462884263494571157270474657229111465698802778908100791511078017956691541039179139452438174957207712983944369444216250680499673781437472886974066976607557037342528525540996018266040632343561743327816877426044144700192382491024228880021607008461339554618894705135455584329604436603867949112268995253280945946965183763539240822981395209769042278160297503459623857954997438274573219439838270898278275103373370068521598569943151432379987963575827868248621388270211244998752340622507594450108860010494856694120038083089966782322187932345658490540842132185015720327330489402451600874267735783839914235350768250475216930289347055549754012751936317175168084943376843398565516041887487493797545433105008184142419850146384716562797827828102741885659003276765035538870986936362739242439685843597623432632113926240909222331070988423051888529004872317341139995865552645669623651371139361828447794098175781964018857025228866734028011689784239895657160826672798910849886583121000418458994722289449035325149079860960104427619669632385622100919625266370104505566176838390754219015790739098526318985994394845655734441162742074756888135201695851791867083353438312448555434459857592727806967357657609171514242789894460484850725820045799828924120921699583846473485538734390733701050516875854392464583582926829715770830117414058391741199453983916626122236510679753495474313333243562266766028969989679708974259308470054613427594010412598701903639416659442067403105138713127939247028357769164541080526126381707823829422833230713841130330767101669769134403020880868443213871501318433621437153148623167638821637154132894150308493514603168552976761072852111445261581472522081011568762215427394016735715930198344391439075786064819395682805450706475189093352576774590489304244342581042736781783076125429266252205339099108289557487905058597622666209820165432934383156696998304819141299264102331699873964764056349745572235289179066831250254439313364369970747766505455218229325390412903200724968037365655515277713020075690454659662854869478934887814512177491806691725516847474682208008810782406239842821989333856643236023185823423799396633607518388514237592982163831765528762192925738446383046833491029510686315667187931098448810184414228897505474963545228229885349246796090680562199116116843122516759500394519108956166882364353795933460804116413194154779001775954655762344431725393989077089146005967783153379923613902096160005726853489532496375361026154197884296956466728574397903473433788873076799027751125533936573975082593790642547653999604512656821832777552241992616532233506166953517012666908151700857092722376951144682027392076493935608175606828135808285419397209569478359789058729384579673050182457747620866564980285719423037641462394000741879055737257148831233362234814586565665638213561896207565560083092217763654421897167132757809448916393738540863948206860287028904714303748831615017780556672384105644180441008917898168043267026831821678687274798458712383186117770407509577052033143265018331248173772872997761530908754833918121926162323352605087518681906137149107549111424038675165489157616434850425980871739339461837793278640551186371166396883274331252590754445175229336387754546897880241578277859436250322859781775347221081614862605278644138005897576544471598504605
while I would expect it to return
Code:
:12: {
668198125478294158910366586815548046466164478727862555826704455704418886847236053799016108003756517340227007193843219028656970976373874455727196843116706375052199239667522851896442043515465907397273648461935739704478199943218426705969942235257401744714720022737847016166580492233397131969116917288306140472383198752577990692700198497236330156353925076218807377030763724449363780675399365191167476169582818053343351137655276699778055322226035412321402822796233524437885844787133529911477653623327402902741552130823845142361524831430264356748988343250998688669161263344972666859723003039823015196359813329339690077780617656841850940344919334019421035083624243355546620757187435600466389666990363417499401360899828287607335669726440353875187096561026914473983983534761826735072045358790315646491636936152856919017054578117826469134909002800612633256328067256466736936238197585549566008406917733980492004752909340316527394417311071086756506579045704238946939409788312392491561495625038585507818736506777378108348021334935236466772696809505524893229634923284107070596542491968651192695696249524403650755313439788728053447656294952816412454117636015843597566697158474977436106830825672580482395909146817031001108311402077516036802115024264461604241242509287730425483329533779574494651766891299876331933901772645861983579836818227130806924003714546218222563808705804221009511110330306812204844221558747846243269750021472775798982630622906376248313683675609587650152860455630716344049472503213237525279327817978675277798730646877895985307550544728222988608864276566024696634319019583966008732738114716425919524707516927735083438439217030892775252006139144190437583838609457355057812415897351844060074106035847428182000847599383628681419758435295022725301828502238187523222522747714466622081095472801468221667981184110629903731391171237577507329191937197273663088873296701640062546882138496337487179941654001888791324033168251061004441374172652807874502642263334216137965038267152483353636535902717437281043105257109355741923503795733842703667952889420273043745470540325137860946005956322899257844329271673089919157421732978253815984880718473138186583017267153585000799272139130305270439316546139496867672913997834059143273664316209093898597315617101856381676217102460227272202760591381928653767121266487661071879163786558383410937042288004727311791273435353384053585786992253382341007285157441257411847716724043322994843840483423771733091455518841971778031692277246882036347594753042801392719473234356393305206960289783665712579887171699116221670864655690158632964665790415576797550618555464794929668107690428755575626138835308735087403117312342389020064334211381438398798264042144488612377121549934776554167717369854823949181643485171299632176126680510764662698462884263494571157270474657229111465698802778908100791511078017956691541039179139452438174957207712983944369444216250680499673781437472886974066976607557037342528525540996018266040632343561743327816877426044144700192382491024228880021607008461338833164800706120088822420194283291007441440624778618723347165343236040662810699045525825243730755706679660479688274734187376994086052612444963449389217702759471834254931971930145196659710870115197001809877208896564111922756474072751175494362488264896266467015086621671236992171584346181949328458963717761455677439945121773216884441240462897893834183112433460020983243213711304780537803538831626575557824096701866929497464555816055797675514097566469236851096556468076122611996171788975217566387982069602503393653432374917293108240357495743630288642772296130877179148815554190337177324384048348499223340427617748114752144751582700143283352299687585350483353534372197113727400882240739014383855687361978170166784662121767356829183195067202272722064201712676183658101716513795898390902613466372341950438799319276768694931645613934072503031931272997000585351762710385681831374817088489518352879237124751919980376172923448752998223659500649068731523045074547340372024988259766307248337597305329147553901752501340182734717209535636353384251762830569731612433362246205478708256271473144400160152861330423197888100456149971784733694831288645260046107692378880366372791739191923705775732171193137309926011481189766122864108274590180226664417747225222325781832205828103527220592534857914186826383995748000281824748530601470060448153798514218750553754906838385734091441931600252577298030712934834380537729615707425919524617411837237800669385910913436696420665672468806889222827445055703589598778646037897772576879718723972525732312305274940443617036554068251056785906576386313842673609226036289897577274120057962342648747855122448402218603033011115900122408507808365222812645417300429608031722818638975389168546277109339133678992198667156494475977335923384524037782905242142406164462420511208630615770204113801100130718641909593284085276528038601634779474851796665795348510636711454214618259492656744350827887934313557056304425942696596291156869194245695070701482329436922398425505908696277664632539433120843801873777605637818705585830526594165194293213887904939649832407540975605657680170113714493725613043909257400294089337719604800665945585791832639637664652760823652336216008200909431964628711875450710919658251639636194646513097853540270537628167435389389374419620165690781578353044627966533706782828998063104994714363099666983664006534781757026645553342426380530124910433919443049058148656716087770096933923318953691510328930300327958666279443362161966886899052343889847653462034138425163241548328031255147209204723326356774119925331787448588734425332697228204123214530622223550877996672556731153343350818285961674761191563993576087363944427367030773708812670529353651033632794891007296099775257891383274041603882719611969131793332294085661610748737220027417447104752532249969507624812349991874407937539164846372793709564515340244698158225766932991250573607611348691727554478373679079656820912348391700722043715657300801610997350632748688814407554407628555268727874461664640845518685663019851492874521891866
721454093999015366761909410153312860507671644216634557598781621947722876430123935869384525311522453617842979935583220810061280487166827393307448889057400613898234266666598013006235720277093460630866438744179373647133075995866549756418955746371745598590227104951461418729790150603586163709162081878414423560042887385367629234716433027272885946080052238334790454233687075635750769216209213104690599610260846674976469068051486071431696122031335538538947291323293678308593950801656039127524319271021207162532145217554561445446134199328347853993143989341630110032043182255434232714711204620823968841916655437934897554871506619556661685164441798488196613535503490856669620300610807543500881273305139310820740683101920999233061629811527222246762603084878148283920769517953118589723710017011799997762555127377519113985524084145125164453815954063121848655149089400031689075056760384607362273514204116313560528575058286934143974808743698156960102782719744819913144478700831786033521675783324394254698919583786233050550966333307340218039080331820096259984158396755167852913032943182510772225962083649349330297586212877093590482032334138701034448928151616091174247054802271220674996127907245466304757477093657523361816382920083178984314416108379156485498047590627402610313909738232243755582308019025132868161389122970716963560988999350108948888267882247294508416217051583002915975678730359917277064723851856814655092044144803590156216066330019284907695018410113596012506459978005650771599494573930736692716727364463727617296637039375494995177056500879954605210695311014810596709482910033660612651095308441440290556418658158327460772719953037876579519200385150712614805492742288762888849801053999889065369617079221983161868231520910803285557342232837909313016204726095740894584651973801614413489871380029283618163325756390774757403664542709721699476022172208450742471190616151829844430107831433230284095390778212685792033943946380269522277015281349230319258761557693851489952690028133080930812043703333669055050332687385919896452493423387576125330687138007874441319918447917287201069651896347808479341439682850575825065313611402415372263706483067650570986130004980941556848121360459518354461521541480425589311915773721555267799997110710017327985811359715967029382841878480306267642222725118926160332999029101386047028013931503372188005345708016003026966658094305535316691884897144461586166655916605178455798439734556619148869328026402117417232434552281340230011036143989341399358743823991431644544165455712541235261702120172913425721930656108059395803876392323192749835835533130221696134170684150860964679476648062016995096401312902612967057536570786332454097433832250080649588272720334617432926763583788240065324414878180261907361685306051097927814164159401722095895547173647559814657945668599570331746373971447834668036064390772027532600310895666662432898316004750988844703393728661784082160018022385539979248716354225113525483968539321034678227749126187895755436612446176705068213351014909167663510999390454127
160129452914412431395355493645578667905076252022076270313861687070509690560468530385710574135500051920073893250652422524935408693168654326249441630658086802944866733250045912137970947977414459443699891320402198814454927895213463459502846242992914417153853886441944071378290051869686204575283450055418751533778098055552093002751573555532434376125576015532857506818977089869511502056276803319310096045926389356134674510524910942514165123711916768985770161125816546389940921768019753209106480006191828355734124559127964437505586224228583975814986584972826182605345853606466822712540252981588709617671892168629674140023985794853501311064130691472365347985088280348159006700598367771734043600590428342823878112242326426566590464193527010497046823726175033330571627328640794010725391464095665624623242211878328243824095006340437177763895007600951843082880589743563274196031460113105358497589320041476926861298176716907885189252045217228664606358543506281628279485689418579385822422685505734469721955421437553828191600084601902357910867129049983645618521161077589867619117321561415249019425015476431653983629540690013913308672650205115968980779818605758235510675521673434235555375157200390255550890877335157814550054382575402686968150092873170449144688358351714419299242648205954364312598729454418891204023198996344954414779749079731219540052337668449208680856036144942623456861396804539425224256052398370029150005531475017583035864065096905070786168313072670220252670509766875546394553593134214419254921061
50477380673914498070326694420762536586135190572475815981398314621396045170850399954722387090162414886486113866081080242079805645214508810942197177840615309172097037527095691864620242264562934582539859561822541728409150198503194943628647727663016994561830630538858760151993666797446057695816310880315135583840126579149585311124487815599265832547454736784388960108832211717412821471711223880106988348763745474523856299551878442111358594197562104838553151308801361859675064479766639915106785883503603816549961036672774682634949130589105190482714522816595893528543926546224202646819659072573079027190351604877179124901880541254650897024208018066831168468841426109078322745999305807154069312641389318951857427509153168563526702449662307089441937608377405
25183954023379068365067390842836528919381056208050757683323793053512257330524957296414831693788244986257395170849836717197073226885859830929650597721163381285055081231870096635493335402866820453339453669007813218055058218336112779505692903895858862237079171763894807159375268944288739613841469275942503375221535039732338675705080265018391982563824809376056386097332045938152
2055363217304673097609147512655954856857248274359808930869420028941871121687896376290702330784870332070926736987861211781498200249680398089534728427586584595562157419067903764037123635502
89720550189303524257654416676974724606366319611691366360642747967661445675242530398105502798
6314340475355910170964884690710195535740434136
92319595296869259591329
68547674586 83638 5
}
RE: HP 50g: Programming Problem: Integer Partition in Palindromic Integers - Gerald H - 02-05-2018 10:08 AM
Her are some smaller numbers that the programme can't process correctly, it might help with trouble-shooting:
Code:
{
2879723196515133729581027886102528537015742667655765453910680280454805795254664395159947306227733420962242654442537228935528546214667263498996080703581986577413499984075501035163636821163771880209111330969151479015019185286779444609090877187385390028446035057399964671652850770634798092066473296286654822085277476288899093419579999003260507172674530244695719721600447817663652276864782377724154392420933129744402100507062480267735169501293003439300034447412723489647760511189276782713903123038505765490421650235322882524317475697960479303487070665467617443798673519541920486046332198565765573139001686856103770494215924240655742304014049253714939097351007453349345038263097776801135298117371296796428280994685323290082657879578085889658154646459725002244724878542870117254634137141902793163198830732047320066904559123014028282752152951213811389779481133326720466738925087299955771046930092837954269635709005925286714628673988578663967459372542970839511525007462863475110291481734000346197257728217591584536838323697925194342912674750561318630970819990716230530238634096096747034186971255727011859741869611024809650195816862056042375310513151575745095015521093626359759013904322578856051024298103463598658256012283780715651573740000834869677168730919284052807518377733430231329041189691023892354757709877363982272481141191844329118319619613433964817518043862557081462341027496310368649485899764106429318527179745756165828034603798250580437251135988979384661546918850594370724752220642810532003757484262004812945052315554834681662344497054828395312568962345916937889011895388998001903446422112017573082001189835097368524694224760037153546438626517301956193298333885183072799671900866409764989356120537550227433424793224133849436211568826234695227684892183531217616791651312181810795982830743382202430622100452131476603601051669837384602237630620786769947192120961204982903111750508311866190664377532195870569827521025922851602101054457252066745355667328159256401917550421886643179219043829990354989585854122209362582487310959976769219898067317586116373455735979967212160207498095183854468348230439676615758258323240736008296816535039623722500886711171838696977976532079824129954452154447220992635449147
9676954530940900939614160605880067244137614780313849317738857406774552038003657384232685399403436769604005726244147403497149011273644008988498331888625874061575364702883281649395021501921558440087907721073447152315743288206177636533876234919182335087487716660433179670114873231111174923591061516433516291863750662857780728657411777400321960709055097372268456535375556022419637986072441115761040169186699259644632949195372937873219437699778889459379782236467271119092945669577283362404647629615265074965598955095157827493930468940045124858696632678952795761939735131722438116736898221401259080218806072799950722199010747625012226965988629269746230371622748040212711073628234166278600638491491037182929577670165312876234765431439686293344042700361845107289833289590782623597887732799563332727018827790102346323783347130652511097540146448372844921453724451213455697713120033664786604711162957048764054823936105698561475649517590186309922277757352997521003088297918272525523227006852026013716031688230472554416688300900528635529019317841246072190130408892969015149428140712320333655826020314579824772165001134805525226320311028610278097339166163507114886188435234407150685385729371385836953679130308973790916826472238214630594496084203619066966177509951778691185565401121337724701580584294860170615940557270368534853173282383020441143476603872849645388217059283515897400849277730276213517879796124343347207941250167248658034546900397892727535053379230281595107140038165116145075333965935882365937497415594279419275138423880371179615648073165694955693415960371989961216992610819899755687285649829119517312836976870789450902472496012351451008173174317163944840813576751026097084503338266531702957275362317396394456350803479273390283924959893742154692435978141494747171943945704587560066956819297657173310958599075981173175148044616794096367210808480298372336089784664761797887468407098884132788027160097819797467665555446472719509992924151788419908224908180521565084706121083741775523133676005150894518944536168565671081784369254378889910165005165173969317713877393497637633499782124898340568423119925200575904500980965758259934068822338314663089017823513450679988732480041577058389121954653672983928822292
458389050170520244255251762556286666211436374672200007238392769189373514585953033982110496786289410858656579605165747552822081436070288495919172605417577732886728178861778329825692238185235687831612024647392446956587584173959369299003230496287958295415857517878486915230000017499594762195678916831829590592818583699978609019076956302657689661831398410651964076523200713565092724576977765186167749919352932549849722587534584937844277129642927543123281142468977892031960707098937313953580751251801916553861444880520193019024334678855187975627065653858452913186338055432741745097662171191988879970769772947384806559282109614060275302225371740609921446218575485255372004235656829151478054660366461130605228793736056101960290483334798036376944359886042206950281544431224091948335838375169554738232457608571069120113928195432355296367899452477562675509484824952930625096476199837513057231782193866877069169387567564429157719763328693485492441468754273561767755946137656657398292550568163569190137462419306614443454745509678632898244947793110591898428376526576994011006692487476263901175921182837958916305716551023635676374926788349650617769346112922539478150993134618932328743516542450044514841319172030714779789934768258288584117942027101788687338818446354506481850179627450680067208598214943586313613455266221187606448214498432200218242467695242576390572052236482480494277551495214284837241340560143921197355549875294443672427038881300137127780641041231043666088145463226828464556393299473239763220728189797777269019037953943671925404331941663524323456493209284222290610155157290162399181597805444647513695847055781924546516117831035341751995038479363360236764037589652552734358075467269503657879590695357837641020937515428835793082090522392295429426511998316316311547216719243990643358028886836794112122510998166851500970600596422814015314922375219772110465370889845311983922868600207992876647554046616916952312516797263924722856679594147621846467230311760483974951074265024269341643500858868218806702134519300099164119392191411815839153029758268013646016109272668720281460431671609068434649628904237351056796057474376823980025688443777027431147221743739169486771047944328820302039159377135550854041857
4856406289363758137697867701393609638102080834652353383486196651402980486507024436897267093878724702454137271759008338855686922703473323862094591259614417770923051746153721064192822941998962726224437438169019164998227063844114939750981363451183265171741964524196416594435428482952539218327180884600891856403738647633821539325499073102926085858160081089902251379407160856814779856881682687574545127549418418939651515302057336928966675352505995692334956722895501767651388041089008687127141099860942466712136933371034132586207286111493681863696788065148489349441610972281017383579718184662822194026651762916254291766360245447522463693269284010643899094204549828012099334694113803091433455365176520451368713710318533130289243905535903399699296248935932130101928924278445286096007833090546330613511721462662554933020861991913459937273092926051976920805025923718723047083680775696151323699574937404648020179781411203731789515981941810172918740300299868567248505213420100251308968215630910845597985081521349844372630173398936225037366776982684932954986142593020124484643833914771313052921063539402138133669300413253656549258386890089256149121586913911187463060096842308129084843525578553757720536168680223076695546248027695994295075706090415384800726682074538662058110449172413644126487904013148102145916317861367695259822217473837438415599319798364593265215730144298560587561534368289298192288832828618491448193206382900239544479790595295779539253696015760045840761010064572535485518528359036089384369805345580955251865231375922721330395137168604173543135514314160687632711640060827201878012461146249431947093595867445079919213631473860457767002659886461246782343968144526669453210964999996180908934866304823524993586842182159569887133617567916550559501620527916832381918610062651211469443922466663383910429013668035252479575757134414962694518350646332532078043691668258532876915524925120129433957436771032085978134099001786735700335419443652458020023975260370914615248045888239590555854253373348089286473441785299312446143587919659057506531232794125846648733258230294045658621647485606484821664811023219763146665434273147779703782319364758098621266781843750043009262910978079272216344685873514849962667987890771022335610063929770207555540229435156622061687044216072663154388239641897088705868582994265809143935248476237622702936206824965162954439107585678072465146608374996462075953695179619622636109318318431479829041635673759183705483332820516298907596719922654024139213529152739232465289917726955078918
44442840187184249379486313408939572854501663045171884548454766388324978394690011084443843073628733994768870285581434225879321054631803789488596889245113128881556141098181885621640470641449035500310459740599953258930366569655849287618350441245109309857135671257062208247811657117472650960462336447237243400181511821451897171393572419687883084182847121091817223019922680920631246572420625494220943770652453393304578279791549112479573713110435812827744883333907413681843148766967271926783035398529927833019839640458383185545031695820188893821520188488964075981221339777266509776153642135953565480272912010338111920024873377653510456116117945624924748253011331793297054947290124715115775355230561574043663396726597128695764246646215878360163067086325980734448666514816010566014653089938115128297026151496257890000116316624042614529213344527881870873185939957713875866656806083842600989921512038355230565512650988237615247017017681891248545952846595030642487341785040548400389543860606073653323544164865247883365373125622237872913825160970966569554559633764535318524760726467086780960419985454919557143694249946568008596648504133327536643916396418181738414408712290470217167181136662734446611429702272146072435177669171090192940732182030580688347546161453236113056147966252082547050674412849282898474217582910792023150273079713374400719700290574492591258528020174977527552965905231058981149815451484497401872103154792627161094154567430759745197235960553519149409027646569575500755912799420926608282934674826969238435914582009789676700037333323328184129973946916157980313520217851107993786294519204735972258529997034349966689049704695739557346732994453718505857447340716441375879664228620625278070650132553353243009437231961044982191139131499533933566246938109140798877147042702242648165218185534390432346920476048648976731035249147223581629176600969882020924655431866516423396918652277833717205869068518418756874700134183340359896706620419620276070761720028936433073526746729859941125147234243921299866657085247172906452184445881551116501252285739004111627992615434062341162444774840562122776731726115363179755700033578444437849254089719379471000537898739916002181115301308211619094130257932908885352613544835781699266103969238922385054094591948792972059564241824433874498285253476714316816344567575787723855698738081778808982186091385870816584054881450290321933640542892870853190226672281352469010228342109479156391264160049374063971383968317286943317633362796658514191232846691033278810259586373545078
24114610173820658649610360154324310723115859462643973654442543604725011427766239640237311168935756070159040637655139686618260524223338102602619199964292472650450269192186993047286369748115820508013331757301843777285990424657279818890004065733175529397360751959117378244902077535322879130821609270162905276999910375037357983816121483608684401234761504837606871179676720704430019034216585109389498956962418792710171872594100651706043653999622144427038242232968462645805143551258810540042016176707764003304988717155189131097195323986604179161362089290520436020602227609138135547901953674548886334802324168894511172176509613962579982572997758017657886545790803208144245465676607005666968142409089394838444925543362812173948655790625817839743318210390697506348283115078966645700092466716980523050188754363570185488485660535417260349955206315765559192622882935044126727151511576864346735986895482998486382392742896803858498129720653513952295810480341867685723254131385832867955637775365340605791999127345648577847712373213860575067949884833269110883176919723611767050835457730502551673242673238827598087548683941758916525240019888851312692558123535015687599608162151276370424141157983203650210413325439564469890419409702750404123812124413011864361049316886387590106121357655239989354948920951775944318497742714565311102222393447170853730856151227914739599372415993088960613543800850394781275174379745186000640793095685517359912073950934548004339578206737853942600746486239940478219255004105983359815503034182728176064138258586448130794249224626581381794378705595836834896973910332829915355425110033165936139176309376557325873322276956483990432404770703471050750727659718351869333875292385510590632818846719594249045077633451938183633320958410396840347653094519887034631723913305071442447680236660412868514623675528849583447022994819383808619238009780044180285257659666050129941744999383550928535380936296236469530188820837814590710286310611398061426275153463281951271343098188380505402793062908581141250553836900486239696276308649714639051503105114520671595153648795532899039575847326550536791649532723947915749988772595750058687839430439242578763704898402079490289693782240934859059292648265252952851165932711130355374560748553931369724795296761443190132535253509342059253351412338089507563366071917837639969480911455475720655964899678804688202257206466516545884004332756130541353742282579060339791802663505605763326183894245121981315894284463188952671820803397836709931880443474202983330475006915133239449154059694586175171402719174791374168472112978144207081610265327362200794155961204652702930182273121826179588551301141859492956350257083628514453792412624590086029199637584026875739055768929276839328460220093793990556832878554234893646467687477389476130259169398999739492246456336498164140536449916332501708233022315326144841447380638887683270188759109083285821361392785276950888821115917846716020329
81204360147158948794178614427539393608397932565359152745641829495312942262647070948241961425447146480742387709596594729482788294818239990123200382384350200264255705860530838218503907757264870707701163773988928680877462421000758263259224967875059446767450110524044349098989932942062732023503311449068744887811382432669854579560219613408851205110672531690669110994508862466339046533118918414485140461818555453882519460410883096236452773132407197657813493100853753451125613328191715657539017069148755439898686239458207790540990495954768254467955913697233314546128486383107913703554887629201479526831598909640802825143617155288418969718224377271807493537950217969574506066225463917423891832142099071946188783637696200872625247738792673234205620596616965773557833883304260804495138851472845905712287309722177511775171728665326445283904548786992225131010196641661502750614820417195682358055018183191258619659241530648993678839145213755361818841710525965254358610961335631071259232844185525247125691400789925295753641473623399895438714799353168871510632975552794954747864685644413405544233975642180553038557849355536879683648497022273693203259631938249845418822477590319489622952590438380245880526471738949421213026861638111991585470905249005220017273994596682174160905835671972721836708896667747890902481066431987480395492707943019065471559845782964126537576233542519074360292690367598421546896852448292646532162012872754952710476796481604420594611544886298530108955462806152834378464861411567440214888776720020735186990453970148386221277050796122056608113142181236355446868210885916180959384027988780295253991720245907980957608988480407272213900955931764774301918092180520551889746989196312468182272857634619143964898677509721354115291038780538831936649064572921199251500447092589999150555300151918203713269103755343263905941779851078905464555151145233599989024369498613218566805217179247816759969871701170611941415063169911186998280911522698608970572288921566155088186863141126762048758557841792346380277217237156310967501138046889585688314741885204686878661134763975426464332079201270669945746758414556557366598828735373884224696146423637106260654681772369108556374283923959712226183165104012137188802416861345488468311234807103728783212733380163258588340011110932741762426300584298693664781476173767141373598387563755762478978501394232148113952872926297363571284252463974661754839258573881244632199276260241635707618310672189637371392170342685737533934146006773480229389808789900812618183684826660227559165394362037203561650431046092679753676950569701026150420813422239355430287209834529084054389799346234834603467733181959843277870002643751454856369552910132475051762294895019486630970867987030097845306196389072659122103905903394855586532166024408194626960932916365195401779240991736428617719062373361770676408381138475122946662756614127232215315554196019772405036444217935512099736114000503108334631
9105762592416954425087443100581908227222644322820422732819553384728057987501047142018400905347573672776415030944734969075104782620724238804530759695514232714034866114668950008262246556883449498013606182090314370407159551951054847291696160387222131779246433745202979984339318751098254320769369097210766429609239820226148958682286950764545990549399927443302894437268887478355159128248985001447002745826345427379149279434123886758884514216173937695129611344017491489685850158232484874974430771145125144819496004040921843062974719129953962449619717865913237462062482587786978917326890373812514234990045840889562331276851260548864653128876986856983210249763026010980967077255970033150490541207042996166752217250232717357036782278685268064022096015052655083182869925432278439110413486092360042270370728714075392128989252098378470712181219679111772771928485170735268850217899703483257027165549849737022176286796047143885360322540176459389781377444794718385195742802439900085930823136692730179512805592117105791133268915623288746061862641065532254781767288092678219420421651789389600170539403882020417630135772921739915180138410531965920254294252473472064118721314428918261978500289233550345342148372383701067564778985412459387305965977753082297614610246538384864106769902029200839722823770772276365628161251455491076748086668627743558033328703317825914177206158910147409498050019393802080992207553746879251864276576580347211095875687321465905050395668436342622983591535721746307022685947190401917305166456224211438312594402860245986989864539883558853049023307908294259821937472749668926272238101268785511990683396771215321574267175913492552063668957271445221451629847283283274262556930782308970934381631490842553881206110244526299826977971785045346546946701128465433611291536745795154437194605087601574259362475055872980415759491252825367175852982418584941856911537954298442161118751289976911748653115523813912596786861925406510678126613830593365223054498181030693960903073367111786979138960290220792907924172816804022835166983668661917091772540944380006219191940358186955056239846623115441637881847060180980160194297493179778425082792462557596835206795089280025058797486032998759563602472671470360462911188527023266998261050482729113068147730692915621011887183837024653216655222838840296650836650741272359749229860551500344569150342062281568970857778051412239004192895787185767401845969072173062508696603735928534801018842641629977751839036410168702242776341679329285637192692661059515619376935134910849724597608382640992143519398458380162389473469092383673245751615813913712063196632724241793033854640023705772837420786923426312497265531808375353019623083788342620180863545187458729808999374185344848202128796818879026648113869328079411277751110779244649168070819737159908844423289417681766391207458167963998646543286739858261556284114690805124850677669435077271309651315028378282277680725355188727055900393360736704978718425626045335993162458211110006646950721645239825287860483422077456899946968488032144067687156174960050380440001893408798917987241253845242023028512047183436583314357883764719634120602
106471593868451748099057592945520663665246551966300268341479255567933057305393714747230259701709748377799487879203811168370152607758062524241149350634171771458605773033601907464911474330572141889228607562686268131516818555948747007907612194947241111426375678618463731866579806613361440108974903439977132638860879947276158844616125297914214854191577257757616811503546930157471265429395712288548072540647249289016374400574554793278822908553602642310120329103438467135369587697204259731778401319042280069089407677221984581795288786699345903294095475664816907254632145945172536358618686902694708507060783692142280085490989278182074777000572611650582146470979216447657966289262960430557826028914338996010817464966195688660259667140054133209811910136236679976162471677518131255901200772926820364985922594277943200713375497060384375204241553040855840571584074198535278122263339250537760500227483794184896215773204928303967146700457601781991454543191404408611173482921436007031152546586806432919369803556382237347159941059220059743640102448803618311597679921088491541172010843757317437194955281962582906808280338498358767394798069554296188638072402813743383752019263161823378052758562148065973869163248107838347713184982864074515987765430758221215796140893587904109118647572611186849130250867964283888357976960578394256985195069138995483363642917811799760344546364806190458231422105107818085654282128094187595729021933520874694208356531623290758289190757626269173169248915575480715797268301082951164232529549528461710247741853678274284649901743438815482106628095700142368263172478308973830387978400067283991563827068825035384999161288157243115188215704748979181138213294386328110311994697976282229229145364419408249906789424133385449061871265083083485169461894709016337666510498553788834628869764182521800351456700914883082201368875233342006497076945516227129708519993260679325887179640775416450105649581882608870813714690809287805855393081614310836982076607236178029769551653439249197415132041735342722602889493860794658718288128994146610104729743602076629362776893790592424262909156120312750077510809142524738209285762178160555308804703095931324025365355532454345122675846671807955055612981757070246808926982093807137813261012141072099068601061285228246722183734276192963277130624880446715680360944599089842048651665425449152327978089991863256905428675169026212011659751709694067654917010539052783917327119588610859138287547793332502899091271854087891665765330312349049772471467645880593167537757853752192279589977623800384012985295628003223216784386925850812157263842474889243714208039686787709533299577176418455726276257471352420019259247622859334725414308580780960504310583006999804278729926344138326424914581877341545702406394843959699095652571930382009557154893012442150591983158074893145340635511353657670916644111391953768470855555312340616297186059776138097328556852732794923221122444356759186426841306081727694142774791934017306365827218875042725989501333440194184409204475060261512178655767046312
246286460141676581222787462776361561419190885581047042190309877519637188343243651232877556249151693439689701358641829479302102714235022224562528831037225395674132514937685199727115705094793324552679829991441480224196473415513754408707384421499145084882376787412576655112891962566359059709367024656045995788504897344652273007468117115052133776868189875433473213883373692256367375313534520912500493587432314714385474262342520907351675439074211418813867421646958257790031591662934641501536798114195538215946988405798212592209044614747318595014047191952841248932346674134447632539724678461957320920884026798428219295683322886419372155085099941276170262916612913481422910493749471028548592110212144466381742049633098851981307779792246932824142323853160891204807608501311647096578675919202087661425469821657912874184389462286705457569788122097445155468399305980958003518188226777624467064972981596169980853530196849062379932478083422782538979843122786839468656228652906664031465581711694825372858374332791235762538495266889364389408587363583556395991250015487686890741013861370603869082336879652144127886795686848929032848334747722012218358461703266605584575333645004974759560072054253992909496911861398581000776724277268477440714621534752535864949827011854038107595480816084936542782589959210189881847476079752955976270803435268806312831437040053893671865048075222958484383869634277953109979721786352551544171012028723179691505349055456009260148251560908291954627566433816230061236916529621184182536828327505177242068545808142021894991302948904457737791340041710942033398960266777626531506368332239423131828830794561556910065918631799229237280602897489120033127188262339864964268287067360763913758779386852144057451380096946828571835560339284259642710116585682304618607564430011002503478265605940228325998930692639733007220923217119222714572061688251727104258131266814526065543277449814947772343754834504693868202465168279437537819233082241495564431325507262415065628459567808971045456803703195156664556449714219312978814063603081526418881046359789086313368308809194802913134259714013564580521776277296885796398858532917375961764090656968929077921526714839505107615761656311358177464590483539889801568153788781855215134793183986397675803780945482297938562149785675626036812992608727592571213335505689805496521680553001159975791018598499955488257656981585992135639099228632423062821479680600255395302668189853511573454840217438357889807640899220977325348671443337807093828762174741864655186642815760798259010805243505668495361406358691382842119501518412090984422869419537866053857727446592165561161152892947792867244740878810292087528825261378635013234048678854231867547086969453728375960618811997371862816114369195082746691381724823199005245784532029369303416700729272963616135195300258287107233279268774946624069174711312318316658838549035850874848056362326345309861327097347093713475120343208966363084730502210572700411300721304096338367732551257059326771885819929041994639185462381676844837570380674636
258073692382647954973393459726740093441483333292051251232401842420136379338751564059806902436681600318697893327735197976014616272436056901151641849997379066647215841712676409882334735324193116562145748681418322120279462005728528014107151687402685066014347313226172642648508439598376804133371802586914960880668292339530224017496354528264614915340725844754279707876311347797391904036169538404641347550886870259376117367761550059059778449178999654088991387932947241657075528462524599513536789648016631873049871964302315525058197096751770643212012486673369474764546137162474982994730749179213398380612994178190833969618600906315380354905949484299381214907771744489452863347688348175619717218657329198370144917222002552620794781458363053894178257686157004448062630280814046001512248712127646725328454630992734803999173936292475836799850902254721539665330468915093870025196048159221430858660206587640175942331621524644938921182579498262746254832916104262494193883805918871569876455299573566369449603332724633764123400876225712354184177347578627867172538655974425807908635145349428120071329056168711203848626663856360864407307619444838209264567299296174509788534355027909672635062859242103312396947079513341012541716127623980352329618508389522896183446131868121812408455681713829453722920335248474959696482928252181945321799369251527703522461864919813689712813104294000178062850079892375139254624819362009307491088910138903680115133827482175724609263988453444925215237881803780229712948587854815196208000486579134103507853080425603823188979079910904680697478694105412026358177649770183187136937699978113104141354435155221581301948719246365247366184823456336305041217727693712990102454549372741389252740229875143044392366938978619405089574675449311617969285649267766301734592407904173725194290105919635920551923005406562031645166473127407843241034175475449194334980773844415207799328716900667749665445568592016762348491866595764549452636173484944704565312823380562609724914767981299848857877157784257659283251881247176896044079253336911486530767954772925645104332081541417919219227189108522731638767774532956572709652316183010552178067196336307066745136795865085002152773841833738414860240034526594232729185138377342229628871687951039827987775044670483966113757317681962451355961589019701564402961804614823104255698860615706948622466923480987879674686496588762514552649817390080055559446880147478322643644506865363265017811605819631876994571854252153921122685510564141068658623147736329246842670259638061265948723582573775989993498981413457876870976222420023334651832619452713704411997317152347588479162322885045649300292777809713404029851371910875025630297101513958289274073444138252308960245488902127324007718838092586731616417276269027904893790078124389003402281623265945335982120913481101115876287848747228960006738887775459346771350973045918183313023539691587397895730064373960497012132309970416334879238592920733831865332553032782397997635108222363037482870207694105923645840864397607771973549754936684
}
RE: HP 50g: Programming Problem: Integer Partition in Palindromic Integers - Gerald H - 02-05-2018 08:31 PM
Juan14 - What is the first symbol in line 7 of your programme?
RE: HP 50g: Programming Problem: Integer Partition in Palindromic Integers - Gerald H - 02-07-2018 05:31 PM
Meanwhile here's my 50g programme which gives correct but perhaps not minimal answers to the problem.
The size of the returned partitions is again log2(SIZE(N)), as for Juan14's programme, but integers up to 40,000 digits have been processed correctly.
Size: 557.5 Bytes
CkSum: # 6711h
Code:
« 0 SWAP
WHILE SWAP 1 + SWAP DUPDUP →STR DUPDUP SREV SAME
IF
THEN DROP 0.
ELSE DUP SIZE 2. IDIV2 DUP 4 ROLLD + 1 SWAP SUB DUP OBJ→ 10 ROT SIZE 1. - R→I ^ OVER SAME
IF
THEN SWAP
IF
THEN 0.
ELSE 10 * 1.
END SWAP
END 1 - →STR DUP SREV ROT
IF
THEN TAIL
END + DUP OBJ SWAP DUP SIZE 2. IDIV2 DUP UNROT
IF
THEN 1. + SUB DUP TAIL SWAP HEAD OBJ→ 1 + SWAP +
ELSE SUB 1 SWAP +
END OBJ→ 1 + DUP 2. <
IF
THEN 0
ELSE →STR DUP HEAD "1" SAME OVER 2. 2. SUB "0" SAME NOT AND
IF
THEN TAIL DUP SREV
ELSE DUP TAIL SWAP HEAD OBJ→ 1 - DUP NOT
IF
THEN DROP TAIL 9
END SWAP + DUP SREV TAIL
END + OBJ→
END ROT OVER >
IF
THEN NIP
ELSE DROP
END DUP2 SAME NOT
END
REPEAT DUP 4. ROLLD -
END DROP SWAP DUPDUP 2. + ROLLD →LIST SWAP →TAG
»
RE: HP 50g: Programming Problem: Integer Partition in Palindromic Integers - Gerald H - 02-08-2018 12:17 PM
Here a smaller & faster version of the programme, produces the same elements of partitions:
Size: 469.5 Bytes
CkSum: # 44E7h
Code:
« 0 SWAP
WHILE SWAP 1 + SWAP DUPDUP →STR DUPDUP SREV SAME
IF
THEN DROP
ELSE DUP SIZE 2. IDIV2 DUP 4 ROLLD + 1. SWAP SUB DUP SREV ROT 1 SAME
IF
THEN TAIL
END + OBJ→ DUP UNROT <
IF
THEN →STR DUP SIZE 2. IDIV2 DUP UNROT
IF
THEN 1. + SUB DUP TAIL SWAP HEAD OBJ→ 1 + SWAP +
ELSE SUB 1 SWAP +
END OBJ→ 1 - DUP 2. <
IF
THEN 0
ELSE DUP →STR DUP HEAD "1" SAME OVER 2. 2. SUB "0" SAME NOT AND
IF
THEN TAIL DUP SREV
ELSE DUP TAIL SWAP HEAD OBJ→ 1 - DUP NOT
IF
THEN DROP TAIL 9
END SWAP + DUP SREV TAIL
END + OBJ→
END NIP
END
END DUP2 SAME NOT
REPEAT DUP 4. ROLLD -
END DROP SWAP DUPDUP 2. + ROLLD →LIST SWAP →TAG
»
RE: HP 50g: Programming Problem: Integer Partition in Palindromic Integers - Gerald H - 02-09-2018 05:43 AM
A further rationalisation of the programme, shorter & faster:
Size: 431. Bytes
CkSum: # 8EABh
Code:
« 0 SWAP
WHILE SWAP 1 + SWAP DUPDUP →STR DUPDUP SREV SAME
IF
THEN DROP 0.
ELSE 1. OVER SIZE 2. / DUP 5. ROLLD DUP FP 4. ROLLD SUB DUP SREV ROT
IF
THEN TAIL
END + OBJ→ DUP UNROT <
IF
THEN →STR SWAP DUP FP DUP UNROT
IF
THEN SUB DUP TAIL SWAP HEAD OBJ→ 1 +
ELSE SUB 1
END SWAP + OBJ→ 1 - DUP →STR DUP HEAD "1" SAME OVER 2. 2. SUB "0" SAME NOT AND
IF
THEN TAIL DUP SREV
ELSE DUP TAIL SWAP HEAD OBJ→ 1 - DUP NOT
IF
THEN DROP TAIL 9
END SWAP + DUP SREV TAIL
END + OBJ→
END NIP DUP2 -
END
REPEAT DUP 4. ROLLD -
END DROP SWAP DUPDUP 2. + ROLLD →LIST SWAP →TAG
»
RE: HP 50g: Programming Problem: Integer Partition in Palindromic Integers - Juan14 - 02-10-2018 12:47 AM
(02-05-2018 08:31 PM)Gerald H Wrote: Juan14 - What is the first symbol in line 7 of your programme?
That symbol should be “≠”, sorry, something went wrong in the copy-paste process, it also returns zero when it finds a polindromic number. The program should have a size of 214.5 bytes and check-sum # FB55h. I tried to make it shorter but I couldn't. I don't dare to check those gigantic numbers you got.
RE: HP 50g: Programming Problem: Integer Partition in Palindromic Integers - Gerald H - 02-10-2018 06:12 AM
Hello Juan14!
For even powers of 10 the programme works economically, eg for input
100
the programme returns
99
1
but for odd powers , eg input
1000
the programme returns
99
898
3
which is a correct partition but slightly extravagant.
Are you planning to improve your programme?
RE: HP 50g: Programming Problem: Integer Partition in Palindromic Integers - Gerald H - 02-10-2018 06:16 AM
A much reduced version of my programme & faster:
Size: 300.5 Bytes
CkSum: # 933Ch
Code:
« 0 SWAP
WHILE SWAP 1 + SWAP DUPDUP →STR DUPDUP SREV SAME
IF
THEN DROP 0.
ELSE DUP SREV OBJ→ 1 ==
IF
THEN DROP 1 - DUP
ELSE 1. OVER SIZE 2. / DUP 5. ROLLD DUP FP 4. ROLLD SUB DUP SREV ROT
IF
THEN TAIL
END + OBJ→ DUP UNROT <
IF
THEN DROP OVER →STR 1. PICK3 SUB OBJ→ 1 - →STR DUP SREV PICK3 FP
IF
THEN TAIL
END + OBJ→
END
END NIP DUP2 -
END
REPEAT DUP 4. ROLLD -
END DROP SWAP DUPDUP 2. + ROLLD →LIST SWAP →TAG
»
RE: HP 50g: Programming Problem: Integer Partition in Palindromic Integers - Juan14 - 02-10-2018 08:06 PM
Hello, Gerald H, I modified the program, now it checks if the integer is a power of 10 at the beginning of the REPEAT portion of the program, with an IFTE command, the program is now 201 bytes long and the check-sum is # 480h
«
WHILE DUP 9 >
REPEAT
DUP →STR SIZE OVER 1 - →STR SIZE ==
« DUP →STR DUPDUP SIZE 2 / SWAP 1 PICK3 SUB
DUPDUP 1 5 PICK FLOOR SUB SREV +
4 ROLL OVER <
{ DROP OBJ→ 1 - →STR DUP 1 4 ROLL FLOOR SUB SREV + }
{ NIP NIP } IFTE
OBJ→ SWAP OVER - »
{ 1 - 1 } IFTE
END
»
RE: HP 50g: Programming Problem: Integer Partition in Palindromic Integers - Gerald H - 02-10-2018 09:00 PM
Very nice programme again, powers of ten now partitioned with 2 elements rather than 3.
The IFTE construction reduces the size of the programme but makes it slower than using IF THEN ELSE END.
The programme still fails for larger, eg 6000 digit, numbers. I think the problem is in the part I have put in bold red below - I believe the comparison should be between the two numbers contained in the character strings rather than the character strings themselves.
«
WHILE DUP 9 >
REPEAT
DUP →STR SIZE OVER 1 - →STR SIZE ==
« DUP →STR DUPDUP SIZE 2 / SWAP 1 PICK3 SUB
DUPDUP 1 5 PICK FLOOR SUB SREV +
4 ROLL OVER <
{ DROP OBJ→ 1 - →STR DUP 1 4 ROLL FLOOR SUB SREV + }
{ NIP NIP } IFTE
OBJ→ SWAP OVER - »
{ 1 - 1 } IFTE
END
»
RE: HP 50g: Programming Problem: Integer Partition in Palindromic Integers - Gerald H - 02-10-2018 09:08 PM
For example
"11" "2" <
returns
1.
.
RE: HP 50g: Programming Problem: Integer Partition in Palindromic Integers - John Keith - 02-13-2018 06:31 PM
(02-10-2018 06:16 AM)Gerald H Wrote: A much reduced version of my programme & faster:
Size: 300.5 Bytes
CkSum: # 933Ch
Code:
« 0 SWAP
WHILE SWAP 1 + SWAP DUPDUP →STR DUPDUP SREV SAME
IF
THEN DROP 0.
ELSE DUP SREV OBJ→ 1 ==
IF
THEN DROP 1 - DUP
ELSE 1. OVER SIZE 2. / DUP 5. ROLLD DUP FP 4. ROLLD SUB DUP SREV ROT
IF
THEN TAIL
END + OBJ→ DUP UNROT <
IF
THEN DROP OVER →STR 1. PICK3 SUB OBJ→ 1 - →STR DUP SREV PICK3 FP
IF
THEN TAIL
END + OBJ→
END
END NIP DUP2 -
END
REPEAT DUP 4. ROLLD -
END DROP SWAP DUPDUP 2. + ROLLD →LIST SWAP →TAG
»
The version in post #12 is actually faster on my physical calculator and emulator. A neat program though, and surprisingly fast- less than 8 seconds for 32000-digit numbers on the physical calc!
John
RE: HP 50g: Programming Problem: Integer Partition in Palindromic Integers - Gerald H - 02-13-2018 08:05 PM
Yes, you're right, P431 is faster than P300.5.
Would be pleased to read of improvements to the programme, I'm sure there are many possibilities.
|