Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Master #113

Open
wants to merge 25 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
2 changes: 1 addition & 1 deletion _content/tour/eng/static/js/page.js
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ function setLanguageOptionBasedOnUrl() {
// replaceLanguageInUrl takes a URL and a new language as arguments,
// and returns a new URL with the language segment replaced by the new language.
function replaceLanguageInUrl(url, newLanguage) {
return url.replace(/(\/tour\/)(eng|rus)(\/)/, `$1${newLanguage}$3`);
return url.replace(/(\/tour\/)(eng|rus|gre)(\/)/, `$1${newLanguage}$3`);
}

window.onload = function() {
Expand Down
1 change: 1 addition & 0 deletions _content/tour/eng/template/index.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@
<div class="language-switcher">
<select id="languageSelector" aria-label="Language selector">
<option value="eng">English</option>
<option value="gre">Greek</option>
</select>
</div>
</div>
Expand Down
12 changes: 12 additions & 0 deletions _content/tour/grc/algorithms-bits-seven.article
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
Bit Operations
This section provides examples that perform bit operations.

* Is Even Or Odd

- [[https://www.ardanlabs.com/training/individual-on-demand/ultimate-go-bundle/][Watch The Video]]
- Need Financial Assistance, Use Our [[https://www.ardanlabs.com/scholarship/][Scholarship Form]]

This sample program shows you how to check if an integer is even or odd
using bit manipulation.

.play algorithms/bits/iseven.go
146 changes: 146 additions & 0 deletions _content/tour/grc/algorithms-data.article
Original file line number Diff line number Diff line change
@@ -0,0 +1,146 @@
Data Structures
This section provides data struct examples.

* Hash Map

- [[https://www.ardanlabs.com/training/individual-on-demand/ultimate-go-bundle/][Watch The Video]]
- Need Financial Assistance, Use Our [[https://www.ardanlabs.com/scholarship/][Scholarship Form]]

This sample program implements a basic hash table.

- hashKey(key) returns a number between 0 to len(buckets)-1

- We use a slice of entries as a bucket to handles cases where two or more keys
are hashed to the same bucket

- See more at [[https://en.wikipedia.org/wiki/Hash_table][https://en.wikipedia.org/wiki/Hash_table]]

*Diagram*

With a hash map, data is indexed by bucket and then position
inside the bucket.

hashKey(key) ──────────────┐
┌────┬─────┬─────┬─────┬─────┬─────┬─────┬─────┐
│ │ │ │ │ │ │ │ │ ◁── bucket
└────┴─────┴─────┴─────┴─────┴─────┴─────┴─────┘
│ │
▽ ▽
┌─────────────┐ ┌─────────────┐
│ key │ value │ │ key │ value │ ◁── entry
├─────────────┤ ├─────────────┤
│ key │ value │ │ key │ value │
├─────────────┤ └─────────────┘
│ key │ value │
├─────────────┤
│ key │ value │
├─────────────┤
│ key │ value │
└─────────────┘

.play algorithms/data/hash_map.go

* Linked List

This sample program implements a basic double linked list.

- See more at [[https://en.wikipedia.org/wiki/Linked_list][https://en.wikipedia.org/wiki/Linked_list]]

*Diagram*

With a linked list, values are tied together in different
order through the use of pointers.

┌─────┐ ┌─────┐ ┌─────┐ ┌─────┐ ┌─────┐
│ Val │ ◁─▷ │ Val │ ◁─▷ │ Val │ ◁─▷ │ Val │ ◁─▷ │ Val │
└─────┘ └─────┘ └─────┘ └─────┘ └─────┘
△ △
│ │
──────────────────── ─────────────────────
│ │
│ │
┌───────────────┐
│ First │ Last │
└───────────────┘

.play algorithms/data/list.go

* Queue

This sample program implements a basic circular queue.

- See more at [[https://en.wikipedia.org/wiki/Queue_(abstract_data_type)][https://en.wikipedia.org/wiki/Queue_(abstract_data_type)]]

*Diagram*

With a queue, the first value in is the first value out.

┌──────────────────────────────────────────┐
┌─────┐ │ ┌─────┐ ┌─────┐ ┌─────┐ ┌─────┐ │ ┌─────┐
│ V06 │ ─▷ │ │ V05 │ ─▷ │ V04 │ ─▷ │ V03 │ ─▷ │ V02 │ │ ─▷ │ V01 │
└─────┘ | └─────┘ └─────┘ └─────┘ └─────┘ | └─────┘
└──────────────────────────────────────────┘

.play algorithms/data/queue_circular.go

* Stack

This sample program implements a basic stack.

- See more at [[https://en.wikipedia.org/wiki/Stack_(abstract_data_type)][https://en.wikipedia.org/wiki/Stack_(abstract_data_type)]]

*Diagram*

With a stack, the first value in is the last value out.

┌─────┐
│ V05 │
└─────┘
▽ ┌─────┐
┌───────────┐ ─▷ │ V04 │
│ ┌─────┐ │ └─────┘
│ │ V03 │ │
│ └─────┘ │
│ ┌─────┐ │
│ │ V02 │ │
│ └─────┘ │
│ ┌─────┐ │
│ │ V01 │ │
│ └─────┘ │
└───────────┘

.play algorithms/data/stack.go

* Binary Tree

This sample program implements a basic binary tree.

- See more at [[https://en.wikipedia.org/wiki/Binary_tree][https://en.wikipedia.org/wiki/Binary_tree]]

*Diagram*

With a binary tree, data is indexed either to the left or right
side of the tree. With the adding of each node, the tree is
balanced.

0 1 2 3 4 5 6 ◁─ Insert Order
┌────┐┌────┐┌────┐┌────┐┌────┐┌────┐┌────┐
│ 65 ││ 45 ││ 35 ││ 75 ││ 85 ││ 78 ││ 95 │
└────┘└────┘└────┘└────┘└────┘└────┘└────┘

┌────┐
│ 75 │ ◁─ Final Tree
└────┘
/ \
┌────┐ ┌────┐
│ 45 │ │ 85 │
└────┘ └────┘
/ \ / \
┌────┐ ┌────┐ ┌────┐ ┌────┐
│ 35 │ │ 65 │ │ 78 │ │ 95 │
└────┘ └────┘ └────┘ └────┘

.play algorithms/data/tree_binary.go
131 changes: 131 additions & 0 deletions _content/tour/grc/algorithms-fun.article
Original file line number Diff line number Diff line change
@@ -0,0 +1,131 @@
Fun Problems
This section contains a set fun code challenges that showcase some of the capabilities offered by Go.

* Sleeping Barber Problem

- [[https://www.ardanlabs.com/training/individual-on-demand/ultimate-go-bundle/][Watch The Video]]
- Need Financial Assistance, Use Our [[https://www.ardanlabs.com/scholarship/][Scholarship Form]]

This sample program implements the sleeping barber problem.

- See more at [[https://en.wikipedia.org/wiki/Sleeping_barber_problem][https://en.wikipedia.org/wiki/Sleeping_barber_problem]]

There is one barber in the barber shop, one barber chair and `n` chairs for
waiting customers. If there are no customers, the barber sits down in the
barber chair and takes a nap. An arriving customer must wake the barber.
Subsequent arriving customers take a waiting chair if any are empty or
leave if all chairs are full.

*Output:*

Opening the shop
Barber ready to work
Customer "cust-1" entered shop
Customer "cust-1" takes a seat and waits
Barber servicing customer "cust-1"
Barber finished customer "cust-1"
Barber taking a nap
Customer "cust-2" entered shop
Customer "cust-2" takes a seat and waits
Barber servicing customer "cust-2"
Customer "cust-3" entered shop
Customer "cust-3" takes a seat and waits
Barber finished customer "cust-2"
Barber servicing customer "cust-3"
Customer "cust-4" entered shop
Customer "cust-4" takes a seat and waits
Closing the shop
Barber finished customer "cust-3"
Barber servicing customer "cust-4"
Barber finished customer "cust-4"
Shop closed

.play algorithms/fun/barber.go

* Frequency

This sample programs shows you how to implement a function that can find
the frequency of a given rune that is used in a specified sentence.

- Sequential: A linear algorithm to perform a rune count.
- Concurrent: A concurrent algorithm to perform a rune count.

.play algorithms/fun/freq_sequential.go
.play algorithms/fun/freq_concurrent.go

* Variable Length Quantity encoding/decoding.

This sample program showcases how Go can be leveraged to implement variable length quantity encoding/decoding.

- See more at [[https://en.wikipedia.org/wiki/Variable-length_code][https://en.wikipedia.org/wiki/Variable-length_code]]

In short, the goal of this encoding is to save encode integer values in
a way that would save bytes. Only the first 7 bits of each byte is significant
(right-justified; sort of like an ASCII byte). So, if you have a 32-bit value,
you have to unpack it into a series of 7-bit bytes. Of course, you will have
a variable number of bytes depending upon your integer. To indicate which
is the last byte of the series, you leave bit #7 clear. In all of the
preceding bytes, you set bit #7.

So, if an integer is between 0-127, it can be represented as one byte. The
largest integer allowed is 0FFFFFFF, which translates to 4 bytes variable
length. Here are examples of delta-times as 32-bit values, and the variable
length quantities that they translate to:

NUMBER VARIABLE QUANTITY
00000000 00
00000040 40
0000007F 7F
00000080 81 00
00002000 C0 00
00003FFF FF 7F
00004000 81 80 00
00100000 C0 80 00
001FFFFF FF FF 7F
00200000 81 80 80 00
08000000 C0 80 80 00
0FFFFFFF FF FF FF 7F

A variable-length quantity (VLQ) is a universal code that uses an arbitrary
number of binary octets (eight-bit bytes) to represent an arbitrarily large
integer. It was defined for use in the standard MIDI file format[1] to save
additional space for a resource constrained system, and is also used in the
later Extensible Music Format (XMF). A VLQ is essentially a base-128
representation of an unsigned integer with the addition of the eighth bit
to mark continuation of bytes. See the example below.

Int: 16384
IntHex: 0x00004000
IntBin: 00000000 00000000 01000000 00000000
VLQHex: 0x81 0x80 0x00
VLQBin: 00000000 10000001 10000000 00000000

Lets say I want to represent the number 3435 in VLQ. 3435 in
binary is 110101101011. We can not fit this in a byte. So we will
chop it up from the end in 7-bit blocks.

Septet 7 6 5 4 3 2 1
#1 1 1 0 1 0 1 1
#2 0 0 1 1 0 1 0

Now we prepend all but the last with a 1-bit to indicate that an octet
follows and prepend a 0-bit to the last, signalling the final octet.

Octet 8 7 6 5 4 3 2 1
#1 0 1 1 0 1 0 1 1
#2 1 0 0 1 1 0 1 0

Finally we concatenate them, most significant octet first, into

Encoded: 10011010 01101011 ToHex: 0x9A 0x6B

*Extra* *Resources:*

- [[https://en.wikipedia.org/wiki/Variable-length_quantity][https://en.wikipedia.org/wiki/Variable-length_quantity]]
- [[https://blogs.infosupport.com/a-primer-on-vlq/][https://blogs.infosupport.com/a-primer-on-vlq/]]

*For* *an* *excellent* *implementation* *of* *this* *algorithm* *look* *here:*

- [[https://github.com/go-audio/midi/blob/master/varint.go][https://github.com/go-audio/midi/blob/master/varint.go]]

.play algorithms/fun/vlq.go
31 changes: 31 additions & 0 deletions _content/tour/grc/algorithms-numbers.article
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
Number Operations
This section provides examples that perform number operations.

* Palindrome

- [[https://www.ardanlabs.com/training/individual-on-demand/ultimate-go-bundle/][Watch The Video]]
- Need Financial Assistance, Use Our [[https://www.ardanlabs.com/scholarship/][Scholarship Form]]

The sample program implements a check to see if an integer is a
palindrome or not.

- See more at [[https://en.wikipedia.org/wiki/Palindrome][https://en.wikipedia.org/wiki/Palindrome]]

*Diagram*

A palindrome is a word, number, phrase, or other sequence of symbols that
reads the same backwards as forwards.

┌───┐┌───┐┌───┐
│ 1 ││ 0 ││ 1 │ ────▷ Palindrome
└───┘└───┘└───┘

┌───┐┌───┐┌───┐
│ 1 ││ 2 ││ 3 │ ────▷ NO
└───┘└───┘└───┘

┌───┐
│ 5 │ ────▷ Palindrome
└───┘

.play algorithms/numbers/palindrome.go
43 changes: 43 additions & 0 deletions _content/tour/grc/algorithms-searches.article
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
Search Operations
This section provides examples that perform search operations.

* Binary Search

- [[https://www.ardanlabs.com/training/individual-on-demand/ultimate-go-bundle/][Watch The Video]]
- Need Financial Assistance, Use Our [[https://www.ardanlabs.com/scholarship/][Scholarship Form]]

The sample program implements a function that performs an iterative
binary search against set of integers.

- See more at [[https://en.wikipedia.org/wiki/Binary_search_algorithm][https://en.wikipedia.org/wiki/Binary_search_algorithm]]

*Diagram*

Binary search compares the target value to the middle element of the
array. If they are not equal, the half in which the target cannot lie
is eliminated and the search continues on the remaining half, again
taking the middle element to compare to the target value, and repeating
this until the target value is found. If the search ends with the
remaining half being empty, the target is not in the array

┌────┐
│ 83 │ ◁── Target Number
└────┘
┌────┐┌────┐┌────┐┌────┐┌────┐
│ 04 ││ 42 ││ 80 ││ 83 ││ 95 │ ◁── Starting Array
└────┘└────┘└────┘└────┘└────┘
┌────┐ ◁── Middle Value
│ 80 │ ◁── Target Number Is Greater
└────┘
┌────┐┌────┐
│ 83 ││ 95 │ ◁── Search This Half
└────┘└────┘
┌────┐
│ 83 │ ◁── Middle Value
└────┘
┌────┐
│ 83 │ ◁── Target Found / Idx 3
└────┘

.play algorithms/searches/binary_iterative.go
.play algorithms/searches/binary_recursive.go
Loading