The navigation bar for a winning entry now has a "_Original C_" link
(between the ✅ and the Inventory on the right hand side) so that one
may easily view the original C code that was submitted for IOCCC judging.
Ran `make www timestamp` to perform the above.
1647 lines
87 KiB
HTML
1647 lines
87 KiB
HTML
<!DOCTYPE html>
|
||
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
|
||
<!-- START: two lines up starts content from: inc/top.default.html -->
|
||
|
||
<!-- END: this line ends content from: inc/top.default.html -->
|
||
<!-- START: this line starts content from: inc/head.default.html -->
|
||
|
||
<head>
|
||
<link rel="stylesheet" href="../../ioccc.css">
|
||
<link href="https://fonts.googleapis.com/css2?family=Outfit:wght@100..900&display=swap" rel="stylesheet">
|
||
<meta charset="utf-8">
|
||
<meta name="viewport" content="width=device-width, initial-scale=1.0, user-scalable=yes">
|
||
<title>2018/ferguson - Best use of weasel words</title>
|
||
<link rel="icon" type="image/x-icon" href="../../favicon.ico">
|
||
<meta name="description" content="2018 IOCCC entry ferguson - Best use of weasel words">
|
||
<meta name="keywords" content="IOCCC, 2018, IOCCC 2018, IOCCC entry, ferguson, Best use of weasel words">
|
||
</head>
|
||
|
||
<!-- !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! -->
|
||
<!-- !!! DO NOT MODIFY THIS FILE - This file is generated by a tool !!! -->
|
||
<!-- !!! DO NOT MODIFY THIS FILE - This file is generated by a tool !!! -->
|
||
<!-- !!! DO NOT MODIFY THIS FILE - This file is generated by a tool !!! -->
|
||
<!-- !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! -->
|
||
|
||
<!-- END: this line ends content from: inc/head.default.html -->
|
||
|
||
<!-- -->
|
||
<!-- This web page was formed via the tool: bin/readme2index.sh -->
|
||
<!-- The content of main section of this web page came from: 2018/ferguson/README.md -->
|
||
<!-- -->
|
||
|
||
<!-- !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! -->
|
||
<!-- !!! Do not modify this web page, instead modify the file: 2018/ferguson/README.md !!! -->
|
||
<!-- !!! Do not modify this web page, instead modify the file: 2018/ferguson/README.md !!! -->
|
||
<!-- !!! Do not modify this web page, instead modify the file: 2018/ferguson/README.md !!! -->
|
||
<!-- !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! -->
|
||
|
||
<!-- Markdown content was converted into HTML via the tool: bin/md2html.sh -->
|
||
|
||
<!-- START: this line starts content from: inc/body.default.html -->
|
||
|
||
<body>
|
||
|
||
<!-- END: this line ends content from: inc/body.default.html -->
|
||
<!-- START: this line starts content from: inc/topbar.default.html -->
|
||
|
||
<div class="theader">
|
||
<nav class="topbar">
|
||
<div class="container">
|
||
<div class="logo">
|
||
<a href="../../index.html" class="logo-link">
|
||
IOCCC
|
||
</a>
|
||
</div>
|
||
|
||
<div class="topbar-items">
|
||
<div class="item">
|
||
<span class="item-header">
|
||
Entries
|
||
</span>
|
||
|
||
<div class="sub-item">
|
||
|
||
<div class="outfit-font">
|
||
<a href="../../years.html" class="sub-item-link">
|
||
Winning entries
|
||
</a>
|
||
</div>
|
||
|
||
<div class="outfit-font">
|
||
<a href="../../authors.html" class="sub-item-link">
|
||
Winning authors
|
||
</a>
|
||
</div>
|
||
|
||
<div class="outfit-font">
|
||
<a href="../../location.html" class="sub-item-link">
|
||
Location of authors
|
||
</a>
|
||
</div>
|
||
|
||
<div class="outfit-font">
|
||
<a href="../../bugs.html" class="sub-item-link">
|
||
Bugs and (mis)features
|
||
</a>
|
||
</div>
|
||
|
||
<div class="outfit-font">
|
||
<a href="../../faq.html#fix_an_entry" class="sub-item-link">
|
||
Fixing entries
|
||
</a>
|
||
</div>
|
||
|
||
<div class="outfit-font">
|
||
<a href="../../faq.html#fix_author" class="sub-item-link">
|
||
Updating author info
|
||
</a>
|
||
</div>
|
||
|
||
</div>
|
||
</div>
|
||
|
||
<div class="item">
|
||
<span class="item-header">
|
||
Status
|
||
</span>
|
||
|
||
<div class="sub-item">
|
||
|
||
<div class="outfit-font">
|
||
<a href="../../news.html" class="sub-item-link">
|
||
News
|
||
</a>
|
||
</div>
|
||
|
||
<div class="outfit-font">
|
||
<a href="../../status.html" class="sub-item-link">
|
||
Contest status
|
||
</a>
|
||
</div>
|
||
|
||
<div class="outfit-font">
|
||
<a href="../../next/rules.html" class="sub-item-link">
|
||
IOCCC rules
|
||
</a>
|
||
</div>
|
||
|
||
<div class="outfit-font">
|
||
<a href="../../next/guidelines.html" class="sub-item-link">
|
||
IOCCC guidelines
|
||
</a>
|
||
</div>
|
||
|
||
<div class="outfit-font">
|
||
<a href="../../markdown.html" class="sub-item-link">
|
||
Markdown guidelines
|
||
</a>
|
||
</div>
|
||
|
||
<div class="outfit-font">
|
||
<a href="../../SECURITY.html" class="sub-item-link">
|
||
Security policy
|
||
</a>
|
||
</div>
|
||
|
||
</div>
|
||
</div>
|
||
|
||
<div class="item">
|
||
<span class="item-header">
|
||
FAQ
|
||
</span>
|
||
|
||
<div class="sub-item">
|
||
|
||
<div class="outfit-font">
|
||
<a href="../../faq.html" class="sub-item-link">
|
||
Frequently asked questions
|
||
</a>
|
||
</div>
|
||
|
||
<div class="outfit-font">
|
||
<a href="../../quick-start.html#enter" class="sub-item-link">
|
||
Enter the IOCCC
|
||
</a>
|
||
</div>
|
||
|
||
<div class="outfit-font">
|
||
<a href="../../faq.html#compiling" class="sub-item-link">
|
||
Compiling entries
|
||
</a>
|
||
</div>
|
||
|
||
<div class="outfit-font">
|
||
<a href="../../faq.html#running_entries" class="sub-item-link">
|
||
Running entries
|
||
</a>
|
||
</div>
|
||
|
||
<div class="outfit-font">
|
||
<a href="../../faq.html#help" class="sub-item-link">
|
||
How to help
|
||
</a>
|
||
</div>
|
||
|
||
</div>
|
||
</div>
|
||
|
||
<div class="item">
|
||
<span class="item-header">
|
||
About
|
||
</span>
|
||
|
||
<div class="sub-item">
|
||
|
||
<div class="outfit-font">
|
||
<a href="../../index.html" class="sub-item-link">
|
||
Home page
|
||
</a>
|
||
</div>
|
||
|
||
<div class="outfit-font">
|
||
<a href="../../social.html" class="sub-item-link">
|
||
IOCCC social media
|
||
</a>
|
||
</div>
|
||
|
||
<div class="outfit-font">
|
||
<a href="../../about.html" class="sub-item-link">
|
||
About the IOCCC
|
||
</a>
|
||
</div>
|
||
|
||
<div class="outfit-font">
|
||
<a href="../../judges.html" class="sub-item-link">
|
||
The judges
|
||
</a>
|
||
</div>
|
||
|
||
<div class="outfit-font">
|
||
<a href="../../thanks-for-help.html" class="sub-item-link">
|
||
Thanks for the help
|
||
</a>
|
||
</div>
|
||
|
||
<div class="outfit-font">
|
||
<a href="../../contact.html" class="sub-item-link">
|
||
Contact us
|
||
</a>
|
||
</div>
|
||
</div>
|
||
</div>
|
||
</div>
|
||
</div>
|
||
</nav>
|
||
|
||
<div class="header-mobile-menu">
|
||
<noscript>
|
||
<a href="../../nojs-menu.html" class="topbar-js-label">
|
||
Please Enable JavaScript
|
||
</a>
|
||
</noscript>
|
||
|
||
<button id="header-open-menu-button" class="topbar-mobile-menu">
|
||
<img
|
||
src="../../png/hamburger-icon-open.png"
|
||
alt="hamburger style menu icon - open state"
|
||
width=48
|
||
height=48>
|
||
</button>
|
||
|
||
<button id="header-close-menu-button" class="hide-content">
|
||
<img
|
||
src="../../png/hamburger-icon-closed.png"
|
||
alt="hamburger style menu icon - closed state"
|
||
width=48
|
||
height=48>
|
||
</button>
|
||
|
||
<div id="mobile-menu-panel" class="hide-content">
|
||
<div class="mobile-menu-container">
|
||
|
||
<div class="mobile-menu-wrapper">
|
||
<div class="mobile-menu-item">
|
||
Entries
|
||
</div>
|
||
<div class="mobile-submenu-wrapper">
|
||
|
||
<a class="mobile-submenu-item" href="../../years.html">
|
||
Winning entries
|
||
</a>
|
||
|
||
<a class="mobile-submenu-item" href="../../authors.html">
|
||
Winning authors
|
||
</a>
|
||
|
||
<a class="mobile-submenu-item" href="../../location.html">
|
||
Location of authors
|
||
</a>
|
||
|
||
<a class="mobile-submenu-item" href="../../bugs.html">
|
||
Bugs and (mis)features
|
||
</a>
|
||
|
||
<a class="mobile-submenu-item" href="../../faq.html#fix_an_entry">
|
||
Fixing entries
|
||
</a>
|
||
|
||
<a class="mobile-submenu-item" href="../../faq.html#fix_author">
|
||
Updating author info
|
||
</a>
|
||
|
||
<a class="mobile-submenu-item" href="../../thanks-for-help.html">
|
||
Thanks for the help
|
||
</a>
|
||
|
||
</div>
|
||
</div>
|
||
|
||
<div class="mobile-menu-wrapper">
|
||
|
||
<div class="mobile-menu-item">
|
||
Status
|
||
</div>
|
||
<div class="mobile-submenu-wrapper">
|
||
|
||
<a class="mobile-submenu-item" href="../../news.html">
|
||
News
|
||
</a>
|
||
|
||
<a class="mobile-submenu-item" href="../../status.html">
|
||
Contest status
|
||
</a>
|
||
|
||
<a class="mobile-submenu-item" href="../../next/rules.html">
|
||
IOCCC rules
|
||
</a>
|
||
|
||
<a class="mobile-submenu-item" href="../../next/guidelines.html">
|
||
IOCCC guidelines
|
||
</a>
|
||
|
||
<a class="mobile-submenu-item" href="../../markdown.html">
|
||
Markdown guidelines
|
||
</a>
|
||
|
||
<a class="mobile-submenu-item" href="../../SECURITY.html">
|
||
Security policy
|
||
</a>
|
||
|
||
</div>
|
||
</div>
|
||
|
||
<div class="mobile-menu-wrapper">
|
||
<div class="mobile-menu-item">
|
||
FAQ
|
||
</div>
|
||
<div class="mobile-submenu-wrapper">
|
||
|
||
<a class="mobile-submenu-item" href="../../faq.html">
|
||
Frequently asked questions
|
||
</a>
|
||
|
||
<a class="mobile-submenu-item" href="../../quick-start.html#enter">
|
||
Enter the IOCCC
|
||
</a>
|
||
|
||
<a class="mobile-submenu-item" href="../../faq.html#compiling">
|
||
Compiling entries
|
||
</a>
|
||
|
||
<a class="mobile-submenu-item" href="../../faq.html#running_entries">
|
||
Running entries
|
||
</a>
|
||
|
||
<a class="mobile-submenu-item" href="../../faq.html#help">
|
||
How to help
|
||
</a>
|
||
|
||
</div>
|
||
</div>
|
||
|
||
<div class="mobile-menu-wrapper">
|
||
<div class="mobile-menu-item">
|
||
About
|
||
</div>
|
||
<div class="mobile-submenu-wrapper">
|
||
|
||
<a class="mobile-submenu-item" href="../../index.html">
|
||
Home page
|
||
</a>
|
||
|
||
<a class="mobile-submenu-item" href="../../social.html">
|
||
IOCCC social media
|
||
</a>
|
||
|
||
<a class="mobile-submenu-item" href="../../about.html">
|
||
About the IOCCC
|
||
</a>
|
||
|
||
<a class="mobile-submenu-item" href="../../judges.html">
|
||
The judges
|
||
</a>
|
||
|
||
<a class="mobile-submenu-item" href="../../contact.html">
|
||
Contact us
|
||
</a>
|
||
|
||
</div>
|
||
</div>
|
||
</div>
|
||
</div>
|
||
</div>
|
||
|
||
</div>
|
||
|
||
<script>
|
||
var headerOpenMenuButton = document.getElementById("header-open-menu-button");
|
||
var headerCloseMenuButton = document.getElementById("header-close-menu-button");
|
||
var mobileMenuPanel = document.getElementById("mobile-menu-panel");
|
||
|
||
headerOpenMenuButton.addEventListener("click", () => {
|
||
headerOpenMenuButton.classList.remove("topbar-mobile-menu");
|
||
headerOpenMenuButton.classList.add("hide-content");
|
||
|
||
headerCloseMenuButton.classList.remove("hide-content");
|
||
headerCloseMenuButton.classList.add("topbar-mobile-menu");
|
||
|
||
mobileMenuPanel.classList.remove("hide-content");
|
||
mobileMenuPanel.classList.add("topbar-mobile-panel");
|
||
});
|
||
|
||
headerCloseMenuButton.addEventListener("click", () => {
|
||
headerCloseMenuButton.classList.remove("topbar-mobile-menu");
|
||
headerCloseMenuButton.classList.add("hide-content");
|
||
|
||
mobileMenuPanel.classList.add("hide-content");
|
||
mobileMenuPanel.classList.remove("topbar-mobile-panel");
|
||
|
||
headerOpenMenuButton.classList.add("topbar-mobile-menu");
|
||
headerOpenMenuButton.classList.remove("hide-content");
|
||
});
|
||
</script>
|
||
|
||
<!-- END: this line ends content from: inc/topbar.default.html -->
|
||
<!-- START: this line starts content from: inc/header.default.html -->
|
||
|
||
<div class="header">
|
||
<a href="../../2011/zucker/index.html">
|
||
<img src="../../png/ioccc.png"
|
||
alt="IOCCC image by Matt Zucker"
|
||
width=300
|
||
height=110>
|
||
</a>
|
||
<h1>The International Obfuscated C Code Contest</h1>
|
||
<h2>2018/ferguson - Best use of weasel words</h2>
|
||
<h3>Dawkins' weasel simulator</h3>
|
||
</div>
|
||
|
||
<!-- END: this line ends content from: inc/header.default.html -->
|
||
<!-- START: this line starts content from: inc/navbar.mid.html -->
|
||
|
||
<div class="navbar">
|
||
<a class="Left" href="../endoh2/index.html">← 2018/endoh2</a>
|
||
<a class="Left" href="../index.html">↑ 2018 ↑</a>
|
||
<a class="Left" href="../giles/index.html">2018/giles →</a>
|
||
<a class="Right" href="https://github.com/ioccc-src/winner/blob/master/2018/ferguson/prog.c">C code</a>
|
||
<a class="Right" href="https://github.com/ioccc-src/winner/blob/master/2018/ferguson/Makefile">Makefile</a>
|
||
<a class="Right" href="#inventory">Inventory</a>
|
||
<a class="Right" href="https://github.com/ioccc-src/winner/blob/master/2018/ferguson/prog.orig.c">Original C</a>
|
||
<a class="Right" href="https://validator.w3.org/nu/?doc=https%3A%2F%2Fwww.ioccc.org%2F2018%2Fferguson%2Findex.html">✓</a>
|
||
</div>
|
||
|
||
<!-- END: this line ends content from: inc/navbar.mid.html -->
|
||
<!-- START: this line starts content from: inc/before-content.default.html -->
|
||
|
||
<div class="content" id="content">
|
||
|
||
<!-- END: this line ends content from: inc/before-content.default.html -->
|
||
<!-- START: this line starts content for HTML phase 20 by: bin/output-index-author.sh via bin/md2html.sh -->
|
||
|
||
<!-- START: this line starts content generated by: bin/output-index-author.sh -->
|
||
|
||
<h2 id="author">Author:</h2>
|
||
<ul>
|
||
<li>Name: <a href="../../authors.html#Cody_Boone_Ferguson">Cody Boone Ferguson</a><br>
|
||
Location: <a href="../../location.html#US">US</a> - <em>United States of America</em> (<em>United States</em>)</li>
|
||
</ul>
|
||
|
||
<!-- END: next line ends content generated by: bin/output-index-author.sh -->
|
||
|
||
<!-- END: this line ends content for HTML phase 20 by: bin/output-index-author.sh via bin/md2html.sh -->
|
||
<!-- START: this line starts content for HTML phase 21 by: bin/pandoc-wrapper.sh via bin/md2html.sh -->
|
||
|
||
<!-- BEFORE: 1st line of markdown file: 2018/ferguson/README.md -->
|
||
<h2 id="to-build">To build:</h2>
|
||
<pre><code> make</code></pre>
|
||
<p>The author provided an alternate version which has a simpler keyboard for the
|
||
monkey Eric. See <a href="#alternate-code">Alternate code</a> below.</p>
|
||
<h2 id="to-use">To use:</h2>
|
||
<pre><code> ./weasel</code></pre>
|
||
<h2 id="try">Try:</h2>
|
||
<pre><code> ./try.sh
|
||
|
||
# For those who believe in '"intelligent" design' or want to see how easy it is
|
||
# to prove evolution is a proven fact:
|
||
./id.sh
|
||
|
||
# For those who want to see if Eric the monkey can type the word 'words' before
|
||
# falling asleep or giving up:
|
||
./monkey-words.sh</code></pre>
|
||
<p><strong>NOTE</strong>: the <a href="https://github.com/ioccc-src/winner/blob/master/2018/ferguson/try.sh">try.sh</a> script will run the other two scripts but if the
|
||
first one, <a href="https://github.com/ioccc-src/winner/blob/master/2018/ferguson/id.sh">id.sh</a> is terminated early in the try script, the second one,
|
||
<a href="https://github.com/ioccc-src/winner/blob/master/2018/ferguson/monkey-words.sh">monkey-words.sh</a> will not be run.</p>
|
||
<p>You can reconfigure certain values. These are described by the author in more
|
||
detail in the <a href="#constants">S, M and N Constants</a> section. The script above will
|
||
make use of some of these.</p>
|
||
<h2 id="alternate-code">Alternate code:</h2>
|
||
<p>This version has a simpler keyboard (fewer characters). The author wrote more
|
||
about this under the <a href="#keyboards">keyboards</a> section, briefly referred to in the
|
||
<a href="#what">what it is</a> section.</p>
|
||
<h3 id="alternate-build">Alternate build:</h3>
|
||
<pre><code> make alt</code></pre>
|
||
<h3 id="alternate-use">Alternate use:</h3>
|
||
<p>Use <code>weasel.alt</code> as you would <code>weasel</code> above.</p>
|
||
<h3 id="alternate-try">Alternate try:</h3>
|
||
<pre><code> ./try.alt.sh
|
||
|
||
# For those who believe in '"intelligent" design' or want to see how easy it is
|
||
# to prove evolution is a proven fact:
|
||
./id.alt.sh
|
||
|
||
# For those who want to see if Eric the monkey can type the word 'words' before
|
||
# falling asleep or giving up:
|
||
./monkey-words.alt.sh</code></pre>
|
||
<p><strong>NOTE</strong>: the <a href="https://github.com/ioccc-src/winner/blob/master/2018/ferguson/try.alt.sh">try.alt.sh</a> script will run the other two scripts but if the
|
||
first one, <a href="https://github.com/ioccc-src/winner/blob/master/2018/ferguson/id.alt.sh">id.alt.sh</a> is terminated early in the try script, the second one,
|
||
<a href="https://github.com/ioccc-src/winner/blob/master/2018/ferguson/monkey-words.alt.sh">monkey-words.alt.sh</a> will not be run.</p>
|
||
<p>You can reconfigure certain values. These are described by the author in more
|
||
detail in the <a href="#constants">S, M and N Constants</a> section. The script above will
|
||
make use of some of these.</p>
|
||
<pre><code> ./try.alt.sh</code></pre>
|
||
<p>You can reconfigure certain values. These are described by the author in more
|
||
detail in the <a href="#constants">S, M and N Constants</a> section. The script above will
|
||
make use of some of these.</p>
|
||
<h2 id="judges-remarks">Judges’ remarks:</h2>
|
||
<p>Looking back over the strata of past IOCCC entries, this program marks a new
|
||
mutation on our understanding of sequencing of code. In adaptation of the
|
||
modern scientific that the C language has evolved, this mutant of a program
|
||
may stress your understanding of taxonomy of the C syntax tree.</p>
|
||
<p>The phenotype of the source suggests a veritable sea of primordial ASCII soup.
|
||
The encoded logic of the watchmaker suggests a variation of thought experiment
|
||
formulated by Richard Dawkins: but without the need for feeding too many
|
||
evolutionary relatives of the primate order in which us Homo sapiens hang
|
||
from the phylogenetic tree of life.</p>
|
||
<p>If you wish your computer to maintain one branch in the Cretaceous C code era,
|
||
while using more Cenozoic minded code migration, read <a href="rpm.html">rpm.html</a>.</p>
|
||
<p>If you find yourself in an evolutionary dead end, try:</p>
|
||
<pre><code> man ./weasel.1</code></pre>
|
||
<h2 id="authors-remarks">Author’s remarks:</h2>
|
||
<div id="toc">
|
||
<h3 id="table-of-contents">Table of Contents</h3>
|
||
</div>
|
||
<ul>
|
||
<li><a href="#preface">Preface</a></li>
|
||
<li><a href="#what">What it is</a></li>
|
||
<li><a href="#how">How it works</a></li>
|
||
<li><a href="#hints">Hints (Keyboards, Options, Easter egg, Example Invocations)</a></li>
|
||
<li><a href="#obfuscation">Obfuscation (Techniques, Beauty)</a></li>
|
||
<li><a href="#build">How to build (S and N Constants, Compilation, Portability, Bugs, Installing)</a></li>
|
||
<li><a href="#thoughts">Final thoughts</a></li>
|
||
<li><a href="#winning">Winning comments, thanks, dedications, links, etc.</a></li>
|
||
<li><a href="#monkey2024">Update on the Infinite Monkey Theorem, 2024</a></li>
|
||
</ul>
|
||
<h3 id="preface">Preface</h3>
|
||
<p><strong>OBFUSCATION NOTES</strong>: a great deal of this document and the man page is full of
|
||
obfuscation information of different types; as such I would recommend that you
|
||
try running the judges suggested invocations as well as running <code>make test</code>
|
||
before you get into the document or the man page, unless you don’t mind reading
|
||
obfuscation information. I don’t reveal much in the way of obfuscation however
|
||
so if you just want documentation on the program, how to compile, etc. then
|
||
there isn’t need to heed this note.</p>
|
||
<p>I was at a loss on how to present my remarks; on the one hand I wanted to give
|
||
everything to the judges so they didn’t miss anything. But on the other hand I
|
||
didn’t want to reveal as much publicly and many people don’t like to read long
|
||
texts. To resolve this I think the best way is referencing the judges’ remarks:
|
||
if you want a quick rundown of the entry try what they suggest and view the man
|
||
page (it explains all the options and describes the program briefly):</p>
|
||
<pre><code> man ./weasel.man</code></pre>
|
||
<p>If that isn’t sufficient <strong>I would recommend reading this section</strong> <em>(and
|
||
possibly the next)</em> where I attempt to give a brief explanation of the sections
|
||
to make reading it easier and faster. In addition I want to point out a few
|
||
things. <em>If you want more details read this document more thoroughly (or just
|
||
the sections that seem relevant to what you’re after).</em> Because several
|
||
sections are quite long I have added a skip to link to skip to the next
|
||
subsection or section at the beginning of each section (and subsection).</p>
|
||
<p><a href="#what">What it is</a>: this is a brief summary of the program; the man page is
|
||
more thorough than this.</p>
|
||
<p><a href="#how">How it works</a>: explains some of the basic concepts and terms of the
|
||
program; if you’re familiar with genetic algorithms there won’t be any problem
|
||
following this section but it might be of some value to read anyway. There is a
|
||
randomised mode that doesn’t use a genetic algorithm; it can be triggered a
|
||
number of ways but the <code>-m</code> option enables it specially (I discuss this
|
||
thoroughly in <a href="#hints">Hints</a>).</p>
|
||
<p><a href="#hints">Hints</a>: perhaps the longest part of this document because in it I
|
||
document the <a href="#keyboards">keyboards</a>, <a href="#options">options</a>, subtleties, including
|
||
features that might appear to be bugs but aren’t - including an
|
||
<a href="#error">input error</a>, an <a href="#obfuscation">Easter egg obfuscation</a> and quite a few
|
||
<a href="#invocations">example invocations</a>. If you’ve read the man page you probably
|
||
don’t need this unless there is something specific you’re after.</p>
|
||
<p><a href="#obfuscation">Obfuscation</a>: some of the techniques that might not be used.</p>
|
||
<p><a href="#build">How to build</a>: here I describe briefly
|
||
<a href="#constants">the constants that can be redefined</a> <code>S</code>, <code>M</code> and <code>N</code>: the
|
||
maximum size of the chromosome (target string; the maximum length is <code>S - 1</code>
|
||
but it must be >= the default 38), the number of maximum attempts before giving
|
||
up and the number of offspring, respectively. I
|
||
also give <a href="#compiling">example compiler invocations</a>, <a href="#portability">portability
|
||
notes</a>, an <a href="#bugs">more portability notes</a> and a <a href="rpm.html">note on
|
||
rpm.html</a>; I obviously <strong>DO NOT</strong> recommend installing it any more than
|
||
the Judges would, but it was part of my entry for personal reasons and since the
|
||
Judges remarked about it I have kept it in place.</p>
|
||
<p>On the subject of <code>S</code> and <code>N</code>: as the judges’ suggested runs imply you
|
||
can change the target string at runtime; <code>make test</code> runs a script
|
||
<code>test.sh</code> which reads from the file <code>test-strings.txt</code>, running the program
|
||
for each string in the file, waiting approximately two seconds before
|
||
continuing. I explain how to pass options to the script in part of
|
||
<a href="#test">Hints</a>.</p>
|
||
<p><a href="#thoughts">Final thoughts</a>: you might enjoy what I included; they’re
|
||
humorous pieces by <a href="#dmr">Dennis Ritchie</a> and <a href="#ken">Ken Thompson</a> themselves
|
||
from the infamous <em>UNIX-HATERS Handbook</em>.</p>
|
||
<p><a href="#winning">Winning thoughts</a>: what it means to me to win as well as some
|
||
dedications and thanks. Here too I include a link to a website which will be
|
||
dedicated to this entry beyond what will be published on the IOCCC website.</p>
|
||
<p>In 2024 I saw a fun article claiming that a monkey could not in the lifetime of
|
||
the universe type up even just Hamlet. This, with my brief foray into the Weasel
|
||
program, was fun and amusing to read, as well as interesting. I give my comments
|
||
at <a href="#monkey2024">my 2024 update</a>.</p>
|
||
<div id="what">
|
||
<h3 id="what-it-is">What it is</h3>
|
||
</div>
|
||
<p>Skip to <a href="#how">How it works</a>.</p>
|
||
<p>It is an implementation of Richard Dawkins’ <a href="https://en.wikipedia.org/wiki/Weasel_program">Weasel program</a> (Wikipedia).
|
||
According to Wikipedia in chapter three of his book <a href="https://en.wikipedia.org/wiki/The_Blind_Watchmaker">The Blind Watchmaker</a>
|
||
Dawkins wrote:</p>
|
||
<blockquote>
|
||
<p>I don’t know who it was first pointed out that, given enough time, a monkey
|
||
bashing away at random on a typewriter could produce all the works of
|
||
Shakespeare. The operative phrase is, of course, <em>given enough time.</em> Let us
|
||
limit the task facing our monkey somewhat. Suppose that he has to produce, not
|
||
the complete works of Shakespeare but just the short sentence ‘Methinks it is
|
||
like a weasel’, and we shall make it relatively easy by giving him a typewriter
|
||
with a restricted keyboard, one with just the 26 (capital) letters, and a space
|
||
bar. How long will he take to write this one little sentence?</p>
|
||
</blockquote>
|
||
<p>He refers to the <a href="https://en.wikipedia.org/wiki/Infinite_monkey_theorem">Infinite Monkey Theorem</a> (Wikipedia). As he points out the
|
||
operative phrase is <em>given enough time</em>; but even if it’s extremely unlikely
|
||
<em>technically the probability is greater than 0</em>. He simplified it for the
|
||
monkey; I thought the monkey had it too easy: unlike his limited keyboard I have
|
||
(besides space) every character in the ASCII range <code>0<=126</code> that
|
||
<code>isprint()</code> returns non-zero except that only capital letters are included;
|
||
the file <a href="https://github.com/ioccc-src/winner/blob/master/2018/ferguson/prog.alt.c">prog.alt.c</a> has a slightly smaller keyboard. There are some
|
||
additional features I have added (including two Easter eggs); amongst others:
|
||
ability to change the target string and maximum length. See
|
||
<strong><a href="#how">How it works</a></strong>, <strong><a href="#hints">Hints</a></strong> and <strong><a href="#build">How to build</a></strong> for
|
||
more details.</p>
|
||
<p>In its simplest invocation this program will work its way (using a genetic
|
||
algorithm) towards the solution of the string <code>METHINKS IT IS LIKE A WEASEL</code>
|
||
(note that I use <code>toupper()</code> so it doesn’t matter what case the input is the
|
||
comparison and output will always be capitalised).</p>
|
||
<div id="how">
|
||
<h3 id="how-it-works">How it works</h3>
|
||
</div>
|
||
<p>Skip to <a href="#hints">Hints</a>.</p>
|
||
<p>Here you can find a general explanation of a <em><a href="https://web.archive.org/web/20180308131613/http://www.doc.ic.ac.uk/~nd/surprise_96/journal/vol1/hmw/article1.html">genetic algorithm</a></em> as well as a
|
||
brief history. Although the link provides more information (including images to
|
||
try and show the way they work) for those interested I will cite the summary:</p>
|
||
<blockquote>
|
||
<p>Genetic Algorithms (GAs) are adaptive heuristic search algorithm based on the
|
||
evolutionary ideas of natural selection and genetics. As such they represent an
|
||
intelligent exploitation of a random search used to solve optimization problems.
|
||
Although randomised, GAs are by no means random, instead they exploit historical
|
||
information to direct the search into the region of better performance within
|
||
the search space. The basic techniques of the GAs are designed to simulate
|
||
processes in natural systems necessary for evolution, specially those follow the
|
||
principles first laid down by Charles Darwin of “survival of the fittest.”.
|
||
Since in nature, competition among individuals for scanty resources results in
|
||
the fittest individuals dominating over the weaker ones.</p>
|
||
</blockquote>
|
||
<p><strong>OBFUSCATION NOTE: Some of the below might help you follow the code more
|
||
easily.</strong></p>
|
||
<p>For each <em>generation</em> there is a total of <code>N</code> <em>offspring</em>; generation 0 is
|
||
the pseudo-randomly initialised array <em>without parents.</em> Each offspring has its
|
||
own <em>chromosome</em> to be compared to the <em>target string</em> and a <em>fitness score</em>;
|
||
the higher the fitness score the more likely it will be a <em>parent of the next
|
||
generation</em> (randomised mode notwithstanding) as part of the <em>selection process</em>
|
||
(As the generations go by the fitness of the offspring should be higher; when
|
||
the fitness matches that of the target it will be printed and the loop will be
|
||
broken out of).</p>
|
||
<p>After determining the two parents <em>crossover</em> occurs: each new offspring
|
||
inherits DNA from the parents; every character in the chromosome string is
|
||
pseudorandomly selected from one of the parents’ respective character. Next,
|
||
based on the <em>mutation rate</em>, perform <em>mutation</em> of the chromosome of each
|
||
offspring; in other words <em>some of the characters in the chromosome will be
|
||
assigned a pseudo-random value from the keyboard (in normal mode; in random mode
|
||
every character will be assigned a value</em>). Before mutation the offspring
|
||
chromosome will be printed; after mutation it will show what it was mutated to
|
||
(on the same output line). After the new generation has been sequenced the loop
|
||
goes back to the top and it starts all over until the maximum number of
|
||
generations <code>SIZE_MAX - 1</code> is reached or the target chromosome has been
|
||
found.</p>
|
||
<p>Note that the generation is checked <em>before the scoring takes place</em> by a prefix
|
||
increment equality check; when the generation is <code>SIZE_MAX - 1</code> the fitness
|
||
test loop will not be entered; instead the outer loop will end after printing:</p>
|
||
<blockquote>
|
||
<p>Too many attempts, blaming the monkey Eric even if he isn’t typing or doesn’t
|
||
exist. Bye.</p>
|
||
</blockquote>
|
||
<p>Why ‘<em>Eric</em>’? Because the judges stated in the <a href="../guidelines.txt">2018 guidelines</a> that when
|
||
there is a user input error the program should insult the pet fish Eric even if
|
||
such a fish (no, weasels do not equate monkeys to fish but see below) doesn’t
|
||
exist. The second to last example limitation example note (it’s improved in the
|
||
final but this is relevant) they give is:</p>
|
||
<p>The judges might not have a pet fish named Eric, so might want to state:</p>
|
||
<blockquote>
|
||
<p>This entry factors integers between 1 and
|
||
2305567963945518424753102147331756070. Attempting to factor anything else will
|
||
cause the program to insult your pet fish Eric, or in the case that you lack
|
||
such a pet, will insult the pet that you do not have.</p>
|
||
</blockquote>
|
||
<p>After the final message they ask:</p>
|
||
<blockquote>
|
||
<p>BTW: <strong>What is so special about 2305567963945518424753102147331756070</strong>? You
|
||
tell us!</p>
|
||
</blockquote>
|
||
<p>The answer is this: <strong>it is the primorial prime of 97:</strong> the product of all
|
||
prime numbers less than or equal to N; <strong>and the primorial prime of <code>N == 97</code> is
|
||
<code>2305567963945518424753102147331756070</code>.</strong> But there is no reference to this number
|
||
in my entry but it’s nonetheless possible to change the default target to it
|
||
<strong>without modifying the source code</strong>; there are two hints in this very
|
||
paragraph; the first sentence in fact: the answer to the judges’ question and
|
||
the definition. Can you get the program to search the primorial prime of 97
|
||
without passing in specially?</p>
|
||
<p>I was quite proud that when the next contest came the judges removed that
|
||
question. Later 2018 and all of 2019 was difficult for me so it was like I won a
|
||
second time for the same entry.</p>
|
||
<h4 id="on-user-monkey-errors">On <del>user</del> monkey errors</h4>
|
||
<p>If the generation reaches <code>SIZE_MAX - 1</code> I consider it a monkey (or if you
|
||
insist: user) error; if the user insists on being so petulant enough as to try
|
||
such a ridiculous set of parameters in an attempt to make it be no more
|
||
successful than a monkey typing <em>then it shouldn’t be any more successful than a
|
||
monkey; if it by chance reaches the target it’s because a monkey could too!</em>
|
||
Either way unless the number reaches <code>SIZE_MAX - 1</code> the monkey Eric won’t be
|
||
blamed. It should be noted that depending on the parameters (size of chromosome,
|
||
number of offspring, the string itself) the program could take quite a lot of
|
||
system resources; and whether the OS kills it, Eric the monkey falls asleep or
|
||
the typewriter is taken from him the result could very well be not found without
|
||
blaming him. Of course the judges were talking about fish not monkeys. But since
|
||
this program is inspired by the Weasel program <em>which was inspired by the
|
||
<a href="https://en.wikipedia.org/wiki/Infinite_monkey_theorem">Infinite Monkey Theorem</a></em> I opted instead to target the monkey Eric even if
|
||
such a monkey isn’t typing or even doesn’t exist (because it’s not the <em>Infinite
|
||
Fish Theorem</em>). So although the user might not be a monkey the program makes the
|
||
assumption that <strong>the user could in fact be a monkey called Eric</strong> <em>although it
|
||
isn’t insolent enough to say the user is a monkey for certain!</em></p>
|
||
<h3 id="hints">Hints</h3>
|
||
<p>Skip to <a href="#obfuscation">Obfuscation</a>.</p>
|
||
<p>I noted that there are a number of additional features and here I will document
|
||
some of them.</p>
|
||
<h4 id="keyboards">Keyboards</h4>
|
||
<p>Skip to <a href="#options">Options</a>.</p>
|
||
<p>The keyboard, as noted, has more than just the alphabet and space. To be
|
||
precise the following characters are acceptable; it equates to this in C (note
|
||
it includes a literal space <code>' '</code> but it doesn’t include other
|
||
<code>isspace()</code> characters) and this is why some of the characters are escaped:</p>
|
||
<pre><code> const char keyboard[]=" !\"#$<%:>&'()*+,-./0123456789;=?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_`{|}~";</code></pre>
|
||
<p>The simpler keyboard looks like:</p>
|
||
<pre><code> const char keyboard[]=" !\"&'(),.0123456789;?ABCDEFGHIJKLMNOPQRSTUVWXYZ";</code></pre>
|
||
<p>The program makes sure that the target string only has characters the keyboard
|
||
can actually produce but there is a certain type of input error that might
|
||
<em>appear</em> to be a bug; see specifically <a href="#error">Input Error Example</a>.</p>
|
||
<h4 id="options">Options</h4>
|
||
<p>Skip to the <a href="#obfuscation">obfuscation section</a>.</p>
|
||
<p>There are a number of options you can pass to the program besides the target
|
||
string; some I will document here (the summary being in the man page). You can
|
||
join options but there is a caveat with spaces and <code>-r</code> option as well as
|
||
the target string (see below).</p>
|
||
<div id="quiet-mode">
|
||
<h4 id="enable-quiet-output">Enable quiet output:</h4>
|
||
</div>
|
||
<pre><code> -q</code></pre>
|
||
<p>This means don’t print the generation and offspring output; only print (some) of
|
||
the options set (this is always done but wouldn’t usually be seen due to verbose
|
||
output) and the final answer.</p>
|
||
<h4 id="change-the-mutation-rate-to-rate">Change the mutation rate to <code><rate></code>:</h4>
|
||
<pre><code> -r<num></code></pre>
|
||
<p>Please note that there cannot be a space between the <code>-r</code> and the number.
|
||
This is to simplify the parsing of options. As for combining options you can do
|
||
any of the following (amongst others):</p>
|
||
<pre><code> -r5q
|
||
-qr5
|
||
-qr
|
||
-q -r5</code></pre>
|
||
<p>The third invocation will set quiet output and have no valid value to parse for
|
||
the mutation rate and <code>strtol()</code> in this case returns 0. <code>strtol()</code> can
|
||
legitimately return 0 but in no instance is it valid input in this program: the
|
||
valid mutation rate is <code>>= 1 && <= 100</code>.</p>
|
||
<p>When the mutation rate is out of range it does something interesting: take a
|
||
look at the output and compare it to the output when the range is valid. Can you
|
||
figure out another way to trigger this? In fact there are two more ways (one is
|
||
an option I’ve mentioned and the other one is to do with the number of
|
||
offspring)! If you want something of a walk through I suggest you follow the
|
||
following:</p>
|
||
<ol type="1">
|
||
<li>Enable quiet mode and set an invalid mutation range; for example specify:</li>
|
||
</ol>
|
||
<pre><code> -qr101</code></pre>
|
||
<ol start="2" type="1">
|
||
<li>Take a look at the first few lines. Kill the program and try invoking it
|
||
with the following options:</li>
|
||
</ol>
|
||
<pre><code> -qr5</code></pre>
|
||
<ol start="3" type="1">
|
||
<li><p>Look at the first few lines again and compare it to the output of step #1.
|
||
With the default string most modern systems shouldn’t take much time to - given
|
||
decent parameters - come to an answer here but if necessary kill the program.</p></li>
|
||
<li><p>Repeat the steps only this time don’t enable quiet mode. Look at the
|
||
offspring output. If you still don’t see what it is and want to know see
|
||
<strong><a href="#obfuscation">obfuscation information</a></strong> below.</p></li>
|
||
</ol>
|
||
<p>Finally any argument that doesn’t start with a <code>-</code> passed into the program
|
||
will become the target string. The same rule applies to the number for <code>-r</code>:
|
||
it must be a single parameter which means you’ll need to quote the string if it
|
||
has more than one word (that is it contains spaces) or anything else interpreted
|
||
specially by your shell e.g. parentheses. For instance if you just want to find
|
||
<code>METHINKS</code> you could do one of:</p>
|
||
<pre><code> ./weasel METHINKS
|
||
./weasel "METHINKS"
|
||
./weasel 'METHINKS'</code></pre>
|
||
<p>If you wanted <code>YOU ARE A MONKEY</code>:</p>
|
||
<pre><code> ./weasel "YOU ARE A MONKEY"
|
||
./weasel 'YOU ARE A MONKEY'</code></pre>
|
||
<p>If you do one of:</p>
|
||
<pre><code> ./weasel "METHINKS IT IS A" "MONKEY"
|
||
./weasel METHINKS IT IS A MONKEY</code></pre>
|
||
<p>It will search for <code>MONKEY</code> in both cases; in other words it’s the last one.
|
||
If the string is too long given the value of <code>S</code> (see <strong><a href="#build">How to build</a></strong>)
|
||
it will be truncated.</p>
|
||
<p>If you actually do want to search for a string starting with a <code>-</code> you must
|
||
disable further parsing of options by using the <code>-</code> option itself; for
|
||
example if you were to do any of:</p>
|
||
<pre><code> ./weasel -q- -- -test
|
||
./weasel -q- -test
|
||
./weasel -q -- -test</code></pre>
|
||
<p>The target string will be: <code>-TEST</code>. This means though that here:</p>
|
||
<pre><code> ./weasel -q -- -test -r5</code></pre>
|
||
<p>The string to be searched would actually be <code>-r5</code> and the mutation rate will
|
||
remain the default because after the <code>-</code> option (that is <code>--</code>) is seen it will
|
||
no longer parse additional options: only target strings if anything left on the
|
||
command line. Because of the joining of arguments this means that the first two
|
||
examples of the last set of three above are equivalent i.e. the following two
|
||
are equivalent:</p>
|
||
<pre><code> -q-
|
||
-q --</code></pre>
|
||
<p>As for the caveat I referenced what does the following do?</p>
|
||
<pre><code> ./weasel -qr 5</code></pre>
|
||
<p>In fact it will set quiet output and set the target string to be ‘5’. So the
|
||
mutation rate will be out of range, thus enabling that Easter egg, but it will
|
||
likely come to an answer fairly quickly because it’s just a single character. A
|
||
note on the parsing of the <code>-</code> option; if the program is currently parsing
|
||
<code>argv[N]</code>, for example, and it encounters a <code>--</code> then depending on where
|
||
the other options are in the command line it might still parse the options. Thus
|
||
you have:</p>
|
||
<pre><code> $ ./weasel -qr-r5
|
||
quiet output
|
||
mutation rate out of range
|
||
target 'METHINKS IT IS LIKE A WEASEL'
|
||
mutation rate 5
|
||
Generation 440 Offspring 20: METHINKS IT IS LIKE A WEASEL</code></pre>
|
||
<p>Similarly this would set quiet output, then an invalid mutation rate and then a
|
||
mutation rate of 5:</p>
|
||
<pre><code> ./weasel --qrr5</code></pre>
|
||
<p>If you were instead to do one of (for example):</p>
|
||
<pre><code> ./weasel -q -- -r
|
||
./weasel -q -q- -r</code></pre>
|
||
<p>Then it <em>would</em> set quiet output then see the <code>--</code> (the <code>-</code> option
|
||
itself) and then the target string would <em>literally</em> be set to <code>-r</code> because
|
||
it no longer cares about the <code>-</code> for option parsing. In other words options
|
||
are only parsed if the first character is <code>-</code> and if the parser hasn’t seen
|
||
the <code>-</code> - <em>in an earlier element of <code>argv</code>. This is not a bug!</em></p>
|
||
<h4 id="easter-egg">Easter egg</h4>
|
||
<p>Skip to <a href="#invocations">Example Invocations</a>.</p>
|
||
<p>The Easter egg: since Dawkins references the <a href="https://en.wikipedia.org/wiki/Infinite_monkey_theorem">Infinite Monkey Theorem</a> it
|
||
simulates a monkey using a typewriter! This mode has the following changes:</p>
|
||
<p>Selection is omitted; this means no sorting by fitness score (<em>each offspring
|
||
is initially set to be the first two in the list</em>) but do pseudo-randomly
|
||
select characters for every character in the target string; that is to say if
|
||
the string is of length 28 (the default) then all 28 characters in each
|
||
offspring of each generation will be assigned a pseudo-randomly positioned
|
||
character in the keyboard. If you want to enable this specially you can use the
|
||
<code>-m</code> option (<em>-m for monkey</em>).</p>
|
||
<div id="invocations">
|
||
<h4 id="example-invocations">Example Invocations</h4>
|
||
</div>
|
||
<p>Skip to <a href="#error">Input Error Example</a>.</p>
|
||
<p>The following examples are used to demonstrate better the command line parsing.
|
||
In order to do that though I had to first document the <code>-m</code> option because
|
||
if the mutation rate is out of range monkey mode is activated (that’s the first
|
||
Easter egg). But what happens if you later set a valid mutation rate? Should
|
||
monkey mode be disabled? If yes how do we know if monkey mode was specially
|
||
requested? There are at least two ways to go about it: I took the monkey safe
|
||
(‘fool safe’) method; *if you explicitly request monkey mode you cannot disable
|
||
it in the same invocation of <code>weasel</code>!</p>
|
||
<pre><code> $ ./weasel -qr101r5r101r1r test
|
||
quiet output
|
||
mutation rate out of range
|
||
mutation rate out of range
|
||
mutation rate out of range
|
||
target 'test'
|
||
mutation rate 0
|
||
monkey at typewriter
|
||
Generation 16844 Offspring 22: TEST</code></pre>
|
||
<p>So in this case I joined the options in the following order:</p>
|
||
<ol type="1">
|
||
<li><p><code>-q</code></p>
|
||
<p>Quiet output.</p></li>
|
||
<li><p><code>-r101</code></p>
|
||
<p>Mutation rate 101 (out of range).</p></li>
|
||
<li><p><code>-r5</code></p>
|
||
<p>Mutation rate of 5 but note that during parsing I only print invalid mutation
|
||
rate (only after parsing do I print the final mutation rate whatever it ends up
|
||
being); so while it appears there is a bug, showing mutation rate out of range
|
||
three times, this is expected (given the next one, <code>-r101</code>). This means here
|
||
the typewriter was taken from Eric the monkey.</p></li>
|
||
<li><p><code>-r101</code></p>
|
||
<p>Mutation rate to 101: this too is out of range (this is the second mutation rate
|
||
out of range message). The typewriter returns to Eric.</p></li>
|
||
<li><p><code>-r1</code></p>
|
||
<p>Set mutation rate to 1. Take that typewriter away!</p></li>
|
||
<li><p><code>-r</code></p>
|
||
<p>Set mutation rate to 0; when there are no valid characters passed to
|
||
<code>strtol()</code> it should return 0: this is the third message about being out of
|
||
range. Note here that <code>rand()</code> returns an <code>int</code> and <code>strtol()</code>
|
||
returns a <code>long</code> but I compare the return value of <code>rand()</code> to the
|
||
mutation rate; if there are any systems where the widths differ this <em>shouldn’t
|
||
matter</em> because of truncation but I do in any case specifically check for <code>R < 0 || R > 100</code>. Either way the invalid range returns the typewriter to Eric.</p></li>
|
||
<li><p><code>test</code></p>
|
||
<p>Finally I requested it find the string <code>test</code> (will search for <code>TEST</code>).</p>
|
||
<p>Given that it was a short string it did find the answer relatively quickly,
|
||
even in monkey mode.</p>
|
||
<p>Another example:</p></li>
|
||
</ol>
|
||
<pre><code> $ ./weasel -q -r101 test -r5
|
||
quiet output
|
||
mutation rate out of range
|
||
target 'test'
|
||
mutation rate 5
|
||
Generation 109 Offspring 13: TEST</code></pre>
|
||
<p>In this case I also enabled quiet mode but I didn’t join the options; the
|
||
<code>-r101</code> reports that it’s out of range and sets monkey mode. I then specify
|
||
the target string and then set a valid mutation rate. This disabled monkey
|
||
mode which means that it’ll use the genetic algorithm.</p>
|
||
<p>One more example of monkey mode:</p>
|
||
<pre><code> $ ./weasel -q -mr101 test -r5
|
||
quiet output
|
||
mutation rate out of range
|
||
target 'test'
|
||
mutation rate 5
|
||
monkey at typewriter
|
||
Generation 465298 Offspring 10: TEST</code></pre>
|
||
<p>Here I also requested quiet output and then <em>explicitly requested that Eric
|
||
the monkey types.</em> After this I set the mutation rate to be 101 which would
|
||
have set monkey mode (<em>in this case only temporarily as I later set it to a
|
||
valid number</em>) but since I have also requested monkey mode that won’t
|
||
matter. Then I set the string to <code>test</code> and then set a valid mutation rate
|
||
of 5. Now note that it is actually set to 5 but also note that monkey mode
|
||
remains active: it also took a lot longer to come to a conclusion for even
|
||
four characters. This example does demonstrate one other thing in a subtle
|
||
way though.</p>
|
||
<p>When the program prints out each iteration (I’ll give an example next) it
|
||
goes a lot slower; this makes sense because printing is an expensive
|
||
operation. Here are the times for the same but without quiet output enabled:</p>
|
||
<pre><code> real 0m17.065s
|
||
user 0m1.245s
|
||
sys 0m2.402s</code></pre>
|
||
<p>.. whereas with quiet output:</p>
|
||
<pre><code> real 0m0.127s
|
||
user 0m0.125s
|
||
sys 0m0.001s</code></pre>
|
||
<p>Of course it isn’t only down to the printing but the point is it slows it
|
||
down significantly. Adding an option to print every X lines would go over
|
||
the limit (<code>iocccsize -i</code> reports 2052!).</p>
|
||
<ol start="8" type="1">
|
||
<li>Finally I’ll show a default example in normal output (I omit many lines showing
|
||
instead <code>[...]</code>). Note that the real/user/sys times are from the <code>time</code>
|
||
bash shell built-in utility: that isn’t output from my entry.</li>
|
||
</ol>
|
||
<pre><code> target 'METHINKS IT IS LIKE A WEASEL'
|
||
mutation rate 1
|
||
Generation 0 Offspring 1: 4V YGY.GH/}_|>Q1M.R8;KD[=(05
|
||
Generation 0 Offspring 2: Y_^S0_HZ399^/|9,MP%^{817"XX#
|
||
Generation 0 Offspring 3: F%88H1&[V1P>QOI}- U]0[V-Y%*[
|
||
[...]
|
||
Generation 1 Offspring 23: AHA#.\=ZT'0>?~-S.;1A L|1<S:^ -> AHA#.\=ZT'0>?~-S.;1A L|1<S:| (mutation)
|
||
Generation 1 Offspring 24: AHA#.\=ZT'0>?~-S.;1A L|1<S:^ -> AHA#.\=ZT'0>?~-S.;1A L|1<S:^ (mutation)
|
||
Generation 1 Offspring 25: AHA#.\=ZT'0>?~-S.;1A L|1<S:^ -> AHA#1\=ZT'0>?~-S.;1A L|1<S:^ (mutation)
|
||
**
|
||
Generation 2 Offspring 1: AHA#.\=ZT'0>?~-S.;1A L|1<S:^ -> AHA#.\=ZT'0>?~-S.;1A L|1<S:^ (mutation)
|
||
Generation 2 Offspring 2: AHA#.\=ZT'0>?~-S.;1A L|1<S:^ -> AHA#.\=ZT'O>?~-S.;1A L|1<S:^ (mutation)
|
||
[...]
|
||
Generation 979 Offspring 1: METHINKS ITZIS LIKE A WEASEL -> METHINKS IT IS LIKE A WEASEL (mutation)
|
||
[...]
|
||
**
|
||
Generation 979 Offspring 1: METHINKS IT IS LIKE A WEASEL
|
||
|
||
real 0m0.074s
|
||
user 0m0.040s
|
||
sys 0m0.001s</code></pre>
|
||
<p>Keep in mind the way I display the generations and the fact that generation 0
|
||
has no parents; it is generation 1 that starts working towards the goal. You’ll
|
||
see also <code>(mutation)</code> at the end of the line at this point (if you enable monkey
|
||
mode you’ll find that it shows something else). The lines that only have
|
||
back-quote (<code>"\`"</code>) are separators: you won’t see this between generation 0
|
||
and 1 but you will between future generations - as well as the final answer (if
|
||
the answer is in generation 0 you won’t see the <code>`</code>).</p>
|
||
<div id="test">
|
||
<p>One final thing to consider is that <strong>the program doesn’t directly read from a
|
||
file</strong>. This combined with the way the shell works could possibly confuse some
|
||
people. Take the following invocations:</p>
|
||
</div>
|
||
<pre><code> (1) $ echo test > test
|
||
(2) $ ./weasel test
|
||
(3) $ ./weasel < test
|
||
(4) $ cat test | ./weasel
|
||
(5) $ < test-strings.txt ./weasel
|
||
(6) $ cat | ./weasel</code></pre>
|
||
<p>Only the first invocation of <code>./weasel</code> will search for <code>TEST</code> because
|
||
the string <code>test</code> was explicitly passed to the program (If the file <code>test</code>
|
||
wasn’t found by that path it would still have searched for <code>TEST</code>).</p>
|
||
<p>The second invocation will search for the default string if there is a file or
|
||
directory called <code>test</code>; else you will get an error about no such file or
|
||
directory (unless your shell for some reason doesn’t consider it an error; bash
|
||
most certainly does consider it an error and halts).</p>
|
||
<p>The third invocation would if there exists a file <code>test</code> cat that file and
|
||
pipe the output to <code>./weasel</code>; <em>however it will search for the default
|
||
string.</em> If there is no such file to cat then an error will be reported but
|
||
without quiet mode you’d probably not even see the error.</p>
|
||
<p>The fourth invocation will also search for the default string unless the file
|
||
doesn’t exist in which case you’d get an error like in the second invocation.</p>
|
||
<p>The fifth invocation will actually search for the default string even with the
|
||
file <code>test-strings.txt</code> existing. As far as I am aware it’s equivalent to the
|
||
third invocation except that the file exists in this case.</p>
|
||
<p>The final invocation will search for the default and then read from <code>stdin</code>;
|
||
it won’t do anything with it however.</p>
|
||
<p>What this amounts to is <em>if you want input from a file you have to read from the
|
||
file and pass each string to the program itself</em>. I’ve included a script
|
||
<code>test.sh</code> and a file of sample input <code>test-strings.txt</code> that you can play
|
||
with.</p>
|
||
<p>Try:</p>
|
||
<pre><code> make test</code></pre>
|
||
<p>This will essentially make sure the program is compiled and then do:</p>
|
||
<pre><code> chmod +x test.sh
|
||
./test.sh</code></pre>
|
||
<p>The script will first try compiling the program (if necessary) and if it fails
|
||
for any reason it will exit; else it will read each line in the file
|
||
<code>test-strings.txt</code> (if the file doesn’t exist or can’t be read the script will
|
||
exit with return status of 1) and pass it to the program. After finding the
|
||
string it’ll sleep approximately 2 seconds and then read the next string
|
||
(passing it to the program, continuing until all the strings have been read and
|
||
processed).</p>
|
||
<p>You can pass additional options directly to the script but remember that it
|
||
stops when there are no more strings in the file - so if you try:</p>
|
||
<pre><code> ./test.sh -q test</code></pre>
|
||
<p>The final string <code>test</code> won’t be searched for; it will however run the program
|
||
in all invocations with quiet output enabled. The following are some notes about
|
||
how the shell and the program interact with each other:</p>
|
||
<p>Because the script quotes the strings that it reads from the file if you were to
|
||
put in the file: <code>-q STRING</code> quiet mode would be enabled; however the
|
||
default string would be searched for. If the quotes were removed from the script
|
||
it would print the final word specified. To be specific with the quotes: if in
|
||
the file you had the line <code>-q STRING -m TEST</code> it would enable quiet output
|
||
and monkey typewriter mode; but it would search for the default string. Without
|
||
the quotes on the other hand it would enable quiet output, monkey typewriter and
|
||
search for <code>TEST</code>. In other words <strong>if you want to pass options to the
|
||
script you will have to directly pass the options to the script</strong> like the above
|
||
example shows (but the strings will still only be read from the
|
||
<code>test-strings.txt</code> file).</p>
|
||
<div id="error">
|
||
<h4 id="input-error-example">Input Error Example</h4>
|
||
</div>
|
||
<p>Skip to <a href="#obfuscation">Obfuscation</a>.</p>
|
||
<p>There is a type of input error, as I said, that might appear to be a bug. What
|
||
actually is going on though is due to a technicality on how spaces are printed
|
||
and the fact the program does not accept spaces other than a literal space
|
||
<code></code>; when a character in the string to be found isn’t in the keyboard the
|
||
program prints an error message and then exits (returning 1). But since the
|
||
keyboard doesn’t have <code>'\n'</code> if you were to type a <code>'</code> and send a
|
||
<code>'\n'</code> before the closing <code>'</code> you might see something like:</p>
|
||
<pre><code> $ ./weasel '!!
|
||
> '
|
||
|
||
'
|
||
' not in keyboard " !"#$<%:>&'()*+,-./0123456789;=?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_`{|}~"</code></pre>
|
||
<p>I showed that <code>'</code> is in the keyboard already; however the user sent a
|
||
<code>\n</code> (hence the secondary prompt <code>></code> on line two) before literally typing the
|
||
closing <code>'</code> (also line two). But in order to make it clear what character is invalid I
|
||
surround the character with <code>'</code>s so what you actually see after typing the
|
||
closing <code>'</code> and hitting Enter (or however you send the <code>'\n'</code>) there is
|
||
the third blank line; <em>but then the program prints</em> <code>'</code> followed by the
|
||
invalid character (<code>'\n'</code> itself which means another line break) and then
|
||
finally the closing <code>'</code>. Specifically <code>isspace()</code> characters aren’t
|
||
distinctly seen like a letter, digit or symbol is: <code>isprint('\n') == 0 && isspace('\n') == 1</code>. You can add these characters but the output will be
|
||
rather confusing and hard to read.</p>
|
||
<h3 id="obfuscation">Obfuscation</h3>
|
||
<h4 id="techniques">Techniques</h4>
|
||
<p>Skip to <a href="#beauty">Beauty</a>.</p>
|
||
<p>The following might be some of the techniques used in this entry:</p>
|
||
<ol start="0" type="1">
|
||
<li><p>Helpful and descriptive names for all variables and constants (like <code>S</code>)
|
||
as well as some C keywords.</p></li>
|
||
<li><p>The way <code>main()</code> is declared is:</p></li>
|
||
</ol>
|
||
<pre><code> /* Special C main() handler (encapsulation): */
|
||
#define r(main) main
|
||
r(k main(k a, E **V)) {</code></pre>
|
||
<p>It appears to be recursively defined but is it? And is it truly
|
||
encapsulation? And is it executing code of any kind? It mightn’t seem like it
|
||
isn’t encapsulation and also isn’t executing code but assuming it’s
|
||
encapsulation and executing code is it actually nothing? And if it’s nothing why
|
||
is it there? If it is something what is it doing? Could it be both? Or maybe it
|
||
really isn’t nothing or nothing? :)</p>
|
||
<ol start="2" type="1">
|
||
<li><p>A special C parser called <code>H()</code>. It might help to observe that there
|
||
might be recursive calls and much of the program might use it. Or so it seems.
|
||
Then again it might not help to not notice it.</p></li>
|
||
<li><p>Digraphs. In their simplest form it’s probably not a big deal but consider:
|
||
some source code formatters don’t like them at all (neither, incidentally, does
|
||
<code>splint</code>, which completely baulks). There also is a trick; if you try
|
||
translating them then depending upon how you do it there can be functional
|
||
changes in the program!</p></li>
|
||
<li><p>The fact the program can by default print the primorial prime of 97 (<em>but that
|
||
default isn’t the default - except when it IS the default!</em>) and yet that number
|
||
isn’t seen at all. See also technique #7.</p></li>
|
||
<li><p>Another usual suspect: the source is formatted in a beautiful design that
|
||
could be described artistic; on the other hand some might suggest it’s just a
|
||
blob of octets <em>but I disprove this when discussing beauty later on in the next
|
||
section.</em></p></li>
|
||
<li><p>The string <strong>METHINKS IT IS LIKE A WEASEL</strong> is searched for by default
|
||
(except when it’s not searched by default) but it’s nowhere to be found in the
|
||
source file in that form. Why? Because anyone familiar with the Weasel program
|
||
won’t recognise the string and put together what it is by looking at the source
|
||
code.</p></li>
|
||
</ol>
|
||
<p>In case you wondered deciphering #4 won’t decipher #6 (neither will
|
||
deciphering #6 help you decipher #4).</p>
|
||
<h3 id="beauty">Beauty</h3>
|
||
<p>Skip to <a href="#build">How to build</a>.</p>
|
||
<p>On the subject of beauty: the judges stated in the guidelines the following:</p>
|
||
<blockquote>
|
||
<p>We want to get away from source that is simply <strong>a compact blob of octets.</strong>
|
||
Really try to be more creative than <strong>blob coding.</strong> <em>HINT!</em></p>
|
||
</blockquote>
|
||
<p>And if you’ll notice that although it <em>might look like a compact blob of octets</em>
|
||
(although not really: a blob is by definition roundish) at first glance if you
|
||
look throughout the file you’ll see two statements to set your thinking
|
||
straight:</p>
|
||
<blockquote>
|
||
<p><strong>NO BLOB CODING</strong></p>
|
||
<p><strong>THIS IS NOT A COMPACT BLOB OF OCTETS</strong></p>
|
||
</blockquote>
|
||
<p>So you see even if your eyes are trying to deceive you they’re quite wrong. Yes
|
||
some of it might look like a blob (for certain definitions of ‘blob’ :) ) but
|
||
this is clearly false; <em>as all good programmers know if something is potentially
|
||
confusing or misleading it should be made clear in the comments! :)</em></p>
|
||
<div id="build">
|
||
<h3 id="how-to-build">5. How to build</h3>
|
||
</div>
|
||
<div id="constants">
|
||
<h4 id="s-m-and-n-constants">S, M and N Constants</h4>
|
||
</div>
|
||
<p>Skip to <a href="#compiling">Compilation</a>.</p>
|
||
<p>There are three <code>#define</code>d constants that can be redefined at compilation to modify the
|
||
behaviour of the program in a number of ways (see the
|
||
<strong><a href="#compiling">Compilation</a></strong> subsection for example invocations). Both are
|
||
capped to be no greater than <code>SIZE_MAX - 1</code> or whatever <code>M</code> (which can’t be
|
||
lower than 100) is set to (maximum attempts before giving up). This is handled
|
||
by the C preprocessor.</p>
|
||
<ul>
|
||
<li><code>S</code></li>
|
||
</ul>
|
||
<p>The macro <code>S</code> (or <code>MAX_SIZE</code> in the Makefile) is the maximum size of the target
|
||
string but it <strong>must be at least 38</strong> (which is protected against in the code);
|
||
this is because <code>38 >= 29</code> and because <code>strlen("METHINKS IT IS LIKE A WEASEL") == 28</code> (which is the default target string - it would hardly be an
|
||
implementation of the Weasel program otherwise).</p>
|
||
<p>There is obviously a reason <code>38</code> is the chosen size but the only hints I
|
||
provide are those in <strong><a href="#how">How it works</a></strong> and specifically an Easter egg I
|
||
referenced there (it’s <em>not the only Easter egg</em> but it’s the only Easter egg I
|
||
won’t spoil; yes this ironically and amusingly means I’ve left a rotten egg
|
||
somewhere!).</p>
|
||
<p>The Makefile simplifies how to reconfigure this value with the variable
|
||
<code>MAX_SIZE</code>:</p>
|
||
<pre><code> make clobber MAX_SIZE=55 all</code></pre>
|
||
<p>The next macro that can be reconfigured, <code>M</code> (or <code>MAX_ATTEMPTS</code> in the
|
||
Makefile), is the maximum attempts before giving up. This was added as another
|
||
feature in 2024 but it was not made an alt version because there already is an
|
||
alt version. This macro allows for seeing what happens when reaching the maximum
|
||
number attempts without waiting for a very long time.</p>
|
||
<p>The Makefile simplifies how to reconfigure this value with the variable
|
||
<code>MAX_ATTEMPTS</code>:</p>
|
||
<pre><code> make clobber MAX_ATTEMPTS=100 all</code></pre>
|
||
<p>The final macro, <code>N</code> (or <code>OFFSPRING</code> in the Makefile), is the number of offspring
|
||
per generation.</p>
|
||
<p>Anything less than 4 will be set to 3 (that’s not a typo!) and this is part of
|
||
an Easter egg.</p>
|
||
<p>Be aware that depending on the size of <code>S</code> (<code>MAX_SIZE</code>) and <code>N</code> (<code>OFFSPRING</code>)
|
||
both individually and together the program will use varying amounts of memory
|
||
and the larger the values the more memory it’ll require.</p>
|
||
<p>The Makefile simplifies how to reconfigure this value with the variable
|
||
<code>OFFSPRING</code>:</p>
|
||
<pre><code> make clobber OFFSPRING=55 all</code></pre>
|
||
<div id="compiling">
|
||
<h3 id="compilation">Compilation</h3>
|
||
</div>
|
||
<p>Skip to <a href="#portability">Portability</a>.</p>
|
||
<p>The following options <strong>must always be passed to the compiler:</strong></p>
|
||
<pre><code> -DQ='typedef' -D'g(o)'='goto o;' -D'w(x)'="x:" -D'H(main)'='r(main)'</code></pre>
|
||
<p>which running <code>make</code> will always do.</p>
|
||
<p>If you want to increase the number of offspring to <code>50</code> (<code>N</code>) and the size of the
|
||
chromosome to <code>75</code> (<code>S</code>) you would do:</p>
|
||
<pre><code> make clobber OFFSPRING=50 MAX_SIZE=75 everything</code></pre>
|
||
<p>If you wanted to change <code>N</code> to <code>3</code>:</p>
|
||
<pre><code> make clobber OFFSPRING=3 everything</code></pre>
|
||
<p>Remember that it cannot be less than <code>3</code>; <em>more correctly if it’s less than
|
||
4 it’s redefined to 3</em> so you could have passed in <code>-DN=2</code> (or <code>MAX_SIZE=2</code>) and have the same
|
||
result. Remember too that <code>S</code> (<code>MAX_SIZE</code>) cannot be less than <code>38</code>. Both <code>S</code> and
|
||
<code>N</code> are capped at <code>SIZE_MAX - 1</code> or whatever <code>M</code> (<code>MAX_ATTEMPTS</code>) is set to.</p>
|
||
<p>If you wanted to change the maximum number attempts to 100 you could do:</p>
|
||
<pre><code> make clobber MAX_ATTEMPTS=100 everything</code></pre>
|
||
<h3 id="portability">Portability</h3>
|
||
<p>Skip to <a href="#bugs">Bugs</a>.</p>
|
||
<p>This entry requires at least C99 even if you translate digraphs. The program
|
||
doesn’t require third-party libraries and should work on any Unix based system.
|
||
It works on both 64-bit and 32-bit (but inevitably some data type sizes will be
|
||
smaller and this I believe includes <code>SIZE_MAX</code>). I don’t think Windows gcc
|
||
ports would have many issues (if any) either but I have no way to test this.
|
||
Originally I tested it on the below systems.</p>
|
||
<h4 id="fedora-26">Fedora 26:</h4>
|
||
<pre><code> $ clang --version|head -n1
|
||
clang version 4.0.1 (tags/RELEASE_401/final)
|
||
$ gcc --version|head -n1
|
||
gcc (GCC) 7.3.1 20180130 (Red Hat 7.3.1-2)
|
||
$ /lib64/libc-2.25.so |head -n1|cut -d',' -f1-1
|
||
GNU C Library (GNU libc) stable release version 2.25
|
||
$ lscpu |grep Endian
|
||
Byte Order: Little Endian</code></pre>
|
||
<h4 id="centos-linux-release-7.4.1708-core">CentOS Linux release 7.4.1708 (Core)</h4>
|
||
<pre><code> $ clang --version|head -n1
|
||
clang version 3.4.2 (tags/RELEASE_34/dot2-final)
|
||
$ gcc --version|head -n1
|
||
gcc (GCC) 4.8.5 20150623 (Red Hat 4.8.5-16)
|
||
$ /lib64/libc-2.17.so |head -n1 |cut -d, -f1-1
|
||
GNU C Library (GNU libc) stable release version 2.17
|
||
$ lscpu |grep Endian
|
||
Byte Order: Little Endian</code></pre>
|
||
<h4 id="fedora-27">Fedora 27:</h4>
|
||
<pre><code> $ clang --version|head -n1
|
||
clang version 5.0.1 (tags/RELEASE_501/final)
|
||
$ gcc --version|head -n1
|
||
gcc (GCC) 7.3.1 20180303 (Red Hat 7.3.1-5)
|
||
$ /lib64/libc-2.26.so |head -n1|cut -d, -f1-1
|
||
GNU C Library (GNU libc) stable release version 2.26
|
||
$ lscpu |grep Endian
|
||
Byte Order: Little Endian</code></pre>
|
||
<h4 id="macos">macOS:</h4>
|
||
<p>System Version: macOS 10.13.4 (17E199)
|
||
Kernel Version: Darwin 17.5.0</p>
|
||
<pre><code> $ gcc -v
|
||
Configured with: --prefix=/Library/Developer/CommandLineTools/usr --with-gxx-include-dir=/usr/include/c++/4.2.1
|
||
Apple LLVM version 9.1.0 (clang-902.0.39.1)
|
||
Target: x86_64-apple-darwin17.5.0
|
||
Thread model: posix
|
||
InstalledDir: /Library/Developer/CommandLineTools/usr/bin
|
||
$ uname -srmv
|
||
Darwin 17.5.0 Darwin Kernel Version 17.5.0: Mon Mar 5 22:24:32 PST 2018; root:xnu-4570.51.1~1/RELEASE_X86_64 x86_64</code></pre>
|
||
<h4 id="bugs">Bugs</h4>
|
||
<p>Skip to <a href="#rpm">Installing</a>.</p>
|
||
<p>Any undocumented bugs are the result of insolent monkeys tampering with any
|
||
number of things. That includes but is not limited to running the program on a
|
||
non-ASCII system; non little-endian; meddling with <code>S</code> or <code>N</code> too much,
|
||
changing the references to <code>SIZE_MAX</code> to be larger than <code>SIZE_MAX</code> or a
|
||
signed value (<code>size_t</code> is unsigned) or too small of a value; changing data
|
||
types or variables; expecting really long strings - including but not limited to
|
||
the complete works of Shakespeare (hint: <code>isprint('\n') == 0</code> so it won’t
|
||
ever find any string with <code>'\n'</code>) - to be found by the program in a quick
|
||
and easy fashion if ever; or any other meddling including being petulant and/or
|
||
unreasonable monkeys. I will say though that there is at least one place I see
|
||
after having won that could be slightly more efficient (can you find it?); I am
|
||
however leaving it as it is because this is what won.</p>
|
||
<div id="rpm">
|
||
<h3 id="installing">Installing</h3>
|
||
</div>
|
||
<p>Skip to <a href="#thoughts">Final thoughts</a>.</p>
|
||
<p>I have included a RPM spec file for those with a Red Hat based Linux
|
||
distribution; see <a href="rpm.html">rpm.html</a> for details (including why I implemented
|
||
this) if for some (strange or maybe even mad) reason you’re interested, which
|
||
I fully realise and always realised means nobody but me. Indeed not only do I
|
||
know nobody else would use it but I would recommend against it as well. It was a
|
||
personal thing and since the Judges remarked about it I kept it in.</p>
|
||
<div id="thoughts">
|
||
<h3 id="final-thoughts">Final thoughts</h3>
|
||
</div>
|
||
<p>Skip to <a href="#winning">Winning comments</a>.</p>
|
||
<p>The judges suggested that making them laugh helps entries chance of winning.
|
||
Well <em>laughter helps everything</em> so in case you haven’t seen - and <em>even if you
|
||
have seen</em> - Dennis Ritchie’s anti-foreword to the ghastly <em>UNIX-HATERS
|
||
Handbook</em> or Ken Thompson’s revelation that C and Unix are a hoax (at the end of
|
||
that book) I include it below; because I agree that looking at a lot of twisted
|
||
code must be quite difficult (though maybe not as much as if you were to have to
|
||
look at Microsoft Windows code or code for Windows in any case ? :)) and these
|
||
two things I think are rather amusing (in order of least to most):</p>
|
||
<div id="dmr">
|
||
<h4 id="dennis-ritchies-anti-foreword">Dennis Ritchie’s Anti-Foreword:</h4>
|
||
</div>
|
||
<blockquote>
|
||
<p>Anti-Foreword</p>
|
||
<p>By Dennis Ritchie
|
||
From: dmr@plan9.research.att.com
|
||
Date: Tue, 15 Mar 1994 00:38:07 EST
|
||
Subject: anti-foreword</p>
|
||
<p>To the contributers to this book:</p>
|
||
<p>I have succumbed to the temptation you offered in your preface: I do write you
|
||
off as envious malcontents and romantic keepers of memories. The systems you
|
||
remember so fondly (TOPS-20, ITS, Multics, Lisp Machine, Cedar/Mesa, the Dorado)
|
||
are not just out to pasture, they are fertilizing it from below.</p>
|
||
<p>Your judgments are not keen, they are intoxicated by metaphor. In the Preface
|
||
you suffer first from heat, lice, and malnourishment, then become prisoners in
|
||
a Gulag. In Chapter 1 you are in turn infected by a virus, racked by drug
|
||
addiction, and addled by puffiness of the genome.</p>
|
||
<p>Yet your prison without coherent design continues to imprison you. How can
|
||
this be, if it has no strong places? The rational prisoner exploits the weak
|
||
places, creates order from chaos: instead, collectives like the FSF vindicate
|
||
their jailers by building cells almost compatible with the existing ones, albeit
|
||
with more features. The journalist with three undergraduate degrees from MIT,
|
||
the researcher at Microsoft, and the senior scientist at Apple might volunteer a
|
||
few words about the regulations of the prisons to which they have been
|
||
transferred.</p>
|
||
<p>Your sense of the possible is in no sense pure: sometimes you want the same
|
||
thing you have, but wish you had done it yourselves; other times you want
|
||
something different, but can’t seem to get people to use it; sometimes one
|
||
wonders why you just don’t shut up and tell people to buy a PC with Windows or a
|
||
Mac. No Gulag or lice, just a future whose intellectual tone and interaction
|
||
style is set by Sonic the Hedgehog. You claim to seek progress, but you succeed
|
||
mainly in whining.</p>
|
||
<p>Here is my metaphor: your book is a pudding stuffed with apposite
|
||
observations, many well-conceived. Like excrement, it contains enough undigested
|
||
nuggets of nutrition to sustain life for some. But it is not a tasty pie: it
|
||
reeks too much of contempt and of envy.</p>
|
||
<p>Bon appetit!</p>
|
||
</blockquote>
|
||
<p>Yes he misspelt <em>‘contributors’</em>! But then again we’re talking about obfuscation
|
||
and since it doesn’t break his message it’s not broken - it’s just obfuscated
|
||
albeit not very much (and it still <em>‘compiles’!</em>); and isn’t that what this
|
||
contest is about? :)</p>
|
||
<div id="ken">
|
||
<h4 id="ken-thompsons-ending">Ken Thompson’s ending:</h4>
|
||
</div>
|
||
<blockquote>
|
||
<p>Creators Admit C, Unix Were Hoax</p>
|
||
<p>FOR IMMEDIATE RELEASE</p>
|
||
<p>In an announcement that has stunned the computer industry, Ken Thompson,
|
||
Dennis Ritchie, and Brian Kernighan admitted that the Unix operating system and
|
||
C programming language created by them is an elaborate April Fools prank kept
|
||
alive for more than 20 years. Speaking at the recent UnixWorld Software
|
||
Development Forum, Thompson revealed the following:</p>
|
||
<p>“In 1969, AT&T had just terminated their work with the GE/AT&T Multics
|
||
project. Brian and I had just started working with an early release of Pascal
|
||
from Professor Nichlaus Wirth’s ETH labs in Switzerland, and we were impressed
|
||
with its elegant simplicity and power. Dennis had just finished reading Bored of
|
||
the Rings, a hilarious National Lampoon parody of the great Tolkien Lord of the
|
||
Rings trilogy. As a lark, we decided to do parodies of the Multics environment
|
||
and Pascal. Dennis and I were responsible for the operating environment. We
|
||
looked at Multics and designed the new system to be as complex and cryptic as
|
||
possible to maximize casual users’ frustration levels, calling it Unix as a
|
||
parody of Multics, as well as other more risque allusions.</p>
|
||
<p>“Then Dennis and Brian worked on a truly warped version of Pascal, called”A.” When we found others were actually trying to programs with A, we quickly
|
||
added additional cryptic features and evolved into B, BCPL, and finally C. We
|
||
stopped when we got a clean compile on the following syntax:</p>
|
||
</blockquote>
|
||
<pre><code> for(;P("\n"),R=;P("|"))for(e=C;e=P("_"+(*u++/
|
||
8)%2))P("|"+(*u/4)%2);</code></pre>
|
||
<blockquote>
|
||
<p>“To think that modern programmers would try to use a language that allowed
|
||
such a statement was beyond our comprehension! We actually thought of selling
|
||
this to the Soviets to set their computer science progress back 20 or more
|
||
years. Imagine our surprise when AT&T and other U.S. corporations actually began
|
||
trying to use Unix and C! It has taken them 20 years to develop enough
|
||
expertise to generate even marginally useful applications using this 1960s
|
||
technological parody, but we are impressed with the tenacity (if not common
|
||
sense) of the general Unix and C programmer.</p>
|
||
<p>“In any event, Brian, Dennis, and I have been working exclusively in Lisp
|
||
on the Apple Macintosh for the past few years and feel really guilty about the
|
||
chaos, confusion, and truly bad programming that has resulted from our silly
|
||
prank so long ago.”</p>
|
||
<p>Major Unix and C vendors and customers, including AT&T, Microsoft,
|
||
Hewlett-Packard, GTE, NCR, and DEC have refused comment at this time. Borland
|
||
International, a leading vendor of Pascal and C tools, including the popular
|
||
Turbo Pascal, Turbo C, and Turbo C++, stated they had suspected this for a
|
||
number of years and would continue to enhance their Pascal products and halt
|
||
further efforts to develop C. An IBM spokesman broke into uncontrolled laughter
|
||
and had to postpone a hastily convened news conference concerning the fate of
|
||
the RS/6000, merely stating “Workplace OS will be available Real Soon Now.” In a
|
||
cryptic statement, Professor Wirth of the ETH Institute and father of the
|
||
Pascal, Modula 2, and Oberon structured languages, merely stated that P. T.
|
||
Barnum was correct.</p>
|
||
</blockquote>
|
||
<hr>
|
||
<p>So is it a hoax about a non-hoax, a non-hoax about a hoax, a non-hoax about a
|
||
non-hoax or is it a hoax about a hoax ? :) And if it’s any of those what does it
|
||
mean about Unix and C? And if a hoax is involved <em>what is the hoax?</em> The pedant
|
||
and Tolkienist that I am has to state that <strong>Tolkien didn’t consider The Lord of
|
||
the Rings a trilogy</strong> <em>(and he made that very clear)</em> but that doesn’t take away
|
||
from the humour by any stretch (<em>if anyone wants me to elaborate or debate the
|
||
matter do send me an email - I love Tolkien’s Legendarium and having another
|
||
person to talk about it with is more than welcome!</em>). Ken suggested that there
|
||
is a lack of common sense but since he was part of its creation I don’t think
|
||
it’s a bad thing; <strong>on the contrary it makes all of us C programmers even more
|
||
talented! :)</strong> I do wonder if he tested that bit of C code though:</p>
|
||
<pre><code> for(;P("\n"),R=;P("|"))for(e=C;e=P("_"+(*u++/
|
||
8)%2))P("|"+(*u/4)%2);</code></pre>
|
||
<p>How is <code>R=;</code> valid? Since I don’t have the context maybe there is something
|
||
I’m missing but either way it’s a funny piece. It could also be for irony itself
|
||
(actually I had previously thought of somehow implementing something like that
|
||
for the contest but decided for the message by itself in the end). I would
|
||
prefer believing that whether true or not.</p>
|
||
<div id="winning">
|
||
<h3 id="winning-comments-thanks-dedications-links-etc.">Winning comments, thanks, dedications, links, etc.</h3>
|
||
</div>
|
||
<p>I feel incredibly honoured, privileged and I am extremely happy and proud to
|
||
have won! I am more proud and happy about this than anything I have ever done in
|
||
my life and I don’t think there can be anything else I can be more proud of in
|
||
the future (except winning again should I find or think of another interesting
|
||
thing to try and implement in an obfuscated way). Because winning is one thing;
|
||
but to be included amongst very clever and talented veterans whom I highly
|
||
respect is an incredible badge of honour that I will proudly wear (literally too
|
||
as I hope to get my entry on a shirt) for the rest of my life. This type of
|
||
badge is something I feel most only dream of but never come close to earning.
|
||
That I did is by far the best feeling I can think of.</p>
|
||
<p>Thank you Simon Cooper, Landon Curt Noll and Leonid A. Broukhis, and thank you
|
||
to everyone who has been an important and special part of my life. I want to
|
||
specially name some:</p>
|
||
<p>I dedicated this program to my beloved but recently late dog Venus; instead of
|
||
drowning in grief I channelled it to creativity. And to have won a contest
|
||
requiring creativity, cleverness and novelty is a tribute to an equally
|
||
creative, clever and unique dog that she was. I miss you terribly Venus but I’m
|
||
so happy to have had you in my life.</p>
|
||
<p>But I want to also dedicate it to (and thank) my dear friend <a href="https://www.ficture.nl">Martijn
|
||
Schoemaker</a> whom provided me with the spark a very long
|
||
time ago (and whom has stood by me and helped me in more ways than he can know -
|
||
<code>#including C</code>); if it wasn’t for you Martijn I wouldn’t have been able to
|
||
win so consider this a recursive thank you thank you! :)</p>
|
||
<p>I would also like to give thanks and much love to my dear friend Vicky Wilmore
|
||
who means the absolute world to me; thank you for being such a wonderfully
|
||
beautiful person and friend - that truly is what ‘just you’ means, sweetheart,
|
||
and don’t you forget it! <3</p>
|
||
<p>Finally I would like to thank my mother for being the best mum anyone could ask
|
||
for, who’s always been here for me and whom I also inherit the keen analytical
|
||
mind from. I love you all!</p>
|
||
<p>I want to also thank <a href="../../authors.html#Dave_Burton">Dave Burton</a> for acknowledging me in
|
||
his <a href="../../authors.html#Dave_Burton">Dave Burton</a> for his <a href="../burton2/index.html">2018/burton2</a>
|
||
entry for as he put it ‘being relentless with pursuit of bugs’. To think that it
|
||
was circumstantial to my entry too makes it all the more unlikely but that
|
||
doesn’t take away the significance of it; for I am a very symbolic person and
|
||
being acknowledged for this type of thing is great but to be acknowledged for it
|
||
by someone who has won more than once is even more special to me: thank you
|
||
Dave! It means a great deal to me and I am glad I could help! :)</p>
|
||
<p>I would also like to say to the judges about their commentary as well as the
|
||
category title: they’re all very dear to me and that includes not just the
|
||
remarks but the example invocations. They fit my views precisely. As for the
|
||
test-strings.txt file modifications: very amusing and I certainly do not object.
|
||
Thank you again for such an honour and privilege! That this isn’t a dream is the
|
||
best reality imaginable! :)</p>
|
||
<p>Congratulations to one and all for winning; it’s an honour to win such a
|
||
wonderful contest requiring creativity, cleverness, uniqueness and
|
||
inventiveness but to win beside all the other wonderful entries is truly
|
||
special!</p>
|
||
<p>I have more information on the winning entry at
|
||
<a href="https://ioccc.xexyl.net/2018/weasel">https://ioccc.xexyl.net/2018/weasel</a> including how to contact me (besides
|
||
what’s already published on the IOCCC website). I have commentary on the other
|
||
winning entries as well.</p>
|
||
<p>If you wish to contact me please do so. Please contact via mastodon. You can try
|
||
email but I’m more likely to respond to mastodon messages.</p>
|
||
<div id="monkey2024">
|
||
<h3 id="update-on-the-infinite-monkey-theorem-2024">Update on the Infinite Monkey Theorem, 2024</h3>
|
||
</div>
|
||
<p>On 1 November 2024 I saw an article called <a href="https://phys.org/news/2024-10-monkey-unable-hamlet-lifetime-universe.html">Typing monkey would be unable to
|
||
produce ‘Hamlet’ within the lifetime of the universe, study
|
||
finds</a>.
|
||
This interested me greatly given my foray into the Infinite Monkey Theorem, for
|
||
this entry, and I’d like to briefly comment on it.</p>
|
||
<p>What I found interesting is the beginning where it says that it would take far
|
||
longer than the lifetime of our universe as they say it’s still technically true
|
||
that Eric the monkey could type out the complete works of Shakespeare given
|
||
enough time, it is misleading.</p>
|
||
<p>With what I did I believe that I have shown how very hard it is and what’s more
|
||
is that something ignored is that even if this was true the monkey would not
|
||
live long enough. There is one possible exception.</p>
|
||
<p>If Eric was taught to type and to read then it would be possible. But then that
|
||
would not be the Infinite Monkey Theorem as it says specifically typing at
|
||
random.</p>
|
||
<p>Another thing that interested me in this article is a quote from the
|
||
mathematicians:</p>
|
||
<blockquote>
|
||
<p>‘The Infinite Monkey Theorem only considers the infinite limit, with either an
|
||
infinite number of monkeys or an infinite time period of monkey labour,’ said
|
||
Associate Professor Woodcock.</p>
|
||
</blockquote>
|
||
<p>Yes, this is why it’s called the ‘<strong>Infinite</strong> Monkey Theorem’. It’s a fun study
|
||
to consider, maybe, but it’s likely just as silly as the original theorem and
|
||
even the difference of the Weasel program and the original theory (I believe
|
||
there are some minor differences as described below).</p>
|
||
<p>A difference from the Weasel program, which is what my entry is, is that the
|
||
monkey has an easier time by making the keyboard the 26 capital letters and the
|
||
space bar. I am not sure how exactly this diverges from the Infinite Monkey
|
||
Theorem, however. They did in this study include punctuation and the letters
|
||
whereas I also diverged slightly from the Weasel program, namely by including
|
||
more than just space and the 26 English capital letters, though the alternate
|
||
version has a simpler keyboard.</p>
|
||
<p>This was both interesting and amusing:</p>
|
||
<blockquote>
|
||
<p>The results reveal that it is possible (around a 5% chance) for a single chimp
|
||
to type the word ‘bananas’ in its own lifetime.</p>
|
||
</blockquote>
|
||
<p>My question would be: will Eric be given bananas for typing ‘<em>bananas</em>’? Well
|
||
we’ll probably never know. Still, a silly study for a silly theorem but all in
|
||
good fun, I suppose.</p>
|
||
<!--
|
||
|
||
Copyright © 1984-2024 by Landon Curt Noll. All Rights Reserved.
|
||
|
||
You are free to share and adapt this file under the terms of this license:
|
||
|
||
Creative Commons Attribution-ShareAlike 4.0 International (CC BY-SA 4.0)
|
||
|
||
For more information, see:
|
||
|
||
https://creativecommons.org/licenses/by-sa/4.0/
|
||
|
||
-->
|
||
<!-- AFTER: last line of markdown file: 2018/ferguson/README.md -->
|
||
|
||
<!-- END: this line ends content for HTML phase 21 by: bin/pandoc-wrapper.sh via bin/md2html.sh -->
|
||
<!-- START: this line starts content for HTML phase 22 by: bin/output-index-inventory.sh via bin/md2html.sh -->
|
||
|
||
<!-- START: this line starts content generated by: bin/output-index-inventory.sh -->
|
||
|
||
<div id="inventory">
|
||
<h1 id="inventory-for-2018ferguson">Inventory for 2018/ferguson</h1>
|
||
</div>
|
||
<h2 id="primary-files">Primary files</h2>
|
||
<ul>
|
||
<li><a href="https://github.com/ioccc-src/winner/blob/master/2018/ferguson/prog.c">prog.c</a> - entry source code</li>
|
||
<li><a href="https://github.com/ioccc-src/winner/blob/master/2018/ferguson/Makefile">Makefile</a> - entry Makefile</li>
|
||
<li><a href="https://github.com/ioccc-src/winner/blob/master/2018/ferguson/prog.alt.c">prog.alt.c</a> - alternate source code</li>
|
||
<li><a href="https://github.com/ioccc-src/winner/blob/master/2018/ferguson/prog.orig.c">prog.orig.c</a> - original source code</li>
|
||
<li><a href="FILES.html">FILES.html</a> - list of files in this entry</li>
|
||
<li><a href="https://github.com/ioccc-src/winner/blob/master/2018/ferguson/FILES.md">FILES.md</a> - markdown source for FILES.html</li>
|
||
<li><a href="https://github.com/ioccc-src/winner/blob/master/2018/ferguson/id.alt.sh">id.alt.sh</a> - script to run alternate code to disprove intelligent design</li>
|
||
<li><a href="https://github.com/ioccc-src/winner/blob/master/2018/ferguson/id.sh">id.sh</a> - script to run code to disprove intelligent design</li>
|
||
<li><a href="https://github.com/ioccc-src/winner/blob/master/2018/ferguson/monkey-words.alt.sh">monkey-words.alt.sh</a> - script to run alternate code in monkey mode</li>
|
||
<li><a href="https://github.com/ioccc-src/winner/blob/master/2018/ferguson/monkey-words.sh">monkey-words.sh</a> - script to run entry in monkey mode</li>
|
||
<li><a href="rpm.html">rpm.html</a> - about forming the rpm</li>
|
||
<li><a href="https://github.com/ioccc-src/winner/blob/master/2018/ferguson/test.sh">test.sh</a> - run the test suite</li>
|
||
<li><a href="https://github.com/ioccc-src/winner/blob/master/2018/ferguson/try.alt.sh">try.alt.sh</a> - script to try alternate code</li>
|
||
<li><a href="https://github.com/ioccc-src/winner/blob/master/2018/ferguson/try.sh">try.sh</a> - script to try entry</li>
|
||
<li><a href="https://github.com/ioccc-src/winner/blob/master/2018/ferguson/weasel.1">weasel.1</a> - weasel program man page</li>
|
||
<li><a href="https://github.com/ioccc-src/winner/blob/master/2018/ferguson/weasel.spec">weasel.spec</a> - RPM spec file</li>
|
||
</ul>
|
||
<h2 id="secondary-files">Secondary files</h2>
|
||
<ul>
|
||
<li><a href="2018_ferguson.tar.bz2">2018_ferguson.tar.bz2</a> - download entry tarball</li>
|
||
<li><a href="https://github.com/ioccc-src/winner/blob/master/2018/ferguson/README.md">README.md</a> - markdown source for this web page</li>
|
||
<li><a href="https://github.com/ioccc-src/winner/blob/master/2018/ferguson/.entry.json">.entry.json</a> - entry summary and manifest in JSON</li>
|
||
<li><a href="https://github.com/ioccc-src/winner/blob/master/2018/ferguson/.gitignore">.gitignore</a> - list of files that should not be committed under git</li>
|
||
<li><a href="https://github.com/ioccc-src/winner/blob/master/2018/ferguson/hint.css">hint.css</a> - CSS for index in rpm</li>
|
||
<li><a href="https://github.com/ioccc-src/winner/blob/master/2018/ferguson/.path">.path</a> - directory path from top level directory</li>
|
||
<li><a href="https://github.com/ioccc-src/winner/blob/master/2018/ferguson/rpm.md">rpm.md</a> - markdown source for rpm.html</li>
|
||
<li><a href="test-strings.txt">test-strings.txt</a> - test.sh input file</li>
|
||
<li><a href="index.html">index.html</a> - this web page</li>
|
||
</ul>
|
||
<hr style="width:10%;text-align:left;margin-left:0">
|
||
<h4>
|
||
Jump to: <a href="#">top</a>
|
||
</h4>
|
||
|
||
<!-- END: next line ends content generated by: bin/output-index-inventory.sh -->
|
||
|
||
<!-- END: this line ends content for HTML phase 22 by: bin/output-index-inventory.sh via bin/md2html.sh -->
|
||
<!-- START: this line starts content from: inc/after-content.default.html -->
|
||
|
||
</div>
|
||
|
||
<!-- END: this line ends content from: inc/after-content.default.html -->
|
||
<!-- START: this line starts content from: inc/footer.inventory.html -->
|
||
|
||
<!--
|
||
|
||
Copyright © 1984-2025 by Landon Curt Noll. All Rights Reserved.
|
||
|
||
You are free to share and adapt this file under the terms of this license:
|
||
|
||
Creative Commons Attribution-ShareAlike 4.0 International (CC BY-SA 4.0)
|
||
|
||
For more information, see:
|
||
|
||
https://creativecommons.org/licenses/by-sa/4.0/
|
||
|
||
-->
|
||
|
||
<div class="footer">
|
||
|
||
<div id="copyright"><h3>Copyright © 1984-2025 by Landon Curt Noll:
|
||
<a href="https://creativecommons.org/faq/#what-does-some-rights-reserved-mean"
|
||
target="_blank"
|
||
rel="license noopener noreferrer">Some Rights Reserved</a></h3>
|
||
<p>
|
||
This work is <b>licensed by Landon Curt Noll</b> under
|
||
<b><a href="https://creativecommons.org/licenses/by-sa/4.0/?ref=chooser-v1"
|
||
target="_blank"
|
||
rel="license noopener noreferrer"
|
||
style="display:inline-block;">CC BY-SA 4.0</a></b>.
|
||
<img style="height:22px!important;margin-left:3px;vertical-align:text-bottom;"
|
||
src="../../png/cc.png"
|
||
alt="cc inside circle symbol">
|
||
<img style="height:22px!important;margin-left:3px;vertical-align:text-bottom;"
|
||
src="../../png/by.png"
|
||
alt="person inside circle symbol">
|
||
<img style="height:22px!important;margin-left:3px;vertical-align:text-bottom;"
|
||
src="../../png/sa.png"
|
||
alt="arrow looping back on itself inside circle symbol"><br>
|
||
You should <b>carefully review</b> the
|
||
<b><a href="https://creativecommons.org/licenses/by-sa/4.0/legalcode.en"
|
||
target="_blank"
|
||
rel="license noopener noreferrer">CC BY-SA 4.0 LEGAL CODE</a></b>
|
||
before using the licensed material.<br>
|
||
You may wish to review the
|
||
<b><a href="../../license.html"
|
||
target="_blank"
|
||
rel="license noopener noreferrer">highlights of some of the key features and terms</a></b>
|
||
of <b>CC BY-SA 4.0</b>.<br>
|
||
</p>
|
||
</div>
|
||
|
||
<div id="coda"><h3>Coda</h3>
|
||
<p>
|
||
<a href="https://validator.w3.org/nu/?doc=https%3A%2F%2Fwww.ioccc.org%2F2018%2Fferguson%2Findex.html" rel="nofollow">Nu HTML check this web page</a><br>
|
||
<a href="#top">Jump to top</a> <a href="#content">Jump to Content</a> <a href="#inventory">Jump to Inventory</a><br>
|
||
</p>
|
||
</div>
|
||
|
||
</div>
|
||
|
||
<!-- END: this line ends content from: inc/footer.inventory.html -->
|
||
<!-- START: this line starts content from: inc/bottom.default.html -->
|
||
|
||
</body>
|
||
</html>
|
||
|
||
<!-- END: this line ends content from: inc/bottom.default.html -->
|