TPK algorithm: Difference between revisions

Content deleted Content added
Pascal: The ISO 7185 standard requires constant, variable, and function declarations to follow in this order, and program parameters to be present if I/O procedures are used on them. Also, fix a few useless semicolons.
No edit summary
Line 236:
eval { say f($_) } or say "Problem with entry $_: $@"
}
</source>
 
===[[Groovy (programming language)|Groovy]]===
<source lang="Groovy">
int groovN = 11;
double[] grooVals = new double[groovN];
 
// declare function fanAND - fan-out function which has an AND to ensure positive value prior to taking square root
double fanAND(double x) {
if( (x >= -1) && ((Math.abs(x) + 5 * Math.pow(x,3)) > 0))
return(Math.sqrt( Math.abs(x) + 5 * Math.pow(x,3) ) );
else
return 0;
}
 
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
String userInput = br.readLine();
 
Scanner s = new Scanner(userInput);
for(int ii = 0; ii < groovN; ii++) {
grooVals[groovN - ii - 1] = s.nextDouble();
}
 
s.close();
 
for(int ii = 0; ii < groovN; ii++) {
Double calcVal = fanAND(grooVals[ii]);
if(calcVal.isInfinite())
println("TOO LARGE");
else
println(calcVal);
}
 
</source>