Posts

Showing posts from June, 2019

Laid out (arrayed) out before you...

We're at the last building block - data structures! But, there is no way to cover every kind of data structure because it is possible for anyone (even you) to make a new one at any time. So instead, we will start with the Array. Just about every programming language includes a built in type that corresponds to an array and the defining characteristic of an array is that each element stored in it can be referenced by an index number that counts up from index [0] and goes up through index [n-1] where 'n' is the number of elements in the array. Usually, there is an easy way to know how many elements there are in an array with some sensible name like 'size', 'length', or 'len'. That is a bunch of words, so let's see a simple example of an array called 'example' with ten elements in it. Here is the list of all of the elements along with their indexes (indices?): example[0] example[1] example[2] example[3] example[4] example[5] e...

Are there bees around here?...

Image
One test that many programmers are asked to do at some point in their life is FizzBuzz. If you haven't heard of it - The problem of FizzBuzz is this (stolen from HackerRank): Write a short program that prints each number from 1 to 100 on a new line. For each multiple of 3, print "Fizz" instead of the number. For each multiple of 5, print "Buzz" instead of the number. For numbers which are multiples of both 3 and 5, print "FizzBuzz" instead of the number. I said last time that I was going to start with a clumsy solution so here is my 'phoning it in' version of pseudo-code for this (let's call it version 1): Loop through the numbers from 1 to 100 and put that number into a variable called 'num' If 'num' is evenly divisible by 3 Print 'Fizz' Else If 'num' is evenly divisible by 5 Print 'Buzz' Else If 'num' is evenly divisible by both 3 and 5 Print 'FizzBuzz' ...