Pack text, numbers and pixels into bytes on the Pasar Wage bridge: JS glue to real WebAssembly. 14 levels, played right in the browser with nothing to install.
What the levels ask
A Wage market morning. Across the river the district has opened a new print shop: its machine is very fast, but it only understands numbers. Mr. Wagino, toll keeper of the Wage Market bridge, now asks that machine to work out the toll through the function ongkos, Rp500 a sack. Mrs. Sari comes first with an order holding karung (sacks) and catatan (a note). Fill the argument of ongkos so every trader pays the right toll.
Mrs. Lastri brings fish from the estuary and weighs it: 2.5 kilos of tuna at Rp12,000 a kilo. The price module across the river has three functions that do the same thing with three kinds of number: harga_i32, harga_i64 and harga_f64. Pick the function that gives the right price for a weight with a decimal.
The traders are ordering name boards with raised letters, charged by the letter. The function hitungHuruf across the river cannot take text: it reads letters from the module's memory, plank by plank, from an address for so many bytes. Pack nama into bytes, lay them on plank 0, then tell the machine where to start and how long it is.
The banner press copies the writing planks onto the print planks at address 1024, then Mr. Wagino reads the result out. encodeInto writes text onto the planks as far as it fits. Decide n, how many planks are used, so every banner today prints whole, Mr. Tono's and Mrs. Yanti's orders included.
Now the machine across the river writes the toll receipt itself, in its memory. struk returns the receipt's address, and panjangStruk gives its length. At the start of the module's memory there is other writing of its own. Make the right view so Mr. Wagino reads that receipt, no less and no more.
The tariff machine keeps a tariff table on plank 0 onwards: one four-byte number for each sack letter (A chicken, B rice, C chillies, and so on). Mrs. Yanti's order is the letters of her sacks. Which planks may it go on? Fill ptr so every trader's total comes out right.
A busy day: twelve traders order name boards at once. This module's allocator has only eight plots on the bridge, 32 planks each, and it refuses hard when it is full or when a plot is given back wrongly. Fill the last line of the loop so all twelve names are counted.
In the afternoon the summary machine writes the market's summary on plank 256: the toll total as an i32, then the number of sacks as the next i32. One i32 takes four planks. Read both with a DataView so the numbers on Mr. Wagino's summary board match the sacks that crossed today.
Ms. Wulan keeps the market's cash book, and the book is on the JavaScript side. The module across the river wants to record every item that passes itself, so it imports the function catat from the namespace pasar. Fill the import object given to instantiate so today's four items are recorded.
The market's loudspeaker is on the JavaScript side. The module across the river wants to announce three pieces of news, but text cannot cross: it only calls umumkan with the address and the length of the news in its memory. Fill what goes up on the notice board so people read the real news.
Dina looks after the market's notice board and wants her photo printed in black and white. A photo is a row of pixels, and each pixel is four bytes: red, green, blue, alpha. The photo is already on the rented planks; the function abu(ptr, len) turns len bytes from ptr grey. Fill the length so the whole photo changes.
The Wage Market bridge turns thirty. Dina wants Mr. Wagino's photo enlarged twice for the banner. The perbesar machine writes its result onto the rented planks out; its allocator lengthens the bridge when the planks do not fit. Decide how many bytes to rent for the result, then print it.