THE PUZZLET PAGE

 Functions and subroutines used in the Puzzlets are discussed here, with explanations of how they work and why they were designed this way. Just what is the difference between a function and a subroutine? A subroutine is a separate piece of code you can call to do a job and then carry on where you left off. A function is a subroutine, but has the additional feature that it can return a value to the routine that called it. So a function designed, say, to find the average of three integers, might be called like this: ave = Average(a, b, c) The name of the function is Average().  The parameters passed to the function are a, b, and c.  The function returns a value, which in this case is (a + b + c)/3, and the result is stored in variable ave. Finally, note that what you pass to a function or subroutine are called parameters. What a function or subroutine receives from the calling routine are known as arguments - the same as parameters, but known differently by sender and receiver. Note: some of these functions have been improved and otherwise matured since the earlier Puzzlets were published. If you want more information on an older version, please follow the e-mail link below. Click on an item to view it (they're listed alphabetically):

 Title Description AllCharsDiff() Checks every character of the argument to see if they're all different to each other. AllDiffBy2() Checks every digit of the argument differs from its neighbours by exactly 2, such as 31357, etc. AllDigitsDifferent() Checks that each digit of the argument is unique, such as 31254, 97561, etc.  No longer recommended: use AddCharsDiff() instead (it's faster). AllDigitsEven() Checks that each digit of the argument is even, such as 22482, 6824, etc. AllDigitsOdd() Checks that each digit of the argument is odd, such as 11371, 5937, etc. AllDigitsSame() Checks that each digit of the argument is unique, such as 222, 5555555, etc. Anagrams() Checks that one the arguments is an anagram of the other.  Fast, but only works for integer arguments.  For other character mixes, see function IsAnagram(). Bin2Dec() Converts the argument from a binary number in string format to a denary integer. ChangeBase() Converts the first argument from a denary integer to the number base indicated by the second argument, with the output in string format. Cont_Dig_Sum() Obtains the argument's CDS (Contiguous Digit Sum, the sum of all the smaller integers that can be formed from it, using only contiguous digits). For example, CDS(8358) is 1393, the sum of 8,83,835,3,35,358,5,58,8. CountPrimeFactors() Counts the prime factors of its argument and returns the number of factors (not the factors themselves) to the calling routine. Dec2Bin() Converts the argument from a denary integer to a binary number in string format. Dec2Oct() Converts the argument from a denary integer to an octal number in string format. Factorial() Returns the factorial of its argument.  Thus argument 6 returns 6! = 720. FinalDigitProduct() Finds the single digit resulting from repeated multiplying of its arugment's digits together. GetNextPrime() Finds the prime number whose value is closest to (but greater than) its argument and returns it to the calling routine. Hex2Dec() Converts a hexadecimal argument to denary format and returns it to the calling routine. Is9Pandigital() Checks that argument uses every digit 1 to 9 inclusive once and once only. Is10Pandigital() Checks that argument uses every digit 0 to 9 inclusive once and once only. IsAbundant() Checks that argument is an Abundant Number. IsAchillesNr() Checks that the argument is an Achilles number, that is, it's not a square and each of its prime factors occur at least twice. IsAnagram() Checks that one argument is an anagram of the other. Works for any kind of characters. IsAPower() Checks that the argument is a power of some smaller digit.  Returns the root or, if it's not a power, 0. IsASquare() Checks that argument is a perfect square, such as 625, 1000, etc. IsDigNum() Checks that  argument can be divided by both product and sum of its own digits, such as 36, 8112, etc. IsDownOrdered() Checks that argument's digits are arranged in descending order, such as 9862, 87551, etc. IsForwardRun() Checks that argument's digits are arranged in consecutive, ascending order, such as 234, 12, 45678, etc. IsOddAbundant() Checks that the argument is an odd Abundant Number. IsPalidrome() Checks that argument's digits are palindromic, such as 232, 9445449, 1551, etc. IsPrime() Checks that argument is a prime number (that is, divisible only by itself and 1), such as 7, 71, etc. IsReverseRun() Checks that argument's digits are arranged in consecutive, descending order, such as 432, 21, 87654, etc. IsUpOrdered() Checks that argument's digits are arranged in ascending order, such as 2689, 23669, etc. MaxInt() Returns the greatest-value digit of the argument. MinInt() Returns the least-value digit of the argument. NoDigitsIncluded() Checks that none of the digits in its first argument are included in its second argument. NoZeroes() Checks that none of argument's digits are equal to zero, such as 24413, 98, etc. PrintPrimeFactors() Prints out the prime factors of its argument in ascending order. PrimeFactorSum() Returns the sum of the prime factors of its argument. ProdNumericStrings() Pass two integers in string format to this function and it will return the product of the two integers in string format , up to 256 digits in length. ProductDigits() Returns the product of argument's digits. Thus, 24 returns 8, 5127 returns 70, etc. RemoveTrailingZeroes() Returns the argument with any trailing zeroes removed. Thus, "356700" is returned as "3567" etc. Reverse() Returns the reverse of its argument. So 98761 returns 16789, 25 returns 52, etc. ReverseString() Returns the reverse of its argument. So "25" returns "52", "abc" returns "cba", etc. SumDigits() Returns the sum of argument's digits. Thus, 24 returns 6, 7189 returns 25, etc. SumFactorials() Returns the sum of the factorials of the digits of its argument.  253 returns 2! + 5! + 3! = 128. SumPowers() Returns sum of powers of arguments digits in position order, so 543 returns 5^1 + 4^2 + 3^3 = 48, and so on. SumSquares() Returns the sum of the squares of the digits of its argument.  253 returns 22 + 52 + 32 = 38.