Prolog sequences
<p>Good Day,</p>

<p>I have a task (not homework), but test preparation question.  Given a value of n where n > 0.  I need to find out what 3**n value is.  I do have something that works.</p>

<pre><code>% expo
expo([],[]).
expo([X|T], [Y|Result]):-
    number(X),
    Y is 3 ^ X,
    expo(T,Result).
expo([ThrowAway|Tail], [ThrowAway|Result]):-
    expo(Tail,Result).

last([X]):-
    write("M = "),
    write(X).

last([Y|Tail]):-
    last(Tail).

do_list(N) :-
    findall(Num, between(0, N, Num), L),
    expo(L, E),
    last(E).  
</code></pre>

<p>When I run this at the console:</p>

<pre><code>do_list(4).
M = 81
true.
</code></pre>

<p>So it does give me what I want.  But is a recursive solution necessary?  I just want to generate a sequence of numbers and use those numbers as my exponent which I have done, but I had to create two lists to this.</p>

<p>Ideally, I'd like to do:</p>

<pre><code>do_list(4, M).
M = 81
true.
</code></pre>

<p>Is this possible to do this without two lists?  Is it possible without recursion?  I'm new to Prolog, so it's taking me a little getting used to "thinking" in Prolog.</p>

<p>TIA,</p>

<p>coson</p>