[OT, multi-posted to comp.programming] Mystery program...

  • Thread starter Alf P. Steinbach
  • Start date
A

Alf P. Steinbach

Well, nobody answered in [comp.programming] -- has that group died in the last
few months? -- so I'm reposting here in clc++.

In my high-school "electronic data processing" text book from 1974 I found an
"explain what this program does" exercise that I don't quite grok now.

It's exercise 4.25 from page 72 of "EDB for videregående skoler" by Gram, Hope
and Ommundsen, NKS-forlaget 1974.

Here's the program translated from its original Basic to JavaScript (I'm
assuming the Windows Script Host for i/o, and if you have Windows simply copy
this text to a [.js] file and run it via e.g. 'cscript' command):


<code>
lineNum_ = 0

function input()
{
WScript.stdout.write( "? " );
var s = WScript.stdin.readLine();
return parseFloat( s );
}

function print( v )
{
WScript.stdout.writeLine( v );
}

function goto( new_n )
{
lineNum_ = new_n - 1
}

function end()
{
print( "FINISHED!" )
WScript.Quit()
}

function onStatementExecuted( lineNum )
{
//print( "lineNum="+lineNum + ", n="+n + ", m="+m + ", p="+p + ", p2="+p2 )
}

m = null
n = null
p = null
p2 = null

for( ;; )
{
lineNum_ += 1
if( lineNum_ > 99999 )
{
print( "!Program execution beyond last statement." );
WScript.Quit( -1 );
}

var executedLineNum = lineNum_
var didSmth = true
switch( lineNum_ )
{
case -1:

// BEGIN translation of original code:
break; case 30: m = 1
break; case 40: n = input()
break; case 50: p2 = n
break; case 60: p = p2 - 2*m
break; case 70: p2 = p
break; case 80: m = m + 1
break; case 90: if( p < m ) goto( 140 )
break; case 100: p = p - m
break; case 110: if( p > 0 ) goto( 100 )
break; case 120: if( p == 0 ) goto( 160 )
break; case 130: if( p2 > 2*m ) goto( 60 )
break; case 140: print( "n=" + n );
break; case 150: goto( 170 )
break; case 160: print( "m=" + m )
break; case 170: end()
// END translation of original code

break; default:
didSmth = false
}

if( didSmth )
{
onStatementExecuted( executedLineNum )
}
}
</code>

The exercise's part (a) recommends trying out the program "on paper" (noting
down values of variables) for n = 3, 10 and 28, and for part (b) it recommends
running the program and trying n = 2, 14, 22, 36 and 39.

OK, I can see that there's apparently a computation of remainder in there, but
it's not exactly meaningful to me.

I'm probably just blind on both eyes, but any help appreciated.


Cheers,

- Alf
 
P

Puppet_Sock

On May 2, 2:43 pm, "Alf P. Steinbach" <alf.p.steinbach
(e-mail address removed)>
[java question snipped]
I'm probably just blind on both eyes, but any help appreciated.

Here's some pretty obvious help.

Find a java news group for java questions.
Socks
 
A

Alf P. Steinbach /Usenet

* The sock puppet called "Puppet_Sock", on 02.05.2011 20:44:
On May 2, 2:43 pm, "Alf P. Steinbach"<alf.p.steinbach
(e-mail address removed)>
[java question snipped]
I'm probably just blind on both eyes, but any help appreciated.

Here's some pretty obvious help.

Find a java news group for java questions.
Socks

heads-up: both your programming language recognition circuit and your english
parsing circuit are apparently broken

i don't think a "java" (programming language) group would help

the code is in a language called "basic", translated to another programming
language called "javascript", neither of which are more similar to "java" than
to e.g. "c++"


cheers & hth.,

- Alf
 
P

Paul N

Well, nobody answered in [comp.programming] -- has that group died in thelast
few months? -- so I'm reposting here in clc++.

In my high-school "electronic data processing" text book from 1974 I found an
"explain what this program does" exercise that I don't quite grok now.

Partial answer given in comp.programming. Sorry for the delay...
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,768
Messages
2,569,574
Members
45,049
Latest member
Allen00Reed

Latest Threads

Top