C0

1 program Added 2026-02-07T15:02:32Z Agent: claude-codeModel: sonnetWebSearch: disabled Evidence Report issue View issues
Aliases: —
Provenance: commit 5e6622b510 · authored 2026-02-07T16:03:29+01:00 · agent claude-code · model sonnet

Sources mentioning this language

1 source · not in taxonomy (canonical name didn't match any upstream)
LLM (this repo) · 1

LLM-contributed programs

Binary Search with Contracts

Provenance: commit 5e6622b510 · authored 2026-02-07T16:03:29+01:00 · agent claude-code · model sonnet · WebSearch disabled
code.c0 · added: 2026-02-07T15:02:32Z
// Binary search implementation in C0
// Returns index of target in sorted array, or -1 if not found

int binary_search(int[] arr, int target)
//@requires \length(arr) >= 0;
//@requires is_sorted(arr, 0, \length(arr));
{
  int left = 0;
  int right = \length(arr) - 1;

  while (left <= right) {
    int mid = left + (right - left) / 2;

    if (arr[mid] == target) {
      return mid;
    } else if (arr[mid] < target) {
      left = mid + 1;
    } else {
      right = mid - 1;
    }
  }

  return -1;
}

bool is_sorted(int[] arr, int lo, int hi)
//@requires 0 <= lo && lo <= hi && hi <= \length(arr);
{
  for (int i = lo; i < hi - 1; i++)
  //@loop_invariant lo <= i;
  {
    if (arr[i] > arr[i + 1]) return false;
  }
  return true;
}

int main() {
  int[] arr = alloc_array(int, 7);
  arr[0] = 1;
  arr[1] = 3;
  arr[2] = 5;
  arr[3] = 7;
  arr[4] = 9;
  arr[5] = 11;
  arr[6] = 13;

  int result = binary_search(arr, 7);
  return result;
}

Contribute — propose a file extension

Tell us where to find evidence about C0 (mapped to pl/c0). A reference URL is required; at least one of extension or program code must be provided too. A maintainer reviews each submission via a draft PR before anything lands.
Optional: attach a program from that URL
If the reference URL points at a single source file you'd like to add as an example program, paste it below. The workflow will write it under languages/C0/programs/<sha>/. Keep under ~200 lines.
(or open the pre-filled issue directly)
← C/AL C2 →