% vim: ts=4 sw=4 et ft=mercury

:- module bug315.
:- interface.
:- import_module io.

:- pred main(io::di, io::uo) is cc_multi.

:- implementation.
:- import_module int.
:- import_module list.
:- import_module string.

:- pred rn(int, int).
:- mode rn(in, out) is multi.
:- pragma memo(rn/2).

rn(N, N).
rn(N, M + 1) :-
    rn(N-1, M).
rn(N, M + 2) :-
    rn(N-2, M).

main(!IO) :-
    test(2, !IO),
    test(3, !IO),
    test(2, !IO).

:- pred test(int::in, io::di, io::uo) is cc_multi.

test(N, !IO) :-
    rn(N, M),
    io.format("rn(%d) = %d\n", [i(N), i(M)], !IO).
