Perfect digit-to-digit invariant
In number theory, a perfect digit-to-digit invariant (PDDI; also known as a Munchausen number) is a natural number in a given number base formula_1 that is equal to the sum of its digits each raised to the power of itself. An example in base 10 is 3435, because formula_2. The term "Munchausen number" was coined by Dutch mathematician and software engineer Daan van Berkel in 2009, as this evokes the story of Baron Munchausen raising himself up by his own ponytail because each digit is raised to the power of itself. Definition. Let  formula_3 be a natural number which can be written in base formula_1 as the k-digit number formula_5 where each digit formula_6 is between formula_7 and formula_8 inclusive, and formula_9. We define the function formula_10 as formula_11. (As 0 is usually undefined, there are typically two conventions used, one where it is taken to be equal to one, and another where it is taken to be equal to zero.) A natural number formula_3 is defined to be a perfect digit-to-digit invariant in base b if formula_13. For example, the number 3435 is a perfect digit-to-digit invariant  in base 10 because formula_14. formula_15 for all formula_1, and thus 1 is a "trivial" perfect digit-to-digit invariant in all bases, and all other perfect digit-to-digit invariants are "nontrivial". For the second convention where formula_17, both formula_7 and formula_19 are trivial perfect digit-to-digit invariants. A natural number formula_3 is a "sociable" digit-to-digit invariant if it is a periodic point for formula_21, where formula_22 for a positive integer formula_23, and forms a cycle of period formula_23. A perfect digit-to-digit invariant is a sociable digit-to-digit invariant with formula_25. An "amicable  digit-to-digit invariant is a sociable digit-to-digit invariant with formula_26. All natural numbers formula_3 are preperiodic points for formula_28, regardless of the base. This is because all natural numbers of base formula_1 with formula_23 digits satisfy formula_31. However, when formula_32, then formula_33, so any formula_3 will satisfy formula_35 until formula_36. There are a finite number of natural numbers less than formula_37, so the number is guaranteed to reach a periodic point or a fixed point less than formula_37, making it a preperiodic point. This means also that there are a finite number of perfect digit-to-digit 	Perfect digit-to-digit invariant
21729198	invariant and cycles for any given base formula_1. The number of iterations formula_40 needed for formula_41 to reach a fixed point is the formula_1-factorion function's persistence of formula_3, and undefined if it never reaches a fixed point. Perfect digit-to-digit invariants and cycles of F for specific b. All numbers are represented in base formula_1. Programming examples. Python. The following program in Python determines whether an integer number is a Munchausen Number / Perfect Digit to Digit Invariant or not, following the convention formula_45. num = int(input(Enter number:")) temp = num s = 0.0 while num > 0 : if s == temp: else: The examples below implements the perfect digit-to-digit invariant function described in the definition above to search for perfect digit-to-digit invariants and cycles in Python for the two conventions. Convention 0 = 1. def pddif(x: int, b: int) -> int: def pddif_cycle(x: int, b: int) -> List[int]: Convention 0 = 0. def pddif(x: int, b: int) -> int: def pddif_cycle(x: int, b: int) -> List[int]: Java. The following program in Java determines whether an integer number is a Munchausen Number / Perfect Digit to Digit Invariant or not, following the convention formula_45 . import java.util.Scanner; public class Munchausen