[VA] Short & Sweet Math Challenges #23: "May the 4th Be With You !" Special
|
05-04-2018, 09:39 PM
Post: #1
|
|||
|
|||
[VA] Short & Sweet Math Challenges #23: "May the 4th Be With You !" Special
.
Welcome to my "Star Wars"-themed S&SMC#23 "May the 4th Be With You" Special, young padawan. Here a difficult challe.. erm, "Jedi Trial" awaits you. Should you complete its 6 Steps to the complete satisfaction of your Jedi Master (that would be me..), you'll be a lowly padawan no more but you'll be promoted to be the 71st Jedi Knight. Alas, it won't be easy ! Far from it ! A great reward requires great achievements. But should you succeed, you'll have learned some ancient, valuable techniques which will vastly enrich your skills and, dare I say it ? Yes ! You'll even have Great Fun ! Shall we begin ? But first of all, a little couple of Notes: While the final 6th Step is solvable to some degree or other with most any reasonably advanced HP calcs, the first 5 Steps are intended specifically for the HP-71B. It might be the case that some of them aren't meaningless and might be solved using other HP models but I can't be sure. When using an HP-71B, unless the particular task specifies otherwise (and most do), you can also use any of these ROMs: Math, HPIL, JPC, plus the STRNGLEX Lex file. No other ROMs or LEX files allowed. In any case, you must use either a physical or emulated/simulated HP calc, solutions for other devices aren't allowed. Step the First: Write a program which accepts from the user an integer N from 1 to 19 and outputs the Nth digit of Log(10), the natural logarithm of 10 (= 2.302585092994045684 to 19-digit accuracy). Example: - if the user specifies 1, it must output 2 (the 1st digit of Log(10)) - if the user specifies 2. it must output 3 (the 2nd digit of Log(10)) - if the user specifies 18, it must output 8 (the 18th digit of Log(10)) - if the user specifies 19, it must output 4 (the 19th digit of Log(10)) Requirements: - the shorter and faster, the better - it must run in a barebones HP-71B (no ROM/LEX files allowed) - it must use no variables at all - and needless to say, you can't supply the full 19-digit value of Log(10) to the program in any way or shape (e.g.: as a string in the program, DATA statements, reading from a file, input from the user, etc.). I'll post my original solution, which is a 1-line program (48 bytes). Step the Second: If you succeeded with the previous Step, you'll find this one dead easy, namely: Write a program which accepts from the user an integer N from 1 to 32 and outputs the Nth digit of Pi/2 (= 1.5707963267948966192313216916397 to 32-digit accuracy). Example: - if the user specifies 1, it must output 1 (the 1st digit of Pi/2) - if the user specifies 2, it must output 5 (the 2nd digit of Pi/2) - if the user specifies 31, it must output 9 (the 31th digit of Pi/2) - if the user specifies 32, it must output 7 (the 32th digit of Pi/2) Requirements: - the shorter and faster, the better - it must run in a barebones HP-71B (no ROM/LEX files allowed) - it must use no standard math functions and no arithmetic operations except + or - - and again, you can't supply the full 32-digit value of Pi/2 to the program in any way or shape (e.g.: as a string in the program, DATA statements, reading from a file, input from the user, etc.). I'll post my original solution, which is a 3-line program (152 bytes). Step the Third: Now for something different: you don't have to write a program but instead solve right from the command line the following equation (which actually is a polynomial equation in disguise): \(\sqrt{x+1}\) + \(\sqrt{x+2}\) + \(\sqrt{x+3}\) + ... + \(\sqrt{x+98}\) + \(\sqrt{x+99}\) + \(\sqrt{x+100}\) = 700 Requirements: - the faster and shorter (in that order), the better - you can execute more than one command line in succession if need be - you can't use data files - you can't run, call or use any program code whatsoever - for timing-comparison purposes, use 0 as any initial guess(es) I'll post my original solution, which is 117 characters long (about 80 bytes). It's slightly longer (just 6 extra characters) but much faster (2.2x) than another shorter version which I'll also post. Step the Fourth: After that much trouble to complete the previous Steps, now for an easy one: Write a program which accepts a positive integer N from the user and outputs both the number and its square for every value from N down to 0, both included, one pair per line. Example: assuming the user supplied the number 1234, the output would be like this, no more, no less: 1234 1522756 1233 1520289 1232 1517824 1231 1515361 ... 4 16 3 9 2 4 1 1 0 0 subject to these Requirements: - the shorter the better - it must run in a barebones HP-71B (no ROM/LEX files allowed) - it must use no variables at all and no PEEK/POKE either I'll post my original solution, which is either a 1-line, 49-byte program or a 2-line, 46-byte one. Step the Fifth: Enough with the easy stuff. Now we're getting tougher so you must ... Write a program which accepts from the user a single-digit Id, then accepts from the user a text to scan for said Id and output the name associated with that Id. The format of the text to scan (up to 80 characters long, say) is as follows: (Id1):(Name1),(Id2):(Name2), ... , (IdN):(NameN) where (Id) is a single digit and (Name) is a string of up to 30 characters A-Z & spaces. The Id aren't necessarily in numerical order in the text, but the Id sought for must appear somewhere within the text. Example: suppose the user supplies to the program these Id and these texts to scan (all identical for this particular example): Id = 1, Text = "2:Yoda,1:Luke Skywalker,5:Obi Wan Kenobi,3:Darth Vader,4:R2D2" Output: Luke Skywalker Id = 5, same text as before Output: Obi Wan Kenobi Id = 2, same text as before Output: Yoda Id = 4, same text as before Output: R2D2 Id = 3, same text as before Output: Darth Vader Requirements: - the shorter the better - it must run in a barebones HP-71B (no ROM/LEX files allowed) - it must use no variables at all and no PEEK/POKE either Sounds familiar, uh ? I'll post my original solution, which is a 2-line program (74 bytes). Step the Sixth: We'll call a "Selfie" to any positive N-digit integer number which has the property that if you sum its N digits raised to the Nth power you get the original number backwards. For instance, the 7-digit number 5271471 is a Selfie: 5271471 => 5\(^7\) + 2\(^7\) + 7\(^7\) + 1\(^7\) + 4\(^7\) + 7\(^7\) + 1\(^7\) = 1741725, which is 5271471 backwards Write a program to find all Selfies from 1 to 9 digits long (for 10-digit HP calcs, 29 in all) or from 1 to 11 digits long (for 12-digit HP calcs, 37 in all). 0 is not a positive number so it's not a Selfie. Requirements: - the faster and shorter (in that order), the better I'll post my original solution for the HP-71B, an 11-line program (398 bytes) which, when run in Emu71, finds in 3'20" all 37 Selfies up to 11 digits long. I'll also post a 12-line version which is 20% faster, in particular it finds all 11-digit Selfies in just over 80 seconds. That's it, young padawan, your Ordeal has come to an end. I'll post my original solutions next Thursday so you've got plenty of time to develop your own. If you succeed in completing the 6 Steps you will become the Most Honored 71st Jedi Knight. May the 4th Be With You !! Regards. V. . All My Articles & other Materials here: Valentin Albillo's HP Collection |
|||
« Next Oldest | Next Newest »
|
User(s) browsing this thread: 1 Guest(s)