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 ()
{
var range = 1000
exec testKapreckerRange(range)
}
function testKapreckerRange(var range)
{
for(var i = 1 ; i < range; i = i+1)
{
var result = `exec testKaprecker(i)`
if ( result == 1)
{
echo i + " is a kaprecker number!!!"
}
}
}
function testKaprecker(var number)
{
var n = `exec countDigits(number)`
var squareNum = `exec pow(number,2)`
squareNum = `exec ceil(squareNum)`
var squareDigits [] = `exec splitNumberIntoArray(squareNum)`
exec reverse(squareDigits)
var sum1 = 0
for(var i = 1 ; i <= n ; i=i+1)
{
var j = i-1
var tmp = `exec pow(10,j)`
sum1 = sum1 + squareDigits[i] * tmp
}
var len = `exec length(squareDigits)`
var sum2 = 0
var k = 0
for(var i = n+1 ; i <= len ; i=i+1)
{
var tmp = `exec pow(10,k)`
k = k+1
sum2 = sum2 + squareDigits[i] * tmp
}
var sum = sum1+sum2
if ( sum == number)
{
return 1
}
else
{
return 0
}
}
function countDigits(var number)
{
var digits [] = `exec splitNumberIntoArray(number)`
return `exec length(digits)`
}
function splitNumberIntoArray(var number)
{
var result [] = new var[]
var i = 1
do
{
var x = number%10
result [i] = x
number = number /10
number = `exec floor(number)`
i = i+1
}
while(number > 0 )
result = `exec reverse(result)`
return result
}
function reverse( var result[])
{
var len = `exec length(result)`
var mid = `exec ceil(len /2)`
for(var i =1 ; i <= mid ; i = i+1)
{
var j = len - i +1
var a = result [i]
var b = result[j]
result[i] = b
result[j] = a
}
return result
}
{
var range = 1000
exec testKapreckerRange(range)
}
function testKapreckerRange(var range)
{
for(var i = 1 ; i < range; i = i+1)
{
var result = `exec testKaprecker(i)`
if ( result == 1)
{
echo i + " is a kaprecker number!!!"
}
}
}
function testKaprecker(var number)
{
var n = `exec countDigits(number)`
var squareNum = `exec pow(number,2)`
squareNum = `exec ceil(squareNum)`
var squareDigits [] = `exec splitNumberIntoArray(squareNum)`
exec reverse(squareDigits)
var sum1 = 0
for(var i = 1 ; i <= n ; i=i+1)
{
var j = i-1
var tmp = `exec pow(10,j)`
sum1 = sum1 + squareDigits[i] * tmp
}
var len = `exec length(squareDigits)`
var sum2 = 0
var k = 0
for(var i = n+1 ; i <= len ; i=i+1)
{
var tmp = `exec pow(10,k)`
k = k+1
sum2 = sum2 + squareDigits[i] * tmp
}
var sum = sum1+sum2
if ( sum == number)
{
return 1
}
else
{
return 0
}
}
function countDigits(var number)
{
var digits [] = `exec splitNumberIntoArray(number)`
return `exec length(digits)`
}
function splitNumberIntoArray(var number)
{
var result [] = new var[]
var i = 1
do
{
var x = number%10
result [i] = x
number = number /10
number = `exec floor(number)`
i = i+1
}
while(number > 0 )
result = `exec reverse(result)`
return result
}
function reverse( var result[])
{
var len = `exec length(result)`
var mid = `exec ceil(len /2)`
for(var i =1 ; i <= mid ; i = i+1)
{
var j = len - i +1
var a = result [i]
var b = result[j]
result[i] = b
result[j] = a
}
return result
}
1is a kaprecker number!!!
9is a kaprecker number!!!
45is a kaprecker number!!!
55is a kaprecker number!!!
99is a kaprecker number!!!
297is a kaprecker number!!!
703is a kaprecker number!!!
999is a kaprecker number!!!
9is a kaprecker number!!!
45is a kaprecker number!!!
55is a kaprecker number!!!
99is a kaprecker number!!!
297is a kaprecker number!!!
703is a kaprecker number!!!
999is a kaprecker number!!!