Scripts
global
prime
power
newtonraphson
fibonacci
file
multithread
digitcubes
perfectseries
perfecttest
kapreckerNumber
kapreckerConstant
hawkresponse
entityTemplate
array
multipleAssignment
global
prime
power
newtonraphson
fibonacci
file
multithread
digitcubes
perfectseries
perfecttest
kapreckerNumber
kapreckerConstant
hawkresponse
entityTemplate
array
multipleAssignment
function main()
{
echo "finding 6 perfect numbers"
//This gets resolved in compilation time
exec findPerfectNumber(6)
}
function findPerfectNumber(var count)
{
var n = 1
for(var i =2 ; i>= 1 ; i= i+1)
{
var j = i-1
var product = `exec power(2,j)`
var primeSuspect = product*2 -1
if( `exec checkPrime(primeSuspect)` == 1)
{
var perfect = product * primeSuspect
echo "Perfect no {"+perfect+"}"
n = n+1
}
if(n > count )
{
return 1
}
}
}
function power(var x , var y)
{
if(y == 0)
{
return 1
}
var product = x
for(var i=1;i
product = product * x
}
return product
}
//This checks if a number is prime or not
function checkPrime(var x)
{
for(var i=2; i<`exec calculateSquareRoot(x)`;i=i+1)
{
if( x%i == 0)
{
return 0
}
}
return 1
}
function calculateSquareRoot(var x)
{
var y = 0
//This gets evaluated in interpretation phase
y = `exec sqrt(x)`
return y
}
finding 6 perfect numbers
Perfect no {6}
Perfect no {28}
Perfect no {496}
Perfect no {8128}
Perfect no {33550336}
Perfect no {8.589869056E9}
Perfect no {6}
Perfect no {28}
Perfect no {496}
Perfect no {8128}
Perfect no {33550336}
Perfect no {8.589869056E9}