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 number = 6174
var count = 0
exec findKapreckerConstant(number , count)
number = 8765
count = 0
exec findKapreckerConstant(number , count)
number = 3124
count = 0
exec findKapreckerConstant(number , count)
number = 1986
count = 0
exec findKapreckerConstant(number , count)
number = 7634
count = 0
exec findKapreckerConstant(number , count)
number = 2913
count = 0
exec findKapreckerConstant(number , count)
}
function findKapreckerConstant(var number , var count)
{
echo " number is " + number
echo " count is " + count
var ascDigits [] = `exec sortDigits(number)`
echo ascDigits
var descDigits [] = new var []
var len = `exec length(ascDigits)`
for(var i = 1 ; i <=len ; i = i+1 )
{
var x = ascDigits [len -i +1]
descDigits [i] = x
}
echo descDigits
var num1 = `exec createNumber(ascDigits)`
var num2 = `exec createNumber(descDigits)`
echo num2
echo num1
var diff = num2 - num1
echo diff
if ( diff == number )
{
var tmpCount = count +1
echo "Found kaprecker constant after {"+ tmpCount+ "} iteration(s)"
}
else
{
echo "testing again for "+ diff
exec findKapreckerConstant(diff, count +1)
}
}
function createNumber ( var digits[])
{
var sum = 0
var len = `exec length(digits)`
for(var i = 1 ; i <=len ; i = i+1 )
{
sum = sum + digits[i] * `exec pow(10,len -i)`
}
return sum
}
function sortDigits(var number)
{
var digits [] = `exec splitNumberIntoArray(number)`
exec sort(digits)
return 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] = result[j]
result[j] = a
}
return result
}
{
var number = 6174
var count = 0
exec findKapreckerConstant(number , count)
number = 8765
count = 0
exec findKapreckerConstant(number , count)
number = 3124
count = 0
exec findKapreckerConstant(number , count)
number = 1986
count = 0
exec findKapreckerConstant(number , count)
number = 7634
count = 0
exec findKapreckerConstant(number , count)
number = 2913
count = 0
exec findKapreckerConstant(number , count)
}
function findKapreckerConstant(var number , var count)
{
echo " number is " + number
echo " count is " + count
var ascDigits [] = `exec sortDigits(number)`
echo ascDigits
var descDigits [] = new var []
var len = `exec length(ascDigits)`
for(var i = 1 ; i <=len ; i = i+1 )
{
var x = ascDigits [len -i +1]
descDigits [i] = x
}
echo descDigits
var num1 = `exec createNumber(ascDigits)`
var num2 = `exec createNumber(descDigits)`
echo num2
echo num1
var diff = num2 - num1
echo diff
if ( diff == number )
{
var tmpCount = count +1
echo "Found kaprecker constant after {"+ tmpCount+ "} iteration(s)"
}
else
{
echo "testing again for "+ diff
exec findKapreckerConstant(diff, count +1)
}
}
function createNumber ( var digits[])
{
var sum = 0
var len = `exec length(digits)`
for(var i = 1 ; i <=len ; i = i+1 )
{
sum = sum + digits[i] * `exec pow(10,len -i)`
}
return sum
}
function sortDigits(var number)
{
var digits [] = `exec splitNumberIntoArray(number)`
exec sort(digits)
return 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] = result[j]
result[j] = a
}
return result
}
number is6174
count is0
[1, 4, 6, 7]
[7, 6, 4, 1]
7641
1467
6174
Found kaprecker constant after {1} iteration(s)
number is8765
count is0
[5, 6, 7, 8]
[8, 7, 6, 5]
8765
5678
3087
testing again for3087
number is3087
count is1
[0, 3, 7, 8]
[8, 7, 3, 0]
8730
378
8352
testing again for8352
number is8352
count is2
[2, 3, 5, 8]
[8, 5, 3, 2]
8532
2358
6174
testing again for6174
number is6174
count is3
[1, 4, 6, 7]
[7, 6, 4, 1]
7641
1467
6174
Found kaprecker constant after {4} iteration(s)
number is3124
count is0
[1, 2, 3, 4]
[4, 3, 2, 1]
4321
1234
3087
testing again for3087
number is3087
count is1
[0, 3, 7, 8]
[8, 7, 3, 0]
8730
378
8352
testing again for8352
number is8352
count is2
[2, 3, 5, 8]
[8, 5, 3, 2]
8532
2358
6174
testing again for6174
number is6174
count is3
[1, 4, 6, 7]
[7, 6, 4, 1]
7641
1467
6174
Found kaprecker constant after {4} iteration(s)
number is1986
count is0
[1, 6, 8, 9]
[9, 8, 6, 1]
9861
1689
8172
testing again for8172
number is8172
count is1
[1, 2, 7, 8]
[8, 7, 2, 1]
8721
1278
7443
testing again for7443
number is7443
count is2
[3, 4, 4, 7]
[7, 4, 4, 3]
7443
3447
3996
testing again for3996
number is3996
count is3
[3, 6, 9, 9]
[9, 9, 6, 3]
9963
3699
6264
testing again for6264
number is6264
count is4
[2, 4, 6, 6]
[6, 6, 4, 2]
6642
2466
4176
testing again for4176
number is4176
count is5
[1, 4, 6, 7]
[7, 6, 4, 1]
7641
1467
6174
testing again for6174
number is6174
count is6
[1, 4, 6, 7]
[7, 6, 4, 1]
7641
1467
6174
Found kaprecker constant after {7} iteration(s)
number is7634
count is0
[3, 4, 6, 7]
[7, 6, 4, 3]
7643
3467
4176
testing again for4176
number is4176
count is1
[1, 4, 6, 7]
[7, 6, 4, 1]
7641
1467
6174
testing again for6174
number is6174
count is2
[1, 4, 6, 7]
[7, 6, 4, 1]
7641
1467
6174
Found kaprecker constant after {3} iteration(s)
number is2913
count is0
[1, 2, 3, 9]
[9, 3, 2, 1]
9321
1239
8082
testing again for8082
number is8082
count is1
[0, 2, 8, 8]
[8, 8, 2, 0]
8820
288
8532
testing again for8532
number is8532
count is2
[2, 3, 5, 8]
[8, 5, 3, 2]
8532
2358
6174
testing again for6174
number is6174
count is3
[1, 4, 6, 7]
[7, 6, 4, 1]
7641
1467
6174
Found kaprecker constant after {4} iteration(s)
count is0
[1, 4, 6, 7]
[7, 6, 4, 1]
7641
1467
6174
Found kaprecker constant after {1} iteration(s)
number is8765
count is0
[5, 6, 7, 8]
[8, 7, 6, 5]
8765
5678
3087
testing again for3087
number is3087
count is1
[0, 3, 7, 8]
[8, 7, 3, 0]
8730
378
8352
testing again for8352
number is8352
count is2
[2, 3, 5, 8]
[8, 5, 3, 2]
8532
2358
6174
testing again for6174
number is6174
count is3
[1, 4, 6, 7]
[7, 6, 4, 1]
7641
1467
6174
Found kaprecker constant after {4} iteration(s)
number is3124
count is0
[1, 2, 3, 4]
[4, 3, 2, 1]
4321
1234
3087
testing again for3087
number is3087
count is1
[0, 3, 7, 8]
[8, 7, 3, 0]
8730
378
8352
testing again for8352
number is8352
count is2
[2, 3, 5, 8]
[8, 5, 3, 2]
8532
2358
6174
testing again for6174
number is6174
count is3
[1, 4, 6, 7]
[7, 6, 4, 1]
7641
1467
6174
Found kaprecker constant after {4} iteration(s)
number is1986
count is0
[1, 6, 8, 9]
[9, 8, 6, 1]
9861
1689
8172
testing again for8172
number is8172
count is1
[1, 2, 7, 8]
[8, 7, 2, 1]
8721
1278
7443
testing again for7443
number is7443
count is2
[3, 4, 4, 7]
[7, 4, 4, 3]
7443
3447
3996
testing again for3996
number is3996
count is3
[3, 6, 9, 9]
[9, 9, 6, 3]
9963
3699
6264
testing again for6264
number is6264
count is4
[2, 4, 6, 6]
[6, 6, 4, 2]
6642
2466
4176
testing again for4176
number is4176
count is5
[1, 4, 6, 7]
[7, 6, 4, 1]
7641
1467
6174
testing again for6174
number is6174
count is6
[1, 4, 6, 7]
[7, 6, 4, 1]
7641
1467
6174
Found kaprecker constant after {7} iteration(s)
number is7634
count is0
[3, 4, 6, 7]
[7, 6, 4, 3]
7643
3467
4176
testing again for4176
number is4176
count is1
[1, 4, 6, 7]
[7, 6, 4, 1]
7641
1467
6174
testing again for6174
number is6174
count is2
[1, 4, 6, 7]
[7, 6, 4, 1]
7641
1467
6174
Found kaprecker constant after {3} iteration(s)
number is2913
count is0
[1, 2, 3, 9]
[9, 3, 2, 1]
9321
1239
8082
testing again for8082
number is8082
count is1
[0, 2, 8, 8]
[8, 8, 2, 0]
8820
288
8532
testing again for8532
number is8532
count is2
[2, 3, 5, 8]
[8, 5, 3, 2]
8532
2358
6174
testing again for6174
number is6174
count is3
[1, 4, 6, 7]
[7, 6, 4, 1]
7641
1467
6174
Found kaprecker constant after {4} iteration(s)