I'm reading the Feynman lectures on Physics at the moment. It's based on some lectures given during the early 1960's, but Feynman's flare and passion is still just as infectious now as it must have been back then, and it's certainly having a huge impact on my study of algorithms.
There are so many quotable bits, but here's one of my favourites:
'From the point of view of basic physics, the most interesting phenomena are of course in the new places, the places where the rules do not work - not the places where they do work! That is the way in which we discover new rules.'
It's all about what we don't know. That's the fun stuff!
Sunday, 22 October 2017
Tuesday, 17 October 2017
Algorithms: Dynamic Connectivity and Quick Find
So, I've signed up for this Algorithms course with Coursera.
It starts on Monday 30th October, but I'm getting a head-start, because I'm a little bit rusty.
The first lesson is all about Union Find: Dynamic Connectivity and Quick Find.
It starts on Monday 30th October, but I'm getting a head-start, because I'm a little bit rusty.
The first lesson is all about Union Find: Dynamic Connectivity and Quick Find.
Key takeaways:
- To find the algorithm to solve a problem you first need to understand the problem.
- If at first you don't succeed, try and try again.
- And even if you do succeed, keep trying until you find the best solution - That's the scientific method.
- When joining the dots, the point of entry is everything.
- Equivalence relations:
- Reflexive: A thing is connected to itself - i.e. p is connected to p.
- Symmetric: If p is connected to q, then q is connected to p.
- Transitive: If p is connected to q, and q is connected to r, then p is connected to r.
- Union commands: They are the match-makers.
- Connected Queries: They follow the breadcrumbs and discover connections.
- Data Structures: Using integers as an array index is convenient to start with. Do it.
I'll put my notes up in a convenient infographic or something shortly.
Thanks for reading!
Tuesday, 10 October 2017
Algorithms... Hello my old friends!
HelloWorld!
It's been a while!
My day job has been keeping me busy, but the challenges have dried-up.
I need something to crank up the old cogs and put my brain through some sweet pain! What better way to do that than tackle algorithms again. My old friends.
I've signed up for 'Algorithms, Part I' on Coursera and although the first submission isn't for 3 weeks, I'm making a start now because it's been such a long time since I did any programming.
Programming skills / awareness or just generally knowing your way round a computer is great for work, but I'm a bit rusty.
Step 1: Download a programming environment
This course recommends DrJava, so I downloaded that this evening and had a play.
I'll keep you updated, and I hope you enjoy the journey!
It's been a while!
My day job has been keeping me busy, but the challenges have dried-up.
I need something to crank up the old cogs and put my brain through some sweet pain! What better way to do that than tackle algorithms again. My old friends.
I've signed up for 'Algorithms, Part I' on Coursera and although the first submission isn't for 3 weeks, I'm making a start now because it's been such a long time since I did any programming.
Programming skills / awareness or just generally knowing your way round a computer is great for work, but I'm a bit rusty.
Step 1: Download a programming environment
This course recommends DrJava, so I downloaded that this evening and had a play.
I'll keep you updated, and I hope you enjoy the journey!
Tuesday, 3 May 2016
for & while loops - The Complete Node JS Developer Course
for and while loops
Lesson 19 started off with a simple demonstration. We followed along and created the simple countdown program below.
Once that was done, we had to go away and tackle a little project of our own. This time, we had to create a couple of countdown functions, that both do the same thing, but one uses a while loop, and the other uses a for loop. Here's mine below:
After that, I resumed the video and followed the tutor's worked example. See below:
I've got loads of notes on for and while loops from the codecademy course that I did a few months ago, so I'll write a full blog on that soon.
Sunday, 1 May 2016
PROJECT 2 - The Complete Node JS Developer Course
In this project we want to be able to do the following things:
- Create new bank accounts
- Search for bank accounts
- Deposit and withdraw amounts
- Check account balances
In lesson 18 of The Complete Node JS Developer Course (check here for an update on my progress so far), the task was set out, and we had to go away and work through it independently. Lesson 19 is a step-by-step guide to a complete solution.
Getting Started
In lesson 18 we did the ground work for the project. This is the code we created to set the foundations:
We have created an empty array that will store all of the accounts, and there are some methods (or functions) that we can call on to make deposits, withdrawals, and check balances.
The Task
In the instructions we are told to create a new function called 'createAccount'. It's going to take an account object and store it in an array of accounts.
Each account object needs a 'balance', which should be a number, and a 'username', which should be a string.
The second function we're going to create is called 'getAccount' and takes one argument, which is 'username'.
The Solution
We start with the 'createAccount' function. It accepts one argument, which is the object 'account'.
Basically, what we've done there is create a function, 'createAccount', that takes an account object and pushes it into the accounts array.
Now we can work on our 'getAccount' function.
getAccount
Within the function, we use forEach to iterate over the accounts and find any matching account.
We create a new variable called 'matchedAccount' within the function, which will store the account if a match is found.
Within the forEach, we want to check if the username of the account matches any of our accounts, so we create an if statement to do that. We then save the account to the matchedAccount variable that we created earlier.
We then return the matched account.
Re-cap
So, here's what we have so far:
Underneath that, we are going to create a new account.
New Account
We create a new account and save it to a variable. We then set that variable equal to createAccount, which is a function that expects an account object. The new object is created right within the function! Awesome! We give it a username and a balance. Yay!
Let's start as we mean to go on, and make a deposit into our account.
Deposit
We'll be using that function we created earlier on lines 19 to 21. Here's a quick reminder:
Here's how we make a deposit into our new account:
Lovely!
We use console.log to keep track of things, and we do this with the getBalance function (also created earlier on lines 27 to 29):
Withdrawal
Another old'un, but a good'un (on lines 23 to 25):
And here's how we use it:
getBalance makes another appearance :)
getAccount
The star of the show!
Create a new variable called existingAccount, and set it equal to getAccount, with the username passed in. It accepts one argument, a string.
It will return the balance of the my account!
We can test it out by creating another account for Pinky.
To make sure that everything is working as it should do, we can log out both of the accounts that we have created so far, by simply doing the following:
That will log them both out to the terminal, with their usernames and balances. Beautiful!
Finally, let's create a new variable for the Pinky's account (like we did with my account earlier):
Here's a re-cap of that code from line 31 onwards:
And it's all done! Until the next time :)
Friday, 29 April 2016
JavaScript Revision Notes - Functions
Here are some flashcards that will be helpful when starting out your JavaScript journey:
Here's how to create a simple function:
In our example, the parentheses are empty.
But we can also add arguments to our function.
We do this by defining the arguments inside the parentheses, and then adding them to the function when we call it:
We have defined the argument inside the parenthesis, giving it the name 'name', and we have passed in a string value of 'Danielle' when we call it. This will print out 'Hello Danielle'.
Functions
Here's how to create a simple function:
In our example, the parentheses are empty.
But we can also add arguments to our function.
We do this by defining the arguments inside the parentheses, and then adding them to the function when we call it:
We have defined the argument inside the parenthesis, giving it the name 'name', and we have passed in a string value of 'Danielle' when we call it. This will print out 'Hello Danielle'.
Arrays - The Complete Node JS Developer Course
Arrays
Lesson 17 covers some really interesting stuff!
Methods
A method is nothing more than a function; it's just accessed using dot notation.
.push method
You can add an item to the end of an array using the .push method!
.unshift method
Here, we have an array containing the numbers 100 and 50. But by using the .push method, we have added the number 79 to the end of the array. So when we run it from the Terminal, it will return all three numbers: 100, 50, 79.
You can add an item to the beginning of an array by using the .unshift method.
.pop method
You can also remove items from an array. The .pop method removes the last item of the array. So when you run the program, that last item will no longer be returned, but the next item along will be returned instead.
In this case, the .pop method on line 3 will remove 79 from the end of the array. Line 5 will show us which item has been removed; i.e. 79 will be logged out by line 5. By the time we get to line 6 and log out the full array, the number 79 will be nowhere to be seen! .pop magic!
.shift method
As we saw in the last lesson, the .pop method removes things from the end of an array. The .shift method, on the other hand, removes the first item of an array.
In the example above, 100 will be removed by line 3, logged out by line 5, and nowhere to be seen when line 6 logs out the full array.
Iteration: the forEach method
This method is special because it takes a function as an argument.
Functions
In JavaScript, naming a function is not required. It's only required if you're going to be referencing the function at any given point. If you're simply passing in the function as an argument, there's no need to name it.
.length method
In this example, the .length method will log out the length of the array, which is 3, because there are 3 items in the array.
The Challenge
We had to create a program that added the grades together (i.e. 100 + 50 + 79), divided that total by the number of grades (i.e. 229 / 3) and returned the result (i.e. 76.333...). It looked a little something like this:
Subscribe to:
Posts (Atom)