RPCIEGE - Skirmish 8
Tags: soroban, stellar
Published: 2023-10-02 21:51:25

So, I'll give this a try: my writeup of Skirmish 8 in the RPCiege.

On the off-chance someone reads this without knowing what that is, here's a brief summary.
On www.rpciege.com there is a series of coding games/challenges on the Soroban smart contract platform. It's currently in a testing stage, aiming to go live end of 2023.
RPCiege (and its predecessor Stellar Quest) will let you get familiar with the language and platform, and gives you kick-ass collectible cards to boot.

So, on to Skirmish 8. I'll give a brief writeup of how I attempted to tackle this, and give some hints on how you can solve it.
No full solution, but enough to get you going.


![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/ibiws3tcm64wgie7g5ex.png)
The booklet gives you your mission, and a helpful link to documentation. However, with the latest preview release, you don't actually need the linked docs!

To get started, we have a contract. I always start by pointing my friend `-h` at the contract.
It will tell you what functions the contract has, which is always a good start.

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/w33by8ikrmseary3uw7r.png)
And you can also use `-h` on those functions itself, to get information about what parameters the function expects. Let's have a look:
![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/u7tg8wqzo2tssdifx261.png)

The `_nft_dest` is optional, so I'll skip it. I already have the cards and my spot on the leaderboard :)
For source, I'll just use my configured identity.
But notice how `--answer` expects an `<Array<u32>>`? And it even gives an example of such an array.
I took the lazy route, and just tried it with that example. 
![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/23dejklbkyh1pemucngr.png)

In the current release, we see a lot of diagnostic events, along with the return of the function.
So, a few things to unwrap here:
1) I just passed [1] as answer
2) The diagnostics return a vector: [0, 4508]
3) We died.. that's usually not good.

So, we didn't solve this yet. But did you expect that, with an answer of `[1]`?

I'll give a hint here: the 0 in that vector is the number of positions we got correct.
And we got some information: the number 4508.
So, let's try `--answer` with that as input:

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/yoi0yrq6se5g9t2ry6aa.png)
And now we starved.. so something has changed.
And notice that we did not get a screen full of diagnostic info.
So, when we `Died`, the contract emitted a diagnostic event, and when we `Starved`, it did not.

But that also leaves us stuck for a bit.
Any random input leads to `Died`, except for that number we got returned earlier.
But `--answer` takes a vector! So we can input more numbers.
After some fiddling around, I decided to add my random guess after the 4508:
![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/l3lj95hsmgy27d850tul.png)

We still `Died`, but have a different diagnostic event.
So we're getting somewhere. 1 correct position, and the number 4509.

That should be enough to get you going.
For reference, there is another way to get the diagnostic events. 
Soroban-cli has a command for it. You can point it at a contract, and it will return (recent) events emitted by it. 
The part that always trips me up is the `--start-ledger`
I end up getting that from Stellar Laboratory. If there's a better way to find out what the latest ledger is, let me know!

Row-Bear

PS: After you have some parts of your sequence right, you might be able to predict the next parts..
If you're smarter than me, that may take you less time than uncovering them one by one.

PPS: Other than `Died` or `Starved`, you can also get `Exploded`. Bonus points if you reach that :)