TPK algorithm: Difference between revisions

Content deleted Content added
Rewritten the Groovy implementation
Line 92:
return 0;
}
</source>
 
 
===[[Groovy (programming language)|Groovy]]===
<source lang="Groovy">
def grooVals = []
Scannerdef sscanner = new Scanner(userInputSystem.in);
11.times {
grooVals[groovN - ii - 1] =<< sscanner.nextDouble();
grooVals = grooVals.reverse()
for (val in grooVals) {
def calcVal = return(Math.sqrt( Math.abs(xval)) + 5 * Math.pow(x,val**3) ) );
if (calcVal.isInfinite())
println(" 'TOO LARGE");'
else
println( calcVal);
}
</source>
 
Line 236 ⟶ 254:
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>