It's a bit unclear to me what you mean by
"problem where there are an N amount of power values in the range of 1-9 and the
last number has to be found". Is this to say you're dealing with a power tower
of integers in the range 1-9?
In any case, to find the last digit of $9^{4^{2^{3^5}}}$, we want to "reduce it
mod $10$". First, some notation.
\begin{equation*}
a \equiv b \pmod{10}
\end{equation*}
means that "$a$ is congruent to $b$ modulo $10$". This means that they differ by
a multiple of $10$, or equivalently, they leave the same remainder when divided
by $10$. Hopefully you agree that if some integer
\begin{equation*}
n \equiv 3 \pmod{10}
\end{equation*}
then the last digit of $n$ must be $3$.
Now, we also have that if $a \equiv b \pmod{10}$ and $c \equiv d \pmod{10}$,
then $ac \equiv bd \pmod{10}$. Maybe this is obvious to you already, if not, you
can prove it from the "differ by a multiple of $10$" definition. Using this,
any power of $9$ is congruent to $-1$ raised to that same exponent. So
\begin{equation*}
9^{4^{2^{3^5}}} \equiv (-1)^{4^{2^{3^5}}} \pmod{10}
\end{equation*}
But the value of $(-1)^{4^{2^{3^5}}}$ just depends on whether
$4^{2^{3^5}}$ is even or odd. Since this is some power of $4$, which is even,
it is clearly even (since it is not $4^0$), so $(-1)^{4^{2^{3^5}}} = 1$, so the
last digit of $9^{4^{2^{3^5}}}$ is $1$.
An alternative approach would just be to look at powers of $9$ mod $10$, and
notice that they are congruent to $1$, $9$, $1$, $9$, ... and take it from
there.
To generalise this approach for some kind of program requires looking at the
periodicity of the powers of the base modulo $10$, and then recursing into the
power tower to reduce the subtower modulo the period of the powers of the base.
(Particularly, not all numbers are as nice as $9$, which only has period $2$)
Proof of $a \equiv b \pmod{10}$ and
$c \equiv d \pmod{10} \implies ac \equiv bd \pmod{10}$.
Have $a = b + 10n$, $c = d + 10m$ for some $n, m \in \mathbb Z$ by definition..
Then
\begin{align*}
ac
&= (b + 10n)(d + 10n) \\
&= bd + 10(n + m + 10nm) \\
&\equiv bd \pmod{10} \quad \text{by definition}
\end{align*}
Proof of $a \equiv b \pmod{10} \implies a^n \equiv b^n \pmod{10}$:
The base case $n = 0$ is trivially true. Then
\begin{align*}
a^{n + 1}
&\equiv a \cdot a^n \\
&\equiv b \cdot a^n \quad \text{by assumption} \\
&\equiv b \cdot b^n \quad \text{by inductive hypothesis} \\
&\equiv b^{n + 1}
\end{align*}