Post Reply 
[VA] Short & Sweet Math Challenges #23: "May the 4th Be With You !" Special
05-08-2018, 04:16 PM
Post: #6
RE: [VA] Short & Sweet Math Challenges #23: "May the 4th Be With You !" ...
(05-04-2018 09:39 PM)Valentin Albillo Wrote:  Step the Third:
... you don't have to write a program but instead solve right from the command line the following equation ...
...
      - you can execute more than one command line in succession if need be
      - you can't run, call or use any program code whatsoever

The requirements put strong constraints on a possible solution:
the command line is limited to 96 characters,
FNROOT is not useable here (unless I missed something...),
it is very difficult (or impossible) to make a loop from the keyboard command line and include tests in it.
So I chose a dichotomic search (with a trick to avoid a test in the loop).
It's easy to find the maximum number of dichotomic steps needed, so no need of a termination test.

Here is my solution in two command lines and about 100 characters:
the first line initializes an array with two values defining an interval where the root is for sure:
DESTROY A @ A(0)=-1 @ A(1)=49

the second line drives a basic dichotomic search:
FOR J=1 TO 46 @ X=(A(0)+A(1))/2 @ S=0 @ FOR I=1 TO 100 @ S=S+SQR(X+I)-7 @ NEXT I @ A(S>0)=X @ NEXT J
(spaces added only for readability, don't type them in order to fit in a 96-char line).

The result is in X:
>X
3.28838856026


Any better/shorter/clever solution?

J-F
Visit this user's website Find all posts by this user
Quote this message in a reply
Post Reply 


Messages In This Thread
RE: [VA] Short & Sweet Math Challenges #23: "May the 4th Be With You !" ... - J-F Garnier - 05-08-2018 04:16 PM



User(s) browsing this thread: 5 Guest(s)