I have solved Project Euler Problem 3, but the thing is that I am not able to create the function in awk.
I have tried this working code (without function):
#!/usr/bin/awk -f
BEGIN{
n=600851475143;
x=2; # minimal prime
while ( x<n ) {
if ( (n%x) == 0 ) {
n = n/x
print n
} else { # if n not divisible then increment x+1
x++
}
}
}
Not working with the function
#!/usr/bin/awk -f
# The prime factors of 13195 are 5, 7, 13 and 29.
# What is the largest prime factor of the number 600851475143 ?
function get.PrimeFactor(n) {
x=2; # minimal prime
while ( x<n ) {
if ( (n%x) == 0 ) {
n = n/x
print n
}
else { # if n not divisible then increment x+1
x++
}
}
BEGIN {
n = $1 # input number by user
get.PrimeFactor(n)
}
I have tried several ways to work with the function but no luck.
Can anyone highlight what I'm doing wrong?