Posted by IanT on 15/12/2020 11:54:32:
SoD – having said I wasn't a Computer Science bod – you went ahead and set what I suspect would be an exercise for first year Computer Science Grads – who presumably have been introduced to "SoDs Algorithm" or some such as part of their course !
…
Not so, the challenge is from Creative Computing magazine circa 1976, almost all of which was BASIC! This one is more number theory than computer science, but the problem isn't that unusual – data getting bigger and bigger!
Here's an answer from the time:
And then this more sophisticated version:
I suspect it would be a challenge to get these working today, because both are written in – I think – minicomputer dialects, not the tidied up BASICs we're used to. For example, Tom Karzes' BASIC appears to allow him to use 'b' as both a scalar integer and as an array, while Gregory Yob had an interpreter that could add strings numerically, eg A$ = "123"
B$ = "321"
so A$ + B$ is "444"
Today most BASICs do string concatenation, eg A$ + B$ is "123321"
No disrespect to Tom Karzes, but his program demonstrates why classic BASIC fell into disrepute. No obvious structure, meaningless names, GOTOs, plus noisy line numbers and continuations. Hard to understand how his code works.
Gregory Yob's program contains a showstopper. DIM A$(254) is the maximum number of digits his BASIC could store in a string. Far too small – after only 1000 reversals '196' is over 400 digits long:
353466443924136897858377144029121143628590980834140834402086145040599291832845719034956
387168795800463971545914548326676428378028814710683108505496412733883652599320082374934
620554240912515790120016687692352197776621010107415220132544026439582289914006246477437
313605494900387117318730883824675524836409655069474008586970693559441817449338082995150
442581194537942329079105826441012030342772858788740429334664452
For the same reason, it's not amenable to John Alexander Stewart's "find ALL the palindromes in the set [0->2,147,483,647] and return a flag indicating which one is set". I like the idea of using a graphics card, but am confident it won't prove 196 never becomes palindromic because 196 is a Lychrel Number – it's 'an unsolved problem in mathematics'. Wikipedia says the reversal number has been taken to over billion digits without becoming a palindrome.
Python can't do a billion digits on my machine but I submit it makes the logic of my working version clearer, and it handles big numbers gracefully:
Python3 strings and integers are only limited by the amount of machine memory available. Although there's no Python command to reverse a string in place, reversing lists is built in, and it's trivial to convert strings to lists and vice versa. Lists might seem like an arcane computer science structure, but they're not!
Micromites are marvellous compared with the computers available in 1976, be interesting to see how far one could get with the 196 palindrome problem.
Dave