user
With the following initial conditions:

```
      u1 = 1 
      u2 = 2 

```

We define the    nth    Ulam number    un    as the smallest number that is greater than    un-1      and
  
is the unique sum of two different Ulam numbers    ui (<n)    and    uj (<n).

Task

Write a function to generate the    nth    Ulam number.

References

* OEIS Ulam numbers
assistant
```
my @ulams = 1, 2, &next-ulam … *;

sub next-ulam {
    state $i = 1;
    state @sums = 0,1,1;
    my $last = @ulams[$i];
    (^$i).map: { @sums[@ulams[$_] + $last]++ };
    ++$i;
    quietly ($last ^.. *).first: { @sums[$_] == 1 };
}

for 1 .. 4 {
    say "The {10**$_}th Ulam number is: ", @ulams[10**$_ - 1]
}

```

Output:

```
The 10th Ulam number is: 18
The 100th Ulam number is: 690
The 1000th Ulam number is: 12294
The 10000th Ulam number is: 132788
```