Hostname: page-component-77f85d65b8-7lfxl Total loading time: 0 Render date: 2026-04-18T06:46:44.340Z Has data issue: false hasContentIssue false

Sorted

Verifying the Problem of the Dutch National Flag in Agda

Published online by Cambridge University Press:  12 October 2011

WOUTER SWIERSTRA*
Affiliation:
Heijendaalseweg 135, 6525 AJ Nijmegen, the Netherlands (e-mail: w.swierstra@cs.ru.nl)
Rights & Permissions [Opens in a new window]

Extract

Core share and HTML view are not available for this content. However, as you have access to this content, a full PDF is available via the 'Save PDF' action button.

The problem of the Dutch national flag was formulated by Dijkstra (1976) as follows:

There is a row of buckets numbered from 1 to n. It is given that:

  1. P1: each bucket contains one pebble

  2. P2: each pebble is either red, white, or blue.

A minicomputer is placed in front of this row of buckets and has to be programmed in such a way that it will rearrange (if necessary) the pebbles in the order of the Dutch national flag.

The minicomputer in question should perform this rearrangement using two commands:

  • swapi j for 1≤in and 1≤jn exchanges the pebbles stored in the buckets numbered i and j;

  • read (i) for 1≤in returns the colour of the pebble currently lying in bucket number i. Dijkstra originally named this operation buck.

Information

Type
Functional Pearls
Copyright
Copyright © Cambridge University Press 2011
Supplementary material: File

Swierstra Supplementary Materials

Swierstra Supplementary Materials

Download Swierstra Supplementary Materials(File)
File 5 KB
Submit a response

Discussions

No Discussions have been published for this article.