Computer Science, Crafty, Logic, Simon's sketch book

Simon crafting a search engine with sticky notes

Simon working on a simplified version of a search engine, including just a few documents, and performing calculations to determine how many searches one should do to make creating an index of all the documents efficient (something he has picked up in Brilliant.org’s Computer Science course.

screenshot from Brilliant.org’s Computer Science course
Computer Science, Contributing, Group, Logic, Math and Computer Science Everywhere, Milestones, Murderous Maths, Notes on everyday life

Brilliant Discussions

This is an example of the learning style that Simon enjoys most. He really likes doing the daily challenges on Brilliant.org. He later sometimes discusses them with other participants or even writes wikis!

Simon writing an explanation on Brilliant.org’s discussion page about a Computer Science Fundamentals daily challenge. Link to the full discussion: https://brilliant.org/daily-problems/what-variable-1/
The problem and Simon’s answer
Simon’s contribution to the discussion
Community Projects, Contributing, Math Riddles, Math Tricks, Milestones, Murderous Maths, Simon teaching, Simon's sketch book

Simon having fun solving math puzzles on Twitter.

While in Southern France, Simon really enjoyed solving this puzzle (he originally saw in a Brilliant.org vid). He was so happy with his solution he kept drawing it out on paper and in digital apps, and later shared the puzzle on Twitter. This sparked quite a few reactions from fellow math lovers, encouraged Brilliant to tweet new puzzles and now Brilliant follows Simon on Twitter, how cool is that!

Coding, Computer Science, English and Text-Based Data, Python, Simon teaching

Encoding and Cracking Codes in Python

Had great fun learning how to crack codes using Python! Simon is currently following the Programming with Python course on Brilliant.org and showed me how to see whether an encrypted piece is gibberish or a real text is hidden behind it.

Simon writes:

A Caesar Shift is a simple cipher, which was a standard in Roman times. It works like this: shift every character by some fixed amount in the alphabet. Something like this:

Example: Suppose some professor writes his name on his board:

ES. TNJUI

It’s encoded with a caesar shift. Because it’s a professor’s name, it probably starts with “Dr.”, so it’s probably a shift that turns D into E, and R into S. So we can work backwards from that shift, and get:

DR. SMITH

That was an easy one, so let’s do something more complex with code.

One of the messages below is a real text, encoded using a Caesar Shift, the other one is just a random sequence of letters. Can you tell which one is which?

Text 1:
yfdpcpoplhhwdpssbjnsqvtlcpzpxqugtjphvgotuvwxufgoqigxwgkskduooyeuoue
fjlnmsqpgxrmcseeliswdheywseqgcbeothskxdzekgxmmkildjnaqbukprpfaaknsu
qpdwayqaqfxsoapvsgreqydqjnkpjghvrkygtidzibhrqkmocukhcunpjcazzvomtsc
fgycwfltmiegaejwcqrgsnxxcbtcrckufwsdxdhbxgppxcuzapbdhftzmugryfseavv
bssqlxanvmfwwzityziixasivzkmvtfczqmdgkabcnjbyhaoealengfptuedlmvryeb
titbwqkekzdpmbtiphdkwwiduassvbgalxgrfhrjrjplxpujrprqzcpcdqsjorigazt
kwwlnwbjryrzhgcttroyemuwwixwufymnknirzmexyowobvardlqktzajzoijwulomg
ztefdpftjealzapcgipgaaspuzxklvd
Text 2:
swodkdbkfovvobpbywkxkxdsaeovkxngrycksndgyfkcdkxndbexuvoccvoqcypcdyx
ocdkxnsxdronocobdxokbdrowyxdrockxnrkvpcexukcrkddobonfsckqovsocgrycop
bygxkxngbsxuvonvszkxncxoobypmyvnmywwkxndovvdrkdsdccmevzdybgovvdrycoz
kccsyxcbokngrsmriodcebfsfocdkwzonyxdrocovspovoccdrsxqcdrorkxndrkdwym
uondrowkxndrorokbddrkdponkxnyxdrozonocdkvdrocogybnckzzokbwixkwoscyji
wkxnskcusxqypusxqcvyyuyxwigybuciowsqrdikxnnoczksbxydrsxqlocsnobowksx
cbyexndronomkiypdrkdmyvycckvgbomulyexnvocckxnlkbodrovyxokxnvofovckxn
ccdbodmrpkbkgki

Simon has explained a way to see whether the encrypted piece contains meaningful (real) text: one can plot the frequency of each letter as it’s used in the encrypted piece. If all letters have generally similar frequency, it’s not a real text, because in real texts, certain letters are encountered much more often than others. Below are the frequency plots Simon made for the texts above, using a Python package called matplotlib:

Frequencies for text 1:

Frequencies for text 2:

As you can see, the second plot depicts a greater variety in frequencies. “For example, o appears the most, but g does not appear that much. And t does not appear at all!” Simon showed me.

As it turned out, we could actually use our knowledge about which letters naturally appear more frequently in English-language texts to crack the code! “Which letter is the most frequent one in English writing?” Simon asked me. “Letter e!” I guessed. “So now we know that the letter o in the encrypted text stands for e in the real text!” Simon exclaimed. “All we have to do to decode it now is simply shift the letters by 10 letters back, because e is 10 letters behind the o!”

Simon Writes:

So, what is the message about? Simon tweaked Brilliant’s code to make sure it shifted by the amount of 10…

imetatravellerfromanantiquelandwhosaidtwovastandtrunklesslegsofstonestandinthedesertnearthemonthesandhalfsunkashatteredvisagelieswhosefrownandwrinkledlipandsneerofcoldcommandtellthatitssculptorwellthosepassionsreadwhichyetsurvivestampedontheselifelessthingsthehandthatmockedthemandtheheartthatfedandonthepedestalthesewordsappearmynameisozymandiaskingofkingslookonmyworksyemightyanddespairnothingbesideremainsroundthedecayofthatcolossalwreckboundlessandbaretheloneandlevelsandsstretchfaraway

…put the spaces and punctuation in appropriately…

I met a traveller from an antique land
Who said: “Two vast and trunkless legs of stone
Stand in the desert . . . Near them, on the sand,
Half sunk, a shattered visage lies, whose frown,
And wrinkled lip, and sneer of cold command,
Tell that its sculptor well those passions read
Which yet survive, stamped on these lifeless things,
The hand that mocked them, and the heart that fed:
And on the pedestal these words appear:
‘My name is Ozymandias, king of kings:
Look on my works, ye Mighty, and despair!’
Nothing beside remains. Round the decay
Of that colossal wreck, boundless and bare
The lone and level sands stretch far away.”

So, it’s about Archeology! This is the poem Ozymandias by Percy Shelley (1818).

Source Code

Encoder / Decoder:

alphabet = "abcdefghijklmnopqrstuvwxyz"

# convert between letters and numbers up to 26
def number_to_letter(i):
    return alphabet[i%26]

def letter_to_number(l):
    return alphabet.find(l)

# How to encode a single character (letter or not)
def caesar_shift_single_character(l, amount):
    i = letter_to_number(l)
    if i == -1: # character not found in alphabet:
        return "" # remove it, it's spaces or punctuation
    else:
        return number_to_letter(i + amount) # Caesar shift

# How to encode a full text
def caesar_shift(text, amount):
    shifted_text = ""
    for char in text.lower(): # also convert uppercase letters to lowercase
        shifted_text += caesar_shift_single_character(char, amount)
    return shifted_text

### MAIN PROGRAM ###

message = """
paste the text here
"""

code = caesar_shift(message, 2)
print(code)

Code for Plots:

import matplotlib.pyplot as plt
alphabet = "abcdefghijklmnopqrstuvwxyz"

code = """
paste the text here
"""

letter_counts = [code.count(l) for l in alphabet]
letter_colors = plt.cm.hsv([0.8*i/max(letter_counts) for i in letter_counts])

plt.bar(range(26), letter_counts, color=letter_colors)
plt.xticks(range(26), alphabet) # letter labels on x-axis
plt.tick_params(axis="x", bottom=False) # no ticks, only labels on x-axis
plt.title("Frequency of each letter")
plt.savefig("output.png")
Math Riddles, Murderous Maths, Notes on everyday life, Simon teaching, Simon's sketch book, Together with sis

Teaching Mathematical Fundamentals

Simon loves challenging other people with math problems. Most often it’s his younger sister Neva who gets served a new portion of colourful riddles, but guests visiting our home also get their share, as do Simon’s Russian grandparents via FaceTime. Simon picks many of his teaching materials in the Mathematical Fundamentals course on Brilliant.org, and now Neva actually associates “fundamentals” with “fun”!

Exercise, Math Riddles, Murderous Maths, Notes on everyday life, Simon teaching, Simon's sketch book, Together with sis, Trips

Math on the Beach

Sunday at the beach, Simon was reenacting the 5 doors and a cat puzzle (he had learned this puzzle from the Mind Your Decisions channel). The puzzle is about guessing behind which door the cat is hiding in as few guesses as possible, while the cat is allowed to move one door further after every wrong guess.

the little houses served as “doors”, and Simon’s little sister Neva as “the cat”

“Here’s a fun fact!” Simon said all of a sudden. “If you add up all the grains of sand on all the beaches all over the world, you are going to get several quintillion sand grains or several times 10^18!” He then proceeded to try to calculate how many sand grains there might be at the beach around us…

In the evening, while having a meal by the sea, Simon challenged Dad with a Brilliant.org problem he particularly liked:

Simon’s explanation sheet (The general formulas are written by Simon, the numbers underneath the table are his Dad’s, who just couldn’t believe Simon’s counterintuitive solution at first and wanted check the concrete sums. He later accepted his defeat):

Math Riddles, Math Tricks, Murderous Maths, Simon's sketch book

Math Fun

magic rectangle
magic square
challenging Dad to guess what the magic square and the magic rectangle are
fun multiplication shortcuts
favourite Brilliant.org problem (Simon has actually carried out an experiment with in real life marbles is a sack to see whether the probability predicted is correct)

Simon finds the explanation on Brilliant.org incomplete, so he started a discussion about it on the Brilliant community page: https://brilliant.org/discussions/thread/games-of-chance-course-marble-problem/?ref_id=1570424

challenging Dad with the Brilliant.org problem
chalenging Dad with the Brilliant.org problem (Simon has also taken this problem to show to his French teacher)
Coding, Computer Science, Milestones, Murderous Maths, Python, RaspberryPi, Simon teaching, Simon's Own Code, Simon's sketch book

More Sorting Algorithms!

An update to Simon’s new project: a series of video tutorials on sorting algorithms! See the full playlist here.

Part 7: Heapsort

Finally, parts 6 and 7 of Simon’s exciting series of video tutorials about sorting algorithms are done! In the videos, Simon codes on his RaspberryPi, but here is the link to the Python code (parts 6 – 7) available on his GitHub page:
https://gist.github.com/simon-tiger/be3864b36f6d89fecd06f150063a6321

Part 6: Shellsort

The code of the sorting algorithms discussed in the previous videos (parts 1 – 5) is available here: https://gist.github.com/simon-tiger/5be70247a066f69c2578be5bb8e41e59

Simon wrote the Shellsort code himself. He tried to run his own code for Heapsort as well, but didn’t get the list fully sorted, so in the end he implemented the heapsort code that he learned from Brilliant.

“Then, with VERY much relief, I MASSIVELY condensed the code (to just 3 lines!), using Zax Rosenberg’s blog“, Simon adds.