Skip to content

realeroberto/spaghetti.awk

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

17 Commits
 
 
 
 
 
 

Repository files navigation

spaghetti.awk

A loose collection of short programs in AWK.

Rationale

Exploring the possibilities of a classical tool in the Unix world.

chinese

An implementation of the Chinese remainder theorem.

Purpose

Given a positive integer k, positive integers a_1, ..., a_k which are pairwise coprime and arbitrary integers n_1, ..., n_k, we find the unique x such that

x = a_1 (mod n_1), ..., x = a_k (mod n_k)

Example

There are certain things whose number is unknown. If we count them by threes, we have two left over; by fives, we have three left over; and by sevens, two are left over. How many things are there? (Sunzi Suanjing)

In other words, we must find the solution of the congruential system of equations:

x ≡ 2 (mod 3) ≡ 3 (mod 5) ≡ 2 (mod 7)

Let's use chinese.awk:

$ chinese.awk
2 3 2
3 5 7
^D

And the answer is:

23

httpd

An AWK implementation of a very basic web server.

pi-by-viete

Calculates an approximation of PI by means of Viète's formula

ttt

An implementation of the classical Tic-Tac-Toe game, based on von Neumann's Minimax algorithm.

Usage

Just do

    awk -f ttt.awk

Enjoy!

Releases

No releases published

Packages

No packages published

Languages