Well, here's a difficult problem that I haven't the creativity to find the solution to...yet. Say for example that "ABCD" is in Str1 and there is a prgm as follows:
Code:
For example, if 666 is the value inputed for Z and 3 for N, then 666 will be stored to C (third letter in Str1).
I'm looking for a space optimization here. I know you can just do:
Code:
But all that is just for being able to select A through D; if I wanted to go up to Z, think of the amount of lines I'd have to add.
I've encountered this problem a couple times before and just encountered it again when making a Hess' Law (enthalpy changes) program. I think such a tool would be useful in the programmers bag of tricks. Oh yeah, and no assembly allowed. Kudos to anyone who can solve this possibly impossible problem.
I tried an approach like:
Code:
Unfortunately unlike doing a manual solve, the variable isn't updated to the solved value and all that happens is Z is stored to Ans. Sigh.
Btw, for the recent contest I didn't get around to fixing up my prgm to a state where I thought it would be exceptional. It involved the Riemann Zeta function but I'll leave it at that. Post-contest a RAM clear got rid of it, but it's okay, it isn't too difficult to remake. Whenever a math prgming contest comes around...
Code:
:"ABCD->Str1
:Prompt Z,N
:sub(Str1,N,1
:Some algorithm to store the value of Z into the Nth variable in Str1
For example, if 666 is the value inputed for Z and 3 for N, then 666 will be stored to C (third letter in Str1).
I'm looking for a space optimization here. I know you can just do:
Code:
:If N=1
:Then:Z->A
:Else:If N=2
:Then:Z->B
:Else:If N=3
:Then:Z->C
:Else:Z->D
:End
:End
:End
But all that is just for being able to select A through D; if I wanted to go up to Z, think of the amount of lines I'd have to add.
I've encountered this problem a couple times before and just encountered it again when making a Hess' Law (enthalpy changes) program. I think such a tool would be useful in the programmers bag of tricks. Oh yeah, and no assembly allowed. Kudos to anyone who can solve this possibly impossible problem.
I tried an approach like:
Code:
:sub(Str1,N,1
:expr("solve(Z-"+Ans+","+Ans+",0"
Unfortunately unlike doing a manual solve, the variable isn't updated to the solved value and all that happens is Z is stored to Ans. Sigh.
Btw, for the recent contest I didn't get around to fixing up my prgm to a state where I thought it would be exceptional. It involved the Riemann Zeta function but I'll leave it at that. Post-contest a RAM clear got rid of it, but it's okay, it isn't too difficult to remake. Whenever a math prgming contest comes around...