esolang

Ante

All you have got is a deck of cards. The four suits are four registers, and the queen waits for the king.

Michael Dvorkin, 2013 · Turing complete: unknown · ●○○ easy · esolangs.org

Tested with 3 known programs · Hello World on Try It Online: identical except the line end · Test method

Run it

Expected: Hello, world!

The idea

Michael Dvorkin made Ante in 2013. A program is a row of playing cards such as 9♦ 8♥ J♦. The first interpreter was written in Ruby, and later versions followed in Go, Rust and Swift.

Read the story

Each suit is a register that holds one integer. Number cards build a value, the jack prints it as a character, the ten prints it as a number, and the queen and king make a loop. That is the whole language.

The machine

CardDoes
2…9 firstSet the register of its suit to that number
A firstStart from the current value of the register of its suit
2…9 after thatApply its suit as an operator: ♦ add, ♥ multiply, ♠ subtract, ♣ divide
JPrint the register of its suit as a character
10Print the register of its suit as a number
QA label
KJump back to the queen of its suit while that register is not 0

The operators work left to right without precedence, so 5♥ 6♦ 4♥ sets ♥ to (5 + 6) × 4 = 44, a comma. Two kings in a row go back to two queens in a row, so loops can nest. Numbers have no size limit and division rounds down. A # starts a comment.

Example

The first three cards set ♦ to 9 × 8 = 72 and print it: H.

The first three cards set ♦ to 9 × 8 = 72 and print it: H. Then A♦ 2♣ 3♥ 7♠ takes 72, halves it, triples it and subtracts 7, which is 101: e. The last four cards make 10, a newline.

Expected: 01234567891011121314

♥ starts at 15. Each round prints ♦, adds 1 to ♦ and takes 1 from ♥, and the king goes back to the queen until ♥ is 0.

This implementation settles three choices the specification leaves open as follows. An ace always starts a new instruction, a king looks backwards for its queen, and a jack prints the lowest 8 bits of its register.

Patterns it teaches

It is not known to be Turing complete.
  • Camouflage: a register machine dressed up as a card game, like ArnoldC in film quotes.

It is not known to be Turing complete. Four unbounded registers and a conditional jump are close to a counter machine, but the operators only work with the constants 2 to 9.

Try this

  1. Print Hi.
  2. Count down from 9 to 1.
  3. Hard: print the first ten powers of 2.

Further

Also in Jokes

Write your own in Run Convert a program from Ante

Implementation

JavaScript interpreter, source and command line

A JavaScript interpreter, used in the browser and on the command line. Id: ante.

Command line

shib run ante -e '3♥ 5♥ # ♥ = 3 * 5
Q♥
10♦
A♦ 3♦ 2♠
A♥ 3♠ 2♦
K♥'
shib manual ante

Source

Module
langs/tio/ports.js
Interpreter
langs/tio/ante.js

Docs: Kernel instructions · The .shib format · Command line · Adding a language

Source esolangs.org (CC0) · Edit on esolangs.org