Just a funny piece from a member-only Coding Train session ðŸ˜‰

# Tag Archives: Coding Train

# Example of Simon contributing an issue on GitHub

Below is Simon’s issue/ topic suggestion he contributed to the Coding Train GitHub yesterday, addressed to Daniel Shiffman:

## Function Overloading

Nah.

## Operator Overloading

OK, first, we have to understand the `valueOf()`

function. `valueOf()`

is a function, that typically performs on a string, that converts it into a “primitive” data type.

A number is a primitive data type, because it’s not an object. And, you can see that by opening a Terminal window, running `node`

and type:

> 2 + 2 // and get 4

Because JS doesn’t have any “real” overloading, you can’t put `+`

in between two objects, in between two objects, and get an answer!

Well, with one slight exception, which is the `valueOf()`

function. It will tell JS how to interpret an instance of an object as a primitive data type, whenever you want to add them together or something. If you put a `valueOf()`

function into the prototype (or class, if you will) of an object, and it converts it into a number, or some other primitive data type, you can suddenly do arithmetic on these objects!

This does have a limitation, though. Say you write a class:

class Vector { constructor(x=0, y=0) { this.x = x; this.y = y; } // Maybe you want a valueOf() function to add them together valueOf() { // TL;DR What goes here??? } }

Maybe you want to add the individual components of a vector to add two vectors together.

It turns out, the answer is, *nothing can go in the place of the question mark*!

Here’s why: There’s no real primitive data type, with further components. That’s because that’s what a primitive data type is! It doesn’t have data, it *is it’s own data!* A Vector does have further components, however, and so we arrive at a contradiction. Because a vector has further components, and `valueOf()`

must return something without further components, this situation is impossible!

## String Overloading

Well, it’s really the same as Operator Overloading, except you need to use the `toString()`

function instead of the `valueOf()`

function. It converts it into a string. I don’t really know why you’d want to do this, maybe you would affect how you print it. I actually don’t even know if `toString()`

can do this.

## [TL;DR] Overloading

Look at this messy video about Matrix Math that you made: https://www.youtube.com/watch?v=NgZAIkDcPkI, at 23:15.

Guess what, there’s a way to fix that!

I don’t know how this one is called. When you say `this`

, it’s an object. But, because objects are associative arrays, you can actually treat `this`

as an associative array! Something like this:

class Matrix { constructor(rows, cols) { this.rows = rows; this.cols = cols; // this.data = [] for (let i = 0; i < this.rows; i++) { this[i] = []; // OMG for (let j = 0; j < this.cols; j++) { this[i][j] = 0; // OMG } } } // . // . // . }

It’s as easy as that!

If you want to, you could even add a `this.length`

variable, and suddenly, you would even be able to iterate over it, with a `for..of`

loop!

# Simon’s Computer Science Algorithm Suggestions

Simon’s suggestion for the Coding Train on GitHub:

Because I like computer science these days, here are some computer science algorithm suggestions:

- Data Structures
- Array
- Linked List
- Hash Table
- Stack
- Queue
- Priority Queue (Binary heap)
- Suffix Array
- Graph Theory
- Graph (general)
- Tree
- Binary Tree
- Full vs. Complete
- BST
- Binary Heap
- AVL Tree
- Red-Black Tree
- Segment Tree
- DFA

- Biparite
- UFDS
- Fenwick Tree
- Min Spanning Tree
- Suffix Tree

- Computational Geometry
- Polygon, etc.

- Algorithms
- Shuffling
- Fisher-Yates Algorithm

- Sorting
- Bubble Sort
- Selection Sort
- Insertion Sort
- Merge Sort
- Quicksort
- Counting Sort
- Radix Sort
- More?
- Even More? (Scroll down to see a GIANT table)

- Traversal / Pathfinding / SSSP
- Basic
- Pre-order
- In-order
- Post-order
- Depth-first
- Breadth-first
- More?

- Shortest Pathfinding
- Dijkstra’s Shortest Path
- A*

- More?
- Even More?

- Basic
- Substring Finding
- Brute-force
- DFA
- KMP
- More?

- Min Spanning Tree
- Brute-force
- Kruskal’s Algorithm
- Prim’s Algorithm(s)

- Max-flow
- Graph Matching
- Cycle Finding
- Convex Hull
- Gift Wrapping
- Graham Scan
- Quickhull
- “The Ultimate Planar Convex Hull Algorithm”
- More?

- Min Vertex Cover
- Brute-force
- MVC
- Approximation

- Traveling Salesman
- Brute-force
- Dynamic Programming
- Approximation

- Steiner Tree

- Shuffling

If you’re brave, Do you want more even after *all of this*?

One last note: **you’re not going to do all of them (probably!)**.

# Chat experiences

Simon came up to me last nigh saying he didn’t understand what “they mean with God is with me” and showed the following funny conversation going on in the comments under Daniel Shiffman’s Quicksort tutorial:)

# Fluid Dynamics: Laughing and Crying

Simon was watching Daniel Shiffman’s live coding lesson on Wednesday, and when fluid dynamics and Navier-Stokes equations came up (describing the motion of fluid in substances and used to model currents and flow), Simon remarked in the live chat that the Navierâ€“Stokes equations are actually one of the seven most important unsolved math problems and one can get a million dollar prize for solving them, awarded by the Clay Mathematics Institute.

(I looked this up on Wikipedia and saw that it has not yet been proven whether solutions always exist in 3D and, if they do exist, whether they are “smooth”Â or infinitely differentiable at all points in the domain).

We had read an in-depth history of the Navierâ€“Stokes equations in Ian Stewart’s book several weeks ago, but I must confess I didn’t remember much of what we’d read anymore. “Is it that chapter where Stewart describes how Fourier’s paper got rejected by the French Academy of Sciences because his proof wasn’t rigid enough?” I asked Simon. – “No, Mom, don’t you remember? That was Chapter 9 about Fourier Transform! And the Navier-Stokes equations was Chapter 10!” – “Oh, and the Fourier Transform was also the one where there was a lot about the violin string, right?” – “No!”, – Simon really laughs at me by now, – “That was in Chapter 8, about the Wave Function! You keep being one chapter behind in everything you say!” Simon honestly finds it hilarious how I can’t seem to retain the information about all of these equations after reading it once. I love his laugh, even when he’s laughing at me.

Today though, he was weeping inconsolably and there was nothing I could do. Daniel Shiffman had to cancel the live session about CFD, computer fluid dynamics. Simon had been waiting impatiently for this stream. My guess, because it’s his favourite teacher talking about something interesting from a purely mathematical view, a cocktail of all things he enjoys most. And because he never seems to be able to postpone the joy of learning. He had explained to me once that if he has this drive inside of him to conduct a certain experiment or watch a certain tutorial *now*, he simply can’t wait, because later he doesn’t seem to get the same kick out of it anymore.

I’m baking Simon’s favourite apple pie to pep him up. Here are a couple more screen shots of him taking part in the Wednesday lesson:

# Daniel Shiffman quotes Simon’s thoughts about complex numbers

NYU’s Associate Professor Daniel Shiffman quotes Simon during a Coding Train live tutorial from New York about Fourier Transform Drawings on 16 January 2019. Simon was participating via the Slack chat. This is just an example of how Simon takes part in the live sessions on a regular basis.

Link to the actual live stream: https://www.youtube.com/watch?v=0b3R8oWffkw

# Simon took part in a Coding Train livestream in Paris!

The video below is part of Daniel Shiffman’s livestream hosted by GROW Le Tank in Paris on 6 January 2019 about KNN, machine learning, transfer learning and image recognition. Daniel kindly allowed Simon to take the stage for a few minutes to make a point about image compression (the algorithm that Daniel used was sort of a compression algorithm):

Here is a different recording (in two parts) of the same moment from a different angle:

# Simon is programming a Logo code editor, but is stuck with one tricky function

Simon is programming a full implementation Logo code editor in p5.js (JavaScript), as part of Coding Train’s Logo Coding Challenge. Logo is a coding language that Simon says he has been learning via Turtle Academy, a site containing 20 lessons. He has already created most of the editor (got as far as lesson 17 on Turtle Academy) but got stuck with the **fill** function in Logo (he doesn’t know how to program the fill function). Can anyone help him out? Simon’s code is online at: https://editor.p5js.org/simontiger/sketches/BknVvCFTm

# Creative Coding Utrecht MeetUp

What a blissful day at Creative Coding Utrecht! Simon also got a chance to show a few of his projects in Processing to a cool and understanding audience!

# On the train

On the way to London: Simon watching the Coding Train on the train…

And giving his sis an English lesson

On the way back: doing maths under the table