summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--gemfeed/2023-04-09-algorithms-in-golang-part-1.gmi229
-rw-r--r--gemfeed/2023-04-09-algorithms-in-golang-part-1.gmi.tpl229
-rw-r--r--gemfeed/atom.xml467
-rw-r--r--gemfeed/index.gmi1
-rw-r--r--index.gmi3
-rw-r--r--uptime-stats.gmi2
6 files changed, 732 insertions, 199 deletions
diff --git a/gemfeed/2023-04-09-algorithms-in-golang-part-1.gmi b/gemfeed/2023-04-09-algorithms-in-golang-part-1.gmi
new file mode 100644
index 00000000..2ac5faa8
--- /dev/null
+++ b/gemfeed/2023-04-09-algorithms-in-golang-part-1.gmi
@@ -0,0 +1,229 @@
+# Algorithms in Go - Part 1
+
+> Published at 2023-04-09T21:48:36+03:00
+
+```
+ ,_---~~~~~----._
+ _,,_,*^____ _____``*g*\"*,
+ / __/ /' ^. / \ ^@q f
+[ @f | @)) | | @)) l 0 _/
+ \`/ \~____ / __ \_____/ \
+ | _l__l_ I
+ } [______] I
+ ] | | | |
+ ] ~ ~ |
+ | |
+ | |
+```
+
+This is the first blog post about my Algorithms in Go series. I am not a Software Developer in my day job. In my current role, programming and scripting skills are desirable but not mandatory. I have been learning about Data Structures and Algorithms many years ago at University. I thought it would be fun to revisit/refresh my knowledge here and implement many of the algorithms in Go.
+
+=> ./2023-04-09-algorithms-in-golang-part-1.gmi 2023-04-09 Algorithms in Go - Part 1 (You are currently reading this)
+
+This post is about setting up some basic data structures and methods for this blog series. I promise, everything will be easy to follow in this post.
+
+## Type constraints
+
+First, the package `ds` (data structures) defines the `types.go`. All examples will either operate on the `Integer` or `Number` type:
+
+```go
+package ds
+
+import (
+ "golang.org/x/exp/constraints"
+)
+
+type Integer interface {
+ constraints.Integer
+}
+
+type Number interface {
+ constraints.Integer | constraints.Float
+}
+
+```
+
+## ArrayList
+
+Next comes the `arraylist.go`, which defines the underlying data structure all the algorithms of this series will use. `ArrayList` is just a type alias of a Go array (or slice) with custom methods on it:
+
+```go
+package ds
+
+import (
+ "fmt"
+ "math/rand"
+ "strings"
+)
+
+type ArrayList[V Number] []V
+
+func NewArrayList[V Number](l int) ArrayList[V] {
+ return make(ArrayList[V], l)
+}
+```
+
+As you can see, the code uses Go generics, which I refactored recently. Besides the default constructor (which only returns an empty `ArrayList` with a given capacity), there are also a bunch of special constructors. `NewRandomArrayList` is returning an `ArrayList` with random numbers, `NewAscendingArrayList` and `NewDescendingArrayList` are returning `ArrayList`s in either ascending or descending order. They all will be used later on for testing and benchmarking the algorithms.
+
+```go
+func NewRandomArrayList[V Number](l, max int) ArrayList[V] {
+ a := make(ArrayList[V], l)
+ for i := 0; i < l; i++ {
+ if max > 0 {
+ a[i] = V(rand.Intn(max))
+ continue
+ }
+ a[i] = V(rand.Int())
+ }
+ return a
+}
+
+func NewAscendingArrayList[V Number](l int) ArrayList[V] {
+ a := make(ArrayList[V], l)
+ for i := 0; i < l; i++ {
+ a[i] = V(i)
+ }
+ return a
+}
+
+func NewDescendingArrayList[V Number](l int) ArrayList[V] {
+ a := make(ArrayList[V], l)
+ j := l - 1
+ for i := 0; i < l; i++ {
+ a[i] = V(j)
+ j--
+ }
+ return a
+}
+```
+
+## Helper methods
+
+The `FirstN` method only returns the first N elements of the `ArrayList`. This is useful for printing out only parts of the data structure:
+
+```go
+func (a ArrayList[V]) FirstN(n int) string {
+ var sb strings.Builder
+ j := n
+
+ l := len(a)
+ if j > l {
+ j = l
+ }
+
+ for i := 0; i < j; i++ {
+ fmt.Fprintf(&sb, "%v ", a[i])
+ }
+
+ if j < l {
+ fmt.Fprintf(&sb, "... ")
+ }
+
+ return sb.String()
+}
+```
+
+The `Sorted` method checks whether the `ArrayList` is sorted. This will be used by the unit tests later on:
+
+```go
+func (a ArrayList[V]) Sorted() bool {
+ for i := len(a) - 1; i > 0; i-- {
+ if a[i] < a[i-1] {
+ return false
+ }
+ }
+ return true
+}
+```
+
+And the last utility method used is `Swap`, which allows swapping the values of two indices in the `ArrayList`:
+
+```go
+func (a ArrayList[V]) Swap(i, j int) {
+ aux := a[i]
+ a[i] = a[j]
+ a[j] = aux
+}
+
+```
+
+## Sleep sort
+
+Let's implement our first algorithm, sleep sort. Sleep sort is a non-traditional and unconventional sorting algorithm based on the idea of waiting a certain amount of time corresponding to the value of each element in the input `ArrayList`. It's more of a fun, creative concept rather than an efficient or practical sorting technique. This is not a sorting algorithm you would use in any production code. As you can imagine, it is quite an inefficient sorting algorithm (it's only listed here as a warm-up exercise). This sorting method may also return false results depending on how the Goroutines are scheduled by the Go runtime.
+
+
+```go
+package sort
+
+import (
+ "codeberg.org/snonux/algorithms/ds"
+ "sync"
+ "time"
+)
+
+func Sleep[V ds.Integer](a ds.ArrayList[V]) ds.ArrayList[V] {
+ sorted := ds.NewArrayList[V](len(a))
+
+ numCh := make(chan V)
+ var wg sync.WaitGroup
+ wg.Add(len(a))
+
+ go func() {
+ wg.Wait()
+ close(numCh)
+ }()
+
+ for _, num := range a {
+ go func(num V) {
+ defer wg.Done()
+ time.Sleep(time.Duration(num) * time.Second)
+ numCh <- num
+ }(num)
+ }
+
+ for num := range numCh {
+ sorted = append(sorted, num)
+ }
+
+ return sorted
+}
+```
+
+### Testing
+
+For testing, we only allow values up to 10, as otherwise, it would take too long to finish:
+
+```go
+package sort
+
+import (
+ "fmt"
+ "testing"
+
+ "codeberg.org/snonux/algorithms/ds"
+)
+
+func TestSleepSort(t *testing.T) {
+ a := ds.NewRandomArrayList[int](10, 10)
+ a = Sleep(a)
+ if !a.Sorted() {
+ t.Errorf("Array not sorted: %v", a)
+ }
+}
+```
+
+As you can see, it takes `9s` here for the algorithm to finish (which is the highest value in the `ArrayList`):
+
+```sh
+❯ go test ./sort -v -run SleepSort
+=== RUN TestSleepSort
+--- PASS: TestSleepSort (9.00s)
+PASS
+ok codeberg.org/snonux/algorithms/sort 9.002s
+```
+
+I won't write any benchmark for sleep sort; that will be done for the algorithms to come in this series :-).
+
+E-Mail your comments to hi@paul.cyou :-)
+
+=> ../ Back to the main site
diff --git a/gemfeed/2023-04-09-algorithms-in-golang-part-1.gmi.tpl b/gemfeed/2023-04-09-algorithms-in-golang-part-1.gmi.tpl
new file mode 100644
index 00000000..a8a583b5
--- /dev/null
+++ b/gemfeed/2023-04-09-algorithms-in-golang-part-1.gmi.tpl
@@ -0,0 +1,229 @@
+# Algorithms in Go - Part 1
+
+> Published at 2023-04-09T21:48:36+03:00
+
+```
+ ,_---~~~~~----._
+ _,,_,*^____ _____``*g*\"*,
+ / __/ /' ^. / \ ^@q f
+[ @f | @)) | | @)) l 0 _/
+ \`/ \~____ / __ \_____/ \
+ | _l__l_ I
+ } [______] I
+ ] | | | |
+ ] ~ ~ |
+ | |
+ | |
+```
+
+This is the first blog post about my Algorithms in Go series. I am not a Software Developer in my day job. In my current role, programming and scripting skills are desirable but not mandatory. I have been learning about Data Structures and Algorithms many years ago at University. I thought it would be fun to revisit/refresh my knowledge here and implement many of the algorithms in Go.
+
+<< template::inline::index algorithms-in-golang-part
+
+This post is about setting up some basic data structures and methods for this blog series. I promise, everything will be easy to follow in this post.
+
+## Type constraints
+
+First, the package `ds` (data structures) defines the `types.go`. All examples will either operate on the `Integer` or `Number` type:
+
+```go
+package ds
+
+import (
+ "golang.org/x/exp/constraints"
+)
+
+type Integer interface {
+ constraints.Integer
+}
+
+type Number interface {
+ constraints.Integer | constraints.Float
+}
+
+```
+
+## ArrayList
+
+Next comes the `arraylist.go`, which defines the underlying data structure all the algorithms of this series will use. `ArrayList` is just a type alias of a Go array (or slice) with custom methods on it:
+
+```go
+package ds
+
+import (
+ "fmt"
+ "math/rand"
+ "strings"
+)
+
+type ArrayList[V Number] []V
+
+func NewArrayList[V Number](l int) ArrayList[V] {
+ return make(ArrayList[V], l)
+}
+```
+
+As you can see, the code uses Go generics, which I refactored recently. Besides the default constructor (which only returns an empty `ArrayList` with a given capacity), there are also a bunch of special constructors. `NewRandomArrayList` is returning an `ArrayList` with random numbers, `NewAscendingArrayList` and `NewDescendingArrayList` are returning `ArrayList`s in either ascending or descending order. They all will be used later on for testing and benchmarking the algorithms.
+
+```go
+func NewRandomArrayList[V Number](l, max int) ArrayList[V] {
+ a := make(ArrayList[V], l)
+ for i := 0; i < l; i++ {
+ if max > 0 {
+ a[i] = V(rand.Intn(max))
+ continue
+ }
+ a[i] = V(rand.Int())
+ }
+ return a
+}
+
+func NewAscendingArrayList[V Number](l int) ArrayList[V] {
+ a := make(ArrayList[V], l)
+ for i := 0; i < l; i++ {
+ a[i] = V(i)
+ }
+ return a
+}
+
+func NewDescendingArrayList[V Number](l int) ArrayList[V] {
+ a := make(ArrayList[V], l)
+ j := l - 1
+ for i := 0; i < l; i++ {
+ a[i] = V(j)
+ j--
+ }
+ return a
+}
+```
+
+## Helper methods
+
+The `FirstN` method only returns the first N elements of the `ArrayList`. This is useful for printing out only parts of the data structure:
+
+```go
+func (a ArrayList[V]) FirstN(n int) string {
+ var sb strings.Builder
+ j := n
+
+ l := len(a)
+ if j > l {
+ j = l
+ }
+
+ for i := 0; i < j; i++ {
+ fmt.Fprintf(&sb, "%v ", a[i])
+ }
+
+ if j < l {
+ fmt.Fprintf(&sb, "... ")
+ }
+
+ return sb.String()
+}
+```
+
+The `Sorted` method checks whether the `ArrayList` is sorted. This will be used by the unit tests later on:
+
+```go
+func (a ArrayList[V]) Sorted() bool {
+ for i := len(a) - 1; i > 0; i-- {
+ if a[i] < a[i-1] {
+ return false
+ }
+ }
+ return true
+}
+```
+
+And the last utility method used is `Swap`, which allows swapping the values of two indices in the `ArrayList`:
+
+```go
+func (a ArrayList[V]) Swap(i, j int) {
+ aux := a[i]
+ a[i] = a[j]
+ a[j] = aux
+}
+
+```
+
+## Sleep sort
+
+Let's implement our first algorithm, sleep sort. Sleep sort is a non-traditional and unconventional sorting algorithm based on the idea of waiting a certain amount of time corresponding to the value of each element in the input `ArrayList`. It's more of a fun, creative concept rather than an efficient or practical sorting technique. This is not a sorting algorithm you would use in any production code. As you can imagine, it is quite an inefficient sorting algorithm (it's only listed here as a warm-up exercise). This sorting method may also return false results depending on how the Goroutines are scheduled by the Go runtime.
+
+
+```go
+package sort
+
+import (
+ "codeberg.org/snonux/algorithms/ds"
+ "sync"
+ "time"
+)
+
+func Sleep[V ds.Integer](a ds.ArrayList[V]) ds.ArrayList[V] {
+ sorted := ds.NewArrayList[V](len(a))
+
+ numCh := make(chan V)
+ var wg sync.WaitGroup
+ wg.Add(len(a))
+
+ go func() {
+ wg.Wait()
+ close(numCh)
+ }()
+
+ for _, num := range a {
+ go func(num V) {
+ defer wg.Done()
+ time.Sleep(time.Duration(num) * time.Second)
+ numCh <- num
+ }(num)
+ }
+
+ for num := range numCh {
+ sorted = append(sorted, num)
+ }
+
+ return sorted
+}
+```
+
+### Testing
+
+For testing, we only allow values up to 10, as otherwise, it would take too long to finish:
+
+```go
+package sort
+
+import (
+ "fmt"
+ "testing"
+
+ "codeberg.org/snonux/algorithms/ds"
+)
+
+func TestSleepSort(t *testing.T) {
+ a := ds.NewRandomArrayList[int](10, 10)
+ a = Sleep(a)
+ if !a.Sorted() {
+ t.Errorf("Array not sorted: %v", a)
+ }
+}
+```
+
+As you can see, it takes `9s` here for the algorithm to finish (which is the highest value in the `ArrayList`):
+
+```sh
+❯ go test ./sort -v -run SleepSort
+=== RUN TestSleepSort
+--- PASS: TestSleepSort (9.00s)
+PASS
+ok codeberg.org/snonux/algorithms/sort 9.002s
+```
+
+I won't write any benchmark for sleep sort; that will be done for the algorithms to come in this series :-).
+
+E-Mail your comments to hi@paul.cyou :-)
+
+=> ../ Back to the main site
diff --git a/gemfeed/atom.xml b/gemfeed/atom.xml
index 2ac864ea..4d2e1753 100644
--- a/gemfeed/atom.xml
+++ b/gemfeed/atom.xml
@@ -1,12 +1,281 @@
<?xml version="1.0" encoding="utf-8"?>
<feed xmlns="http://www.w3.org/2005/Atom">
- <updated>2023-04-09T14:08:52+03:00</updated>
+ <updated>2023-04-09T21:48:36+03:00</updated>
<title>foo.zone feed</title>
<subtitle>To be in the .zone!</subtitle>
<link href="gemini://foo.zone/gemfeed/atom.xml" rel="self" />
<link href="gemini://foo.zone/" />
<id>gemini://foo.zone/</id>
<entry>
+ <title>Algorithms in Go - Part 1</title>
+ <link href="gemini://foo.zone/gemfeed/2023-04-09-algorithms-in-golang-part-1.gmi" />
+ <id>gemini://foo.zone/gemfeed/2023-04-09-algorithms-in-golang-part-1.gmi</id>
+ <updated>2023-04-09T21:48:36+03:00</updated>
+ <author>
+ <name>Paul Buetow</name>
+ <email>hi@paul.cyou</email>
+ </author>
+ <summary>This is the first blog post about my Algorithms in Go series. I am not a Software Developer in my day job. In my current role, programming and scripting skills are desirable but not mandatory. I have been learning about Data Structures and Algorithms many years ago at University. I thought it would be fun to revisit/refresh my knowledge here and implement many of the algorithms in Go.</summary>
+ <content type="xhtml">
+ <div xmlns="http://www.w3.org/1999/xhtml">
+ <h1 style='display: inline'>Algorithms in Go - Part 1</h1><br />
+<br />
+<pre>
+ ,_---~~~~~----._
+ _,,_,*^____ _____``*g*\"*,
+ / __/ /' ^. / \ ^@q f
+[ @f | @)) | | @)) l 0 _/
+ \`/ \~____ / __ \_____/ \
+ | _l__l_ I
+ } [______] I
+ ] | | | |
+ ] ~ ~ |
+ | |
+ | |
+</pre>
+<br />
+<span>This is the first blog post about my Algorithms in Go series. I am not a Software Developer in my day job. In my current role, programming and scripting skills are desirable but not mandatory. I have been learning about Data Structures and Algorithms many years ago at University. I thought it would be fun to revisit/refresh my knowledge here and implement many of the algorithms in Go.</span><br />
+<br />
+<a class='textlink' href='./2023-04-09-algorithms-in-golang-part-1.html'>2023-04-09 Algorithms in Go - Part 1 (You are currently reading this)</a><br />
+<br />
+<span>This post is about setting up some basic data structures and methods for this blog series. I promise, everything will be easy to follow in this post.</span><br />
+<br />
+<h2 style='display: inline'>Type constraints</h2><br />
+<br />
+<span>First, the package <span class='inlinecode'>ds</span> (data structures) defines the <span class='inlinecode'>types.go</span>. All examples will either operate on the <span class='inlinecode'>Integer</span> or <span class='inlinecode'>Number</span> type:</span><br />
+<br />
+<!-- Generator: GNU source-highlight 3.1.9
+by Lorenzo Bettini
+http://www.lorenzobettini.it
+http://www.gnu.org/software/src-highlite -->
+<pre><b><font color="#0000FF">package</font></b> ds
+
+<b><font color="#0000FF">import</font></b> <font color="#990000">(</font>
+ <font color="#FF0000">"golang.org/x/exp/constraints"</font>
+<font color="#990000">)</font>
+
+<b><font color="#0000FF">type</font></b> Integer <b><font color="#0000FF">interface</font></b> <font color="#FF0000">{</font>
+ constraints<font color="#990000">.</font>Integer
+<font color="#FF0000">}</font>
+
+<b><font color="#0000FF">type</font></b> Number <b><font color="#0000FF">interface</font></b> <font color="#FF0000">{</font>
+ constraints<font color="#990000">.</font>Integer <font color="#990000">|</font> constraints<font color="#990000">.</font>Float
+<font color="#FF0000">}</font>
+
+</pre>
+<br />
+<h2 style='display: inline'>ArrayList</h2><br />
+<br />
+<span>Next comes the <span class='inlinecode'>arraylist.go</span>, which defines the underlying data structure all the algorithms of this series will use. <span class='inlinecode'>ArrayList</span> is just a type alias of a Go array (or slice) with custom methods on it:</span><br />
+<br />
+<!-- Generator: GNU source-highlight 3.1.9
+by Lorenzo Bettini
+http://www.lorenzobettini.it
+http://www.gnu.org/software/src-highlite -->
+<pre><b><font color="#0000FF">package</font></b> ds
+
+<b><font color="#0000FF">import</font></b> <font color="#990000">(</font>
+ <font color="#FF0000">"fmt"</font>
+ <font color="#FF0000">"math/rand"</font>
+ <font color="#FF0000">"strings"</font>
+<font color="#990000">)</font>
+
+<b><font color="#0000FF">type</font></b> ArrayList<font color="#990000">[</font>V Number<font color="#990000">]</font> <font color="#990000">[]</font>V
+
+<b><font color="#0000FF">func</font></b> NewArrayList<font color="#990000">[</font>V Number<font color="#990000">](</font>l int<font color="#990000">)</font> ArrayList<font color="#990000">[</font>V<font color="#990000">]</font> <font color="#FF0000">{</font>
+ <b><font color="#0000FF">return</font></b> <b><font color="#000000">make</font></b><font color="#990000">(</font>ArrayList<font color="#990000">[</font>V<font color="#990000">],</font> l<font color="#990000">)</font>
+<font color="#FF0000">}</font>
+</pre>
+<br />
+<span>As you can see, the code uses Go generics, which I refactored recently. Besides the default constructor (which only returns an empty <span class='inlinecode'>ArrayList</span> with a given capacity), there are also a bunch of special constructors. <span class='inlinecode'>NewRandomArrayList</span> is returning an <span class='inlinecode'>ArrayList</span> with random numbers, <span class='inlinecode'>NewAscendingArrayList</span> and <span class='inlinecode'>NewDescendingArrayList</span> are returning <span class='inlinecode'>ArrayList</span>s in either ascending or descending order. They all will be used later on for testing and benchmarking the algorithms.</span><br />
+<br />
+<!-- Generator: GNU source-highlight 3.1.9
+by Lorenzo Bettini
+http://www.lorenzobettini.it
+http://www.gnu.org/software/src-highlite -->
+<pre><b><font color="#0000FF">func</font></b> NewRandomArrayList<font color="#990000">[</font>V Number<font color="#990000">](</font>l<font color="#990000">,</font> max int<font color="#990000">)</font> ArrayList<font color="#990000">[</font>V<font color="#990000">]</font> <font color="#FF0000">{</font>
+ a <font color="#990000">:=</font> <b><font color="#000000">make</font></b><font color="#990000">(</font>ArrayList<font color="#990000">[</font>V<font color="#990000">],</font> l<font color="#990000">)</font>
+ <b><font color="#0000FF">for</font></b> i <font color="#990000">:=</font> <font color="#993399">0</font><font color="#990000">;</font> i <font color="#990000">&lt;</font> l<font color="#990000">;</font> i<font color="#990000">++</font> <font color="#FF0000">{</font>
+ <b><font color="#0000FF">if</font></b> max <font color="#990000">&gt;</font> <font color="#993399">0</font> <font color="#FF0000">{</font>
+ a<font color="#990000">[</font>i<font color="#990000">]</font> <font color="#990000">=</font> <b><font color="#000000">V</font></b><font color="#990000">(</font>rand<font color="#990000">.</font><b><font color="#000000">Intn</font></b><font color="#990000">(</font>max<font color="#990000">))</font>
+ <b><font color="#0000FF">continue</font></b>
+ <font color="#FF0000">}</font>
+ a<font color="#990000">[</font>i<font color="#990000">]</font> <font color="#990000">=</font> <b><font color="#000000">V</font></b><font color="#990000">(</font>rand<font color="#990000">.</font><b><font color="#000000">Int</font></b><font color="#990000">())</font>
+ <font color="#FF0000">}</font>
+ <b><font color="#0000FF">return</font></b> a
+<font color="#FF0000">}</font>
+
+<b><font color="#0000FF">func</font></b> NewAscendingArrayList<font color="#990000">[</font>V Number<font color="#990000">](</font>l int<font color="#990000">)</font> ArrayList<font color="#990000">[</font>V<font color="#990000">]</font> <font color="#FF0000">{</font>
+ a <font color="#990000">:=</font> <b><font color="#000000">make</font></b><font color="#990000">(</font>ArrayList<font color="#990000">[</font>V<font color="#990000">],</font> l<font color="#990000">)</font>
+ <b><font color="#0000FF">for</font></b> i <font color="#990000">:=</font> <font color="#993399">0</font><font color="#990000">;</font> i <font color="#990000">&lt;</font> l<font color="#990000">;</font> i<font color="#990000">++</font> <font color="#FF0000">{</font>
+ a<font color="#990000">[</font>i<font color="#990000">]</font> <font color="#990000">=</font> <b><font color="#000000">V</font></b><font color="#990000">(</font>i<font color="#990000">)</font>
+ <font color="#FF0000">}</font>
+ <b><font color="#0000FF">return</font></b> a
+<font color="#FF0000">}</font>
+
+<b><font color="#0000FF">func</font></b> NewDescendingArrayList<font color="#990000">[</font>V Number<font color="#990000">](</font>l int<font color="#990000">)</font> ArrayList<font color="#990000">[</font>V<font color="#990000">]</font> <font color="#FF0000">{</font>
+ a <font color="#990000">:=</font> <b><font color="#000000">make</font></b><font color="#990000">(</font>ArrayList<font color="#990000">[</font>V<font color="#990000">],</font> l<font color="#990000">)</font>
+ j <font color="#990000">:=</font> l <font color="#990000">-</font> <font color="#993399">1</font>
+ <b><font color="#0000FF">for</font></b> i <font color="#990000">:=</font> <font color="#993399">0</font><font color="#990000">;</font> i <font color="#990000">&lt;</font> l<font color="#990000">;</font> i<font color="#990000">++</font> <font color="#FF0000">{</font>
+ a<font color="#990000">[</font>i<font color="#990000">]</font> <font color="#990000">=</font> <b><font color="#000000">V</font></b><font color="#990000">(</font>j<font color="#990000">)</font>
+ j<font color="#990000">--</font>
+ <font color="#FF0000">}</font>
+ <b><font color="#0000FF">return</font></b> a
+<font color="#FF0000">}</font>
+</pre>
+<br />
+<h2 style='display: inline'>Helper methods</h2><br />
+<br />
+<span>The <span class='inlinecode'>FirstN</span> method only returns the first N elements of the <span class='inlinecode'>ArrayList</span>. This is useful for printing out only parts of the data structure:</span><br />
+<br />
+<!-- Generator: GNU source-highlight 3.1.9
+by Lorenzo Bettini
+http://www.lorenzobettini.it
+http://www.gnu.org/software/src-highlite -->
+<pre><b><font color="#0000FF">func</font></b> <font color="#990000">(</font>a ArrayList<font color="#990000">[</font>V<font color="#990000">])</font> <b><font color="#000000">FirstN</font></b><font color="#990000">(</font>n int<font color="#990000">)</font> <font color="#009900">string</font> <font color="#FF0000">{</font>
+ <b><font color="#0000FF">var</font></b> sb strings<font color="#990000">.</font>Builder
+ j <font color="#990000">:=</font> n
+
+ l <font color="#990000">:=</font> <b><font color="#000000">len</font></b><font color="#990000">(</font>a<font color="#990000">)</font>
+ <b><font color="#0000FF">if</font></b> j <font color="#990000">&gt;</font> l <font color="#FF0000">{</font>
+ j <font color="#990000">=</font> l
+ <font color="#FF0000">}</font>
+
+ <b><font color="#0000FF">for</font></b> i <font color="#990000">:=</font> <font color="#993399">0</font><font color="#990000">;</font> i <font color="#990000">&lt;</font> j<font color="#990000">;</font> i<font color="#990000">++</font> <font color="#FF0000">{</font>
+ fmt<font color="#990000">.</font><b><font color="#000000">Fprintf</font></b><font color="#990000">(&amp;</font>sb<font color="#990000">,</font> <font color="#FF0000">"%v "</font><font color="#990000">,</font> a<font color="#990000">[</font>i<font color="#990000">])</font>
+ <font color="#FF0000">}</font>
+
+ <b><font color="#0000FF">if</font></b> j <font color="#990000">&lt;</font> l <font color="#FF0000">{</font>
+ fmt<font color="#990000">.</font><b><font color="#000000">Fprintf</font></b><font color="#990000">(&amp;</font>sb<font color="#990000">,</font> <font color="#FF0000">"... "</font><font color="#990000">)</font>
+ <font color="#FF0000">}</font>
+
+ <b><font color="#0000FF">return</font></b> sb<font color="#990000">.</font><b><font color="#000000">String</font></b><font color="#990000">()</font>
+<font color="#FF0000">}</font>
+</pre>
+<br />
+<span>The <span class='inlinecode'>Sorted</span> method checks whether the <span class='inlinecode'>ArrayList</span> is sorted. This will be used by the unit tests later on:</span><br />
+<br />
+<!-- Generator: GNU source-highlight 3.1.9
+by Lorenzo Bettini
+http://www.lorenzobettini.it
+http://www.gnu.org/software/src-highlite -->
+<pre><b><font color="#0000FF">func</font></b> <font color="#990000">(</font>a ArrayList<font color="#990000">[</font>V<font color="#990000">])</font> <b><font color="#000000">Sorted</font></b><font color="#990000">()</font> <font color="#009900">bool</font> <font color="#FF0000">{</font>
+ <b><font color="#0000FF">for</font></b> i <font color="#990000">:=</font> <b><font color="#000000">len</font></b><font color="#990000">(</font>a<font color="#990000">)</font> <font color="#990000">-</font> <font color="#993399">1</font><font color="#990000">;</font> i <font color="#990000">&gt;</font> <font color="#993399">0</font><font color="#990000">;</font> i<font color="#990000">--</font> <font color="#FF0000">{</font>
+ <b><font color="#0000FF">if</font></b> a<font color="#990000">[</font>i<font color="#990000">]</font> <font color="#990000">&lt;</font> a<font color="#990000">[</font>i<font color="#990000">-</font><font color="#993399">1</font><font color="#990000">]</font> <font color="#FF0000">{</font>
+ <b><font color="#0000FF">return</font></b> false
+ <font color="#FF0000">}</font>
+ <font color="#FF0000">}</font>
+ <b><font color="#0000FF">return</font></b> true
+<font color="#FF0000">}</font>
+</pre>
+<br />
+<span>And the last utility method used is <span class='inlinecode'>Swap</span>, which allows swapping the values of two indices in the <span class='inlinecode'>ArrayList</span>:</span><br />
+<br />
+<!-- Generator: GNU source-highlight 3.1.9
+by Lorenzo Bettini
+http://www.lorenzobettini.it
+http://www.gnu.org/software/src-highlite -->
+<pre><b><font color="#0000FF">func</font></b> <font color="#990000">(</font>a ArrayList<font color="#990000">[</font>V<font color="#990000">])</font> <b><font color="#000000">Swap</font></b><font color="#990000">(</font>i<font color="#990000">,</font> j int<font color="#990000">)</font> <font color="#FF0000">{</font>
+ aux <font color="#990000">:=</font> a<font color="#990000">[</font>i<font color="#990000">]</font>
+ a<font color="#990000">[</font>i<font color="#990000">]</font> <font color="#990000">=</font> a<font color="#990000">[</font>j<font color="#990000">]</font>
+ a<font color="#990000">[</font>j<font color="#990000">]</font> <font color="#990000">=</font> aux
+<font color="#FF0000">}</font>
+
+</pre>
+<br />
+<h2 style='display: inline'>Sleep sort</h2><br />
+<br />
+<span>Let's implement our first algorithm, sleep sort. Sleep sort is a non-traditional and unconventional sorting algorithm based on the idea of waiting a certain amount of time corresponding to the value of each element in the input <span class='inlinecode'>ArrayList</span>. It's more of a fun, creative concept rather than an efficient or practical sorting technique. This is not a sorting algorithm you would use in any production code. As you can imagine, it is quite an inefficient sorting algorithm (it's only listed here as a warm-up exercise). This sorting method may also return false results depending on how the Goroutines are scheduled by the Go runtime. </span><br />
+<br />
+<br />
+<!-- Generator: GNU source-highlight 3.1.9
+by Lorenzo Bettini
+http://www.lorenzobettini.it
+http://www.gnu.org/software/src-highlite -->
+<pre><b><font color="#0000FF">package</font></b> sort
+
+<b><font color="#0000FF">import</font></b> <font color="#990000">(</font>
+ <font color="#FF0000">"codeberg.org/snonux/algorithms/ds"</font>
+ <font color="#FF0000">"sync"</font>
+ <font color="#FF0000">"time"</font>
+<font color="#990000">)</font>
+
+<b><font color="#0000FF">func</font></b> Sleep<font color="#990000">[</font>V ds<font color="#990000">.</font>Integer<font color="#990000">](</font>a ds<font color="#990000">.</font>ArrayList<font color="#990000">[</font>V<font color="#990000">])</font> ds<font color="#990000">.</font>ArrayList<font color="#990000">[</font>V<font color="#990000">]</font> <font color="#FF0000">{</font>
+ sorted <font color="#990000">:=</font> ds<font color="#990000">.</font>NewArrayList<font color="#990000">[</font>V<font color="#990000">](</font><b><font color="#000000">len</font></b><font color="#990000">(</font>a<font color="#990000">))</font>
+
+ numCh <font color="#990000">:=</font> <b><font color="#000000">make</font></b><font color="#990000">(</font><b><font color="#0000FF">chan</font></b> V<font color="#990000">)</font>
+ <b><font color="#0000FF">var</font></b> wg sync<font color="#990000">.</font>WaitGroup
+ wg<font color="#990000">.</font><b><font color="#000000">Add</font></b><font color="#990000">(</font><b><font color="#000000">len</font></b><font color="#990000">(</font>a<font color="#990000">))</font>
+
+ <b><font color="#0000FF">go</font></b> <b><font color="#0000FF">func</font></b><font color="#990000">()</font> <font color="#FF0000">{</font>
+ wg<font color="#990000">.</font><b><font color="#000000">Wait</font></b><font color="#990000">()</font>
+ <b><font color="#000000">close</font></b><font color="#990000">(</font>numCh<font color="#990000">)</font>
+ <font color="#FF0000">}</font><font color="#990000">()</font>
+
+ <b><font color="#0000FF">for</font></b> _<font color="#990000">,</font> num <font color="#990000">:=</font> <b><font color="#0000FF">range</font></b> a <font color="#FF0000">{</font>
+ <b><font color="#0000FF">go</font></b> <b><font color="#0000FF">func</font></b><font color="#990000">(</font>num V<font color="#990000">)</font> <font color="#FF0000">{</font>
+ <b><font color="#0000FF">defer</font></b> wg<font color="#990000">.</font><b><font color="#000000">Done</font></b><font color="#990000">()</font>
+ time<font color="#990000">.</font><b><font color="#000000">Sleep</font></b><font color="#990000">(</font>time<font color="#990000">.</font><b><font color="#000000">Duration</font></b><font color="#990000">(</font>num<font color="#990000">)</font> <font color="#990000">*</font> time<font color="#990000">.</font>Second<font color="#990000">)</font>
+ numCh <font color="#990000">&lt;-</font> num
+ <font color="#FF0000">}</font><font color="#990000">(</font>num<font color="#990000">)</font>
+ <font color="#FF0000">}</font>
+
+ <b><font color="#0000FF">for</font></b> num <font color="#990000">:=</font> <b><font color="#0000FF">range</font></b> numCh <font color="#FF0000">{</font>
+ sorted <font color="#990000">=</font> <b><font color="#000000">append</font></b><font color="#990000">(</font>sorted<font color="#990000">,</font> num<font color="#990000">)</font>
+ <font color="#FF0000">}</font>
+
+ <b><font color="#0000FF">return</font></b> sorted
+<font color="#FF0000">}</font>
+</pre>
+<br />
+<h3 style='display: inline'>Testing</h3><br />
+<br />
+<span>For testing, we only allow values up to 10, as otherwise, it would take too long to finish:</span><br />
+<br />
+<!-- Generator: GNU source-highlight 3.1.9
+by Lorenzo Bettini
+http://www.lorenzobettini.it
+http://www.gnu.org/software/src-highlite -->
+<pre><b><font color="#0000FF">package</font></b> sort
+
+<b><font color="#0000FF">import</font></b> <font color="#990000">(</font>
+ <font color="#FF0000">"fmt"</font>
+ <font color="#FF0000">"testing"</font>
+
+ <font color="#FF0000">"codeberg.org/snonux/algorithms/ds"</font>
+<font color="#990000">)</font>
+
+<b><font color="#0000FF">func</font></b> <b><font color="#000000">TestSleepSort</font></b><font color="#990000">(</font>t <font color="#990000">*</font>testing<font color="#990000">.</font>T<font color="#990000">)</font> <font color="#FF0000">{</font>
+ a <font color="#990000">:=</font> ds<font color="#990000">.</font>NewRandomArrayList<font color="#990000">[</font>int<font color="#990000">](</font><font color="#993399">10</font><font color="#990000">,</font> <font color="#993399">10</font><font color="#990000">)</font>
+ a <font color="#990000">=</font> <b><font color="#000000">Sleep</font></b><font color="#990000">(</font>a<font color="#990000">)</font>
+ <b><font color="#0000FF">if</font></b> <font color="#990000">!</font>a<font color="#990000">.</font><b><font color="#000000">Sorted</font></b><font color="#990000">()</font> <font color="#FF0000">{</font>
+ t<font color="#990000">.</font><b><font color="#000000">Errorf</font></b><font color="#990000">(</font><font color="#FF0000">"Array not sorted: %v"</font><font color="#990000">,</font> a<font color="#990000">)</font>
+ <font color="#FF0000">}</font>
+<font color="#FF0000">}</font>
+</pre>
+<br />
+<span>As you can see, it takes <span class='inlinecode'>9s</span> here for the algorithm to finish (which is the highest value in the <span class='inlinecode'>ArrayList</span>):</span><br />
+<br />
+<!-- Generator: GNU source-highlight 3.1.9
+by Lorenzo Bettini
+http://www.lorenzobettini.it
+http://www.gnu.org/software/src-highlite -->
+<pre>❯ go <b><font color="#0000FF">test</font></b> <font color="#990000">.</font>/sort -v -run SleepSort
+<font color="#990000">===</font> RUN TestSleepSort
+--- PASS<font color="#990000">:</font> TestSleepSort <font color="#990000">(</font><font color="#993399">9</font><font color="#990000">.</font>00s<font color="#990000">)</font>
+PASS
+ok codeberg<font color="#990000">.</font>org/snonux/algorithms/sort <font color="#993399">9</font><font color="#990000">.</font>002s
+</pre>
+<br />
+<span>I won't write any benchmark for sleep sort; that will be done for the algorithms to come in this series :-).</span><br />
+<br />
+<span>E-Mail your comments to hi@paul.cyou :-)</span><br />
+<br />
+<a class='textlink' href='../'>Back to the main site</a><br />
+ </div>
+ </content>
+ </entry>
+ <entry>
<title>'Never split the difference' book notes</title>
<link href="gemini://foo.zone/gemfeed/2023-04-01-never-split-the-difference-book-notes.gmi" />
<id>gemini://foo.zone/gemfeed/2023-04-01-never-split-the-difference-book-notes.gmi</id>
@@ -7847,200 +8116,4 @@ _jgs_\|//_\\|///_\V/_\|//__
</div>
</content>
</entry>
- <entry>
- <title>Perl Poetry</title>
- <link href="gemini://foo.zone/gemfeed/2008-06-26-perl-poetry.gmi" />
- <id>gemini://foo.zone/gemfeed/2008-06-26-perl-poetry.gmi</id>
- <updated>2008-06-26T21:43:51+01:00</updated>
- <author>
- <name>Paul Buetow</name>
- <email>hi@paul.cyou</email>
- </author>
- <summary>Here are some Perl Poems I wrote. They don't do anything useful when you run them, but they don't produce a compiler error either. They only exist for fun and demonstrate what you can do with Perl syntax.</summary>
- <content type="xhtml">
- <div xmlns="http://www.w3.org/1999/xhtml">
- <h1 style='display: inline'>Perl Poetry</h1><br />
-<br />
-<span class='quote'>Published at 2008-06-26T21:43:51+01:00; Updated at 2021-05-04</span><br />
-<br />
-<pre>
- '\|/' *
--- * -----
- /|\ ____
- ' | ' {_ o^&gt; *
- : -_ /)
- : ( ( .-''`'.
- . \ \ / \
- . \ \ / \
- \ `-' `'.
- \ . ' / `.
- \ ( \ ) ( .')
- ,, t '. | / | (
- '|``_/^\___ '| |`'-..-'| ( ()
-_~~|~/_|_|__/|~~~~~~~ | / ~~~~~ | | ~~~~~~~~
- -_ |L[|]L|/ | |\ MJP ) )
- ( |( / /|
- ~~ ~ ~ ~~~~ | /\\ / /| |
- || \\ _/ / | |
- ~ ~ ~~~ _|| (_/ (___)_| |Nov291999
- (__) (____)
-</pre>
-<br />
-<span>Here are some Perl Poems I wrote. They don't do anything useful when you run them, but they don't produce a compiler error either. They only exist for fun and demonstrate what you can do with Perl syntax.</span><br />
-<br />
-<span>Wikipedia: "Perl poetry is the practice of writing poems that can be compiled as legal Perl code, for example the piece known as Black Perl. Perl poetry is made possible by the large number of English words that are used in the Perl language. New poems are regularly submitted to the community at PerlMonks."</span><br />
-<br />
-<a class='textlink' href='https://en.wikipedia.org/wiki/Perl'>https://en.wikipedia.org/wiki/Perl</a><br />
-<br />
-<h2 style='display: inline'>math.pl</h2><br />
-<br />
-<!-- Generator: GNU source-highlight 3.1.9
-by Lorenzo Bettini
-http://www.lorenzobettini.it
-http://www.gnu.org/software/src-highlite -->
-<pre><i><font color="#9A1900">#!/usr/bin/perl</font></i>
-
-<i><font color="#9A1900"># (C) 2006 by Paul C. Buetow</font></i>
-
-<b><font color="#0000FF">goto</font></b> library <b><font color="#0000FF">for</font></b> study <font color="#009900">$math</font><font color="#990000">;</font>
-BEGIN <font color="#FF0000">{</font> <b><font color="#0000FF">s</font></b><font color="#FF0000">/earching/ books/</font>
-<b><font color="#0000FF">and</font></b> <b><font color="#0000FF">read</font></b> <font color="#009900">$them</font><font color="#990000">,</font> <font color="#009900">$at</font><font color="#990000">,</font> <font color="#009900">$the</font> <font color="#FF0000">}</font> library<font color="#990000">:</font>
-
-<b><font color="#0000FF">our</font></b> <font color="#009900">$topics</font><font color="#990000">,</font> <b><font color="#0000FF">cos</font></b> <b><font color="#0000FF">and</font></b> tan<font color="#990000">,</font>
-<b><font color="#0000FF">require</font></b> strict<font color="#990000">;</font> <b><font color="#000080">import</font></b> <font color="#FF0000">{</font> of<font color="#990000">,</font> <b><font color="#0000FF">tied</font></b> <font color="#009900">$patience</font> <font color="#FF0000">}</font><font color="#990000">;</font>
-
-<b><font color="#0000FF">do</font></b> <font color="#FF0000">{</font> <b><font color="#0000FF">int</font></b><font color="#FF0000">'egrate'</font><font color="#990000">;</font> <b><font color="#0000FF">sub</font></b> trade<font color="#990000">;</font> <font color="#FF0000">}</font><font color="#990000">;</font>
-<b><font color="#0000FF">do</font></b> <font color="#FF0000">{</font> <b><font color="#0000FF">exp</font></b><font color="#FF0000">'onentize'</font> <b><font color="#0000FF">and</font></b> <b><font color="#0000FF">abs</font></b><font color="#FF0000">'olutize'</font> <font color="#FF0000">}</font><font color="#990000">;</font>
-study <b><font color="#0000FF">and</font></b> study <b><font color="#0000FF">and</font></b> study <b><font color="#0000FF">and</font></b> study<font color="#990000">;</font>
-
-<b><font color="#0000FF">foreach</font></b> <font color="#009900">$topic</font> <font color="#990000">(</font><font color="#FF0000">{</font>of<font color="#990000">,</font> math<font color="#FF0000">}</font><font color="#990000">)</font> <font color="#FF0000">{</font>
-you<font color="#990000">,</font> <b><font color="#0000FF">m</font></b><font color="#FF6600">/ay /</font>go<font color="#990000">,</font> to<font color="#990000">,</font> limits <font color="#FF0000">}</font>
-
-<b><font color="#0000FF">do</font></b> <font color="#FF0000">{</font> not <b><font color="#0000FF">qw</font></b><font color="#FF0000">/erk /</font> <b><font color="#0000FF">unless</font></b> <font color="#009900">$success</font>
-<b><font color="#0000FF">and</font></b> <b><font color="#0000FF">m</font></b><font color="#FF6600">/ove /</font>o<font color="#990000">;</font><font color="#009900">$n</font> <b><font color="#0000FF">and</font></b> study <font color="#FF0000">}</font><font color="#990000">;</font>
-
-<b><font color="#0000FF">do</font></b> <font color="#FF0000">{</font> <b><font color="#0000FF">int</font></b><font color="#FF0000">'egrate'</font><font color="#990000">;</font> <b><font color="#0000FF">sub</font></b> trade<font color="#990000">;</font> <font color="#FF0000">}</font><font color="#990000">;</font>
-<b><font color="#0000FF">do</font></b> <font color="#FF0000">{</font> <b><font color="#0000FF">exp</font></b><font color="#FF0000">'onentize'</font> <b><font color="#0000FF">and</font></b> <b><font color="#0000FF">abs</font></b><font color="#FF0000">'olutize'</font> <font color="#FF0000">}</font><font color="#990000">;</font>
-study <b><font color="#0000FF">and</font></b> study <b><font color="#0000FF">and</font></b> study <b><font color="#0000FF">and</font></b> study<font color="#990000">;</font>
-
-<b><font color="#0000FF">grep</font></b> <font color="#FF0000">/all/</font><font color="#990000">,</font> <b><font color="#0000FF">exp</font></b><font color="#FF0000">'onents'</font> <b><font color="#0000FF">and</font></b> <b><font color="#0000FF">cos</font></b><font color="#FF0000">'inuses'</font><font color="#990000">;</font>
-<font color="#FF0000">/seek results/</font> <b><font color="#0000FF">for</font></b> <font color="#009900">@all</font><font color="#990000">,</font> <b><font color="#0000FF">log</font></b><font color="#FF0000">'4rithms'</font><font color="#990000">;</font>
-
-<font color="#FF0000">'you'</font> <font color="#990000">=~</font> <b><font color="#0000FF">m</font></b><font color="#FF6600">/ay /</font>go<font color="#990000">,</font> not home
-<b><font color="#0000FF">unless</font></b> <b><font color="#0000FF">each</font></b> <font color="#009900">%book</font> ne<i><font color="#9A1900">#ars</font></i>
-<font color="#009900">$completion</font><font color="#990000">;</font>
-
-<b><font color="#0000FF">do</font></b> <font color="#FF0000">{</font> <b><font color="#0000FF">int</font></b><font color="#FF0000">'egrate'</font><font color="#990000">;</font> <b><font color="#0000FF">sub</font></b> trade<font color="#990000">;</font> <font color="#FF0000">}</font><font color="#990000">;</font>
-<b><font color="#0000FF">do</font></b> <font color="#FF0000">{</font> <b><font color="#0000FF">exp</font></b><font color="#FF0000">'onentize'</font> <b><font color="#0000FF">and</font></b> <b><font color="#0000FF">abs</font></b><font color="#FF0000">'olutize'</font> <font color="#FF0000">}</font><font color="#990000">;</font>
-
-<i><font color="#9A1900">#at</font></i>
-home<font color="#990000">:</font> <font color="#FF0000">//ig,'nore', time and sleep $very =~ s/tr/on/</font><b><font color="#0000FF">g</font></b><font color="#990000">;</font>
-__END__
-
-</pre>
-<br />
-<h2 style='display: inline'>christmas.pl</h2><br />
-<br />
-<!-- Generator: GNU source-highlight 3.1.9
-by Lorenzo Bettini
-http://www.lorenzobettini.it
-http://www.gnu.org/software/src-highlite -->
-<pre><i><font color="#9A1900">#!/usr/bin/perl</font></i>
-
-<i><font color="#9A1900"># (C) 2006 by Paul C. Buetow</font></i>
-
-Christmas<font color="#990000">:</font><font color="#FF0000">{</font>time<font color="#990000">;</font><i><font color="#9A1900">#!!!</font></i>
-
-Children<font color="#990000">:</font> <b><font color="#0000FF">do</font></b> <b><font color="#0000FF">tell</font></b> <font color="#009900">$wishes</font><font color="#990000">;</font>
-
-Santa<font color="#990000">:</font> <b><font color="#0000FF">for</font></b> <font color="#009900">$each</font> <font color="#990000">(</font><font color="#009900">@children</font><font color="#990000">)</font> <font color="#FF0000">{</font>
-BEGIN <font color="#FF0000">{</font> <b><font color="#0000FF">read</font></b> <font color="#009900">$each</font><font color="#990000">,</font> <font color="#009900">$their</font><font color="#990000">,</font> wishes <b><font color="#0000FF">and</font></b> study them<font color="#990000">;</font> <b><font color="#0000FF">use</font></b> Memoize<i><font color="#9A1900">#ing</font></i>
-
-<font color="#FF0000">}</font> <b><font color="#0000FF">use</font></b> constant gift<font color="#990000">,</font> <font color="#FF0000">'wrapping'</font><font color="#990000">;</font>
-<b><font color="#0000FF">package</font></b> Gifts<font color="#990000">;</font> <b><font color="#0000FF">pack</font></b> <font color="#009900">$each</font><font color="#990000">,</font> gift <b><font color="#0000FF">and</font></b> <b><font color="#0000FF">bless</font></b> <font color="#009900">$each</font> <b><font color="#0000FF">and</font></b> <b><font color="#0000FF">goto</font></b> deliver
-or <b><font color="#0000FF">do</font></b> <b><font color="#000080">import</font></b> <b><font color="#0000FF">if</font></b> not <b><font color="#0000FF">local</font></b> <font color="#009900">$available</font><font color="#990000">,!!!</font> HO<font color="#990000">,</font> HO<font color="#990000">,</font> HO<font color="#990000">;</font>
-
-<b><font color="#0000FF">redo</font></b> Santa<font color="#990000">,</font> <b><font color="#0000FF">pipe</font></b> <font color="#009900">$gifts</font><font color="#990000">,</font> to_childs<font color="#990000">;</font>
-<b><font color="#0000FF">redo</font></b> Santa <b><font color="#0000FF">and</font></b> <b><font color="#0000FF">do</font></b> <b><font color="#0000FF">return</font></b> <b><font color="#0000FF">if</font></b> <b><font color="#0000FF">last</font></b> one<font color="#990000">,</font> is<font color="#990000">,</font> delivered<font color="#990000">;</font>
-
-deliver<font color="#990000">:</font> gift <b><font color="#0000FF">and</font></b> <b><font color="#0000FF">require</font></b> diagnostics <b><font color="#0000FF">if</font></b> <b><font color="#0000FF">our</font></b> <font color="#009900">$gifts</font> <font color="#990000">,</font>not break<font color="#990000">;</font>
-<b><font color="#0000FF">do</font></b><font color="#FF0000">{</font> <b><font color="#0000FF">use</font></b> NEXT<font color="#990000">;</font> time<font color="#990000">;</font> <b><font color="#0000FF">tied</font></b> <font color="#009900">$gifts</font><font color="#FF0000">}</font> <b><font color="#0000FF">if</font></b> broken <b><font color="#0000FF">and</font></b> <b><font color="#0000FF">dump</font></b> the<font color="#990000">,</font> broken<font color="#990000">,</font> ones<font color="#990000">;</font>
-The_children<font color="#990000">:</font> <b><font color="#0000FF">sleep</font></b> <b><font color="#0000FF">and</font></b> <b><font color="#0000FF">wait</font></b> <b><font color="#0000FF">for</font></b> <font color="#990000">(</font><b><font color="#0000FF">each</font></b> <font color="#009900">%gift</font><font color="#990000">)</font> <b><font color="#0000FF">and</font></b> try <font color="#FF0000">{</font> to <font color="#990000">=&gt;</font> <b><font color="#0000FF">untie</font></b> <font color="#009900">$gifts</font> <font color="#FF0000">}</font><font color="#990000">;</font>
-
-<b><font color="#0000FF">redo</font></b> Santa<font color="#990000">,</font> <b><font color="#0000FF">pipe</font></b> <font color="#009900">$gifts</font><font color="#990000">,</font> to_childs<font color="#990000">;</font>
-<b><font color="#0000FF">redo</font></b> Santa <b><font color="#0000FF">and</font></b> <b><font color="#0000FF">do</font></b> <b><font color="#0000FF">return</font></b> <b><font color="#0000FF">if</font></b> <b><font color="#0000FF">last</font></b> one<font color="#990000">,</font> is<font color="#990000">,</font> delivered<font color="#990000">;</font>
-
-The_christmas_tree<font color="#990000">:</font> formline <b><font color="#0000FF">s</font></b><font color="#FF0000">/ /childrens/</font><font color="#990000">,</font> <font color="#009900">$gifts</font><font color="#990000">;</font>
-<b><font color="#0000FF">alarm</font></b> <b><font color="#0000FF">and</font></b> <b><font color="#0000FF">warn</font></b> <b><font color="#0000FF">if</font></b> not <b><font color="#0000FF">exists</font></b> <font color="#009900">$Christmas</font><font color="#FF0000">{</font> tree<font color="#FF0000">}</font><font color="#990000">,</font> <font color="#009900">@t</font><font color="#990000">,</font> <font color="#009900">$ENV</font><font color="#FF0000">{</font>HOME<font color="#FF0000">}</font><font color="#990000">;</font>
-<b><font color="#0000FF">write</font></b> <font color="#990000">&lt;&lt;</font>EMail
- to the parents to buy a new christmas tree<font color="#990000">!!!!</font><font color="#993399">111</font>
- <b><font color="#0000FF">and</font></b> send the
-EMail
-<font color="#990000">;</font><b><font color="#0000FF">wait</font></b> <b><font color="#0000FF">and</font></b> <b><font color="#0000FF">redo</font></b> deliver until <b><font color="#0000FF">defined</font></b> <b><font color="#0000FF">local</font></b> <font color="#009900">$tree</font><font color="#990000">;</font>
-
-<b><font color="#0000FF">redo</font></b> Santa<font color="#990000">,</font> <b><font color="#0000FF">pipe</font></b> <font color="#009900">$gifts</font><font color="#990000">,</font> to_childs<font color="#990000">;</font>
-<b><font color="#0000FF">redo</font></b> Santa <b><font color="#0000FF">and</font></b> <b><font color="#0000FF">do</font></b> <b><font color="#0000FF">return</font></b> <b><font color="#0000FF">if</font></b> <b><font color="#0000FF">last</font></b> one<font color="#990000">,</font> is<font color="#990000">,</font> delivered <font color="#990000">;</font><font color="#FF0000">}</font>
-
-END <font color="#FF0000">{}</font> <b><font color="#0000FF">our</font></b> <font color="#009900">$mission</font> <b><font color="#0000FF">and</font></b> <b><font color="#0000FF">do</font></b> <b><font color="#0000FF">sleep</font></b> until <b><font color="#0000FF">next</font></b> Christmas <font color="#990000">;</font><font color="#FF0000">}</font>
-
-__END__
-
-This is perl<font color="#990000">,</font> v5<font color="#990000">.</font><font color="#993399">8.8</font> built <b><font color="#0000FF">for</font></b> i386<font color="#990000">-</font>freebsd<font color="#990000">-</font>64int
-</pre>
-<br />
-<h2 style='display: inline'>shopping.pl</h2><br />
-<br />
-<!-- Generator: GNU source-highlight 3.1.9
-by Lorenzo Bettini
-http://www.lorenzobettini.it
-http://www.gnu.org/software/src-highlite -->
-<pre><i><font color="#9A1900">#!/usr/bin/perl</font></i>
-
-<i><font color="#9A1900"># (C) 2007 by Paul C. Buetow</font></i>
-
-BEGIN<font color="#FF0000">{}</font> <b><font color="#0000FF">goto</font></b> mall <b><font color="#0000FF">for</font></b> <font color="#009900">$shopping</font><font color="#990000">;</font>
-
-<b><font color="#0000FF">m</font></b><font color="#FF6600">/y/</font><font color="#990000">;</font> mall<font color="#990000">:</font> <b><font color="#0000FF">seek</font></b><font color="#009900">$s</font><font color="#990000">,</font> cool <b><font color="#000000">products</font></b><font color="#990000">(),</font> <font color="#FF0000">{</font> to <font color="#990000">=&gt;</font> <font color="#009900">$sell</font> <font color="#FF0000">}</font><font color="#990000">;</font>
-<b><font color="#0000FF">for</font></b> <font color="#009900">$their</font> <font color="#990000">(</font><font color="#009900">@business</font><font color="#990000">)</font> <font color="#FF0000">{</font> to<font color="#990000">:;</font> earn<font color="#990000">:;</font> a<font color="#990000">:;</font> lot<font color="#990000">:;</font> of<font color="#990000">:;</font> money<font color="#990000">:</font> <font color="#FF0000">}</font>
-
-<b><font color="#0000FF">do</font></b> not <b><font color="#0000FF">goto</font></b> home <b><font color="#0000FF">and</font></b> <b><font color="#0000FF">exit</font></b> mall <b><font color="#0000FF">if</font></b> <b><font color="#0000FF">exists</font></b> <font color="#009900">$new</font><font color="#FF0000">{</font>product<font color="#FF0000">}</font><font color="#990000">;</font>
-<b><font color="#0000FF">foreach</font></b> <font color="#009900">$of</font> <font color="#990000">(</font><b><font color="#0000FF">q</font></b><font color="#FF0000">(uality rich products)</font><font color="#990000">)</font><font color="#FF0000">{}</font> <b><font color="#0000FF">package</font></b> products<font color="#990000">;</font>
-
-<b><font color="#0000FF">our</font></b> <font color="#009900">$news</font><font color="#990000">;</font> <b><font color="#0000FF">do</font></b> <b><font color="#0000FF">tell</font></b> cool <b><font color="#000000">products</font></b><font color="#990000">()</font> <b><font color="#0000FF">and</font></b> <b><font color="#0000FF">do</font></b><font color="#FF0000">{</font> <b><font color="#0000FF">sub</font></b><i><font color="#9A1900">#tract</font></i>
-cool<font color="#FF0000">{</font> <font color="#009900">$products</font> <b><font color="#0000FF">and</font></b> <b><font color="#0000FF">shift</font></b> <font color="#009900">@the</font><font color="#990000">,</font> <font color="#009900">@bad</font><font color="#990000">,</font> <font color="#009900">@ones</font><font color="#990000">;</font>
-
-<b><font color="#0000FF">do</font></b> <b><font color="#0000FF">bless</font></b> <font color="#990000">[</font><b><font color="#0000FF">q</font></b><font color="#FF0000">(uality)</font><font color="#990000">],</font> <font color="#009900">$products</font>
-<b><font color="#0000FF">and</font></b> <b><font color="#0000FF">return</font></b> not <b><font color="#0000FF">undef</font></b> <font color="#009900">$stuff</font> <b><font color="#0000FF">if</font></b> <b><font color="#000000">not</font></b> <font color="#990000">(</font><b><font color="#0000FF">local</font></b> <font color="#009900">$available</font><font color="#990000">)</font> <font color="#FF0000">}}</font><font color="#990000">;</font>
-
-<b><font color="#0000FF">do</font></b> <font color="#FF0000">{</font> study <b><font color="#0000FF">and</font></b> study <b><font color="#0000FF">and</font></b> study <b><font color="#0000FF">for</font></b> cool <b><font color="#000000">products</font></b><font color="#990000">()</font> <font color="#FF0000">}</font>
-<b><font color="#0000FF">and</font></b> <b><font color="#0000FF">do</font></b> <font color="#FF0000">{</font> <b><font color="#0000FF">seek</font></b> <font color="#009900">$all</font><font color="#990000">,</font> cool <b><font color="#000000">products</font></b><font color="#990000">(),</font> <font color="#FF0000">{</font> to <font color="#990000">=&gt;</font> <font color="#009900">$buy</font> <font color="#FF0000">}</font> <font color="#FF0000">}</font><font color="#990000">;</font>
-
-<b><font color="#0000FF">do</font></b> <font color="#FF0000">{</font> <b><font color="#0000FF">write</font></b> <font color="#009900">$them</font><font color="#990000">,</font> <font color="#009900">$down</font> <font color="#FF0000">}</font> <b><font color="#0000FF">and</font></b> <b><font color="#0000FF">do</font></b> <font color="#FF0000">{</font> order<font color="#990000">:</font> <b><font color="#0000FF">foreach</font></b> <font color="#990000">(</font><font color="#009900">@case</font><font color="#990000">)</font> <font color="#FF0000">{</font> <b><font color="#0000FF">package</font></b> <b><font color="#0000FF">s</font></b> <font color="#FF0000">}</font> <font color="#FF0000">}</font><font color="#990000">;</font>
-<b><font color="#0000FF">goto</font></b> home <b><font color="#0000FF">if</font></b> not <b><font color="#0000FF">exists</font></b> <font color="#009900">$more</font><font color="#FF0000">{</font>money<font color="#FF0000">}</font> or <b><font color="#0000FF">die</font></b> <b><font color="#0000FF">q</font></b><font color="#FF0000">(uerying)</font> <font color="#990000">;</font><b><font color="#0000FF">for</font></b><font color="#990000">(</font> <font color="#009900">@money</font><font color="#990000">)</font><font color="#FF0000">{}</font><font color="#990000">;</font>
-
-at<font color="#990000">:;</font>home<font color="#990000">:</font> <b><font color="#0000FF">do</font></b> <font color="#FF0000">{</font> END<font color="#FF0000">{}</font> <b><font color="#0000FF">and</font></b><font color="#990000">:;</font> rest<font color="#990000">:;</font> a<font color="#990000">:;</font> bit<font color="#990000">:</font> <b><font color="#0000FF">exit</font></b> <font color="#009900">$shopping</font> <font color="#FF0000">}</font>
-<b><font color="#0000FF">and</font></b> <b><font color="#0000FF">sleep</font></b> until <b><font color="#0000FF">unpack</font></b><font color="#009900">$ing</font><font color="#990000">,</font> cool <b><font color="#000000">products</font></b><font color="#990000">();</font>
-
-__END__
-This is perl<font color="#990000">,</font> v5<font color="#990000">.</font><font color="#993399">8.8</font> built <b><font color="#0000FF">for</font></b> i386<font color="#990000">-</font>freebsd<font color="#990000">-</font>64int
-</pre>
-<br />
-<h2 style='display: inline'>More...</h2><br />
-<br />
-<span>Did you like what you saw? Have a look at Codeberg to see my other poems too:</span><br />
-<br />
-<a class='textlink' href='https://codeberg.org/snonux/perl-poetry'>https://codeberg.org/snonux/perl-poetry</a><br />
-<br />
-<span>Other related posts are:</span><br />
-<br />
-<a class='textlink' href='./2022-05-27-perl-is-still-a-great-choice.html'>2022-05-27 Perl is still a great choice</a><br />
-<a class='textlink' href='./2011-05-07-perl-daemon-service-framework.html'>2011-05-07 Perl Daemon (Service Framework)</a><br />
-<a class='textlink' href='./2008-06-26-perl-poetry.html'>2008-06-26 Perl Poetry (You are currently reading this)</a><br />
-<br />
-<span>E-Mail your comments to hi@paul.cyou :-)</span><br />
-<br />
-<a class='textlink' href='../'>Back to the main site</a><br />
- </div>
- </content>
- </entry>
</feed>
diff --git a/gemfeed/index.gmi b/gemfeed/index.gmi
index 6e171263..c52c8519 100644
--- a/gemfeed/index.gmi
+++ b/gemfeed/index.gmi
@@ -2,6 +2,7 @@
## To be in the .zone!
+=> ./2023-04-09-algorithms-in-golang-part-1.gmi 2023-04-09 - Algorithms in Go - Part 1
=> ./2023-04-01-never-split-the-difference-book-notes.gmi 2023-04-01 - 'Never split the difference' book notes
=> ./2023-03-25-gemtexter-2.0.0-lets-gemtext-again-2.gmi 2023-03-25 - Gemtexter 2.0.0 - Let's Gemtext again^2
=> ./2023-03-16-the-pragmatic-programmer-book-notes.gmi 2023-03-16 - 'The Pragmatic Programmer' book notes
diff --git a/index.gmi b/index.gmi
index a119d244..b35e5f09 100644
--- a/index.gmi
+++ b/index.gmi
@@ -1,6 +1,6 @@
# foo.zone
-> This site was generated at 2023-04-09T15:24:16+03:00 by `Gemtexter`
+> This site was generated at 2023-04-09T21:48:36+03:00 by `Gemtexter`
```
|\---/|
@@ -32,6 +32,7 @@ If you reach this site via the modern web, please read this:
### Posts
+=> ./gemfeed/2023-04-09-algorithms-in-golang-part-1.gmi 2023-04-09 - Algorithms in Go - Part 1
=> ./gemfeed/2023-04-01-never-split-the-difference-book-notes.gmi 2023-04-01 - 'Never split the difference' book notes
=> ./gemfeed/2023-03-25-gemtexter-2.0.0-lets-gemtext-again-2.gmi 2023-03-25 - Gemtexter 2.0.0 - Let's Gemtext again^2
=> ./gemfeed/2023-03-16-the-pragmatic-programmer-book-notes.gmi 2023-03-16 - 'The Pragmatic Programmer' book notes
diff --git a/uptime-stats.gmi b/uptime-stats.gmi
index e5f85219..000eb5a9 100644
--- a/uptime-stats.gmi
+++ b/uptime-stats.gmi
@@ -1,6 +1,6 @@
# My machine uptime stats
-> This site was last updated at 2023-04-09T15:24:16+03:00
+> This site was last updated at 2023-04-09T21:48:36+03:00
The following stats were collected via `uptimed` on all of my personal computers over many years and the output was generated by `guprecords`, the global uptime records stats analyser of mine.