Home

20Jun2022: LeetCode, Maths

Created June 20, 2022

Today was another chill day on the coding front, just from a couple other personal priorities taking precedence which are really important for some upcoming reasons. But I am trying to keep up some of this momentum as well.

Leetcode

Today I did a really simple palindrome leetcode challenge - nothing big but helpful to just practice a bit of string manipulation. It reminds me I should get back to the daily code challenges from GA as well (but for whatever reason do not push as counts to my GH - something about the repository being forked).

Maths

There's a final section in Algorithms of The Self Taught Computer Scientist on some maths review.

I'm currently going through this chapter and I'm working to understand why this bitwise operator function in Python works the way it does: def is_even(n): return not n& 1 I'm not entirely catching why print(2 & 3) yields 2, and if I use and it yields 3. This will be material I have to dig into more and study...I presume it will come up again as I study Python specifically. I'm also just not catching Python like before - after studying JavaScript it's gotten a bit hard to switch to Python. But I'll get over it I'm sure. I'm just still trying to cover more ground in expanse with coding and sticking to JavaScript has certainly been a lot easier.

Something new I learned today from this section is Euclid's algorithm for finding the greatest common factor. I've never seen this in all my years of maths class, and I really like it - finding the greatest common factor by dividing the two numbers and finding the remainder, and continuing to divide it until there is no more remainder. The code looks like:

    if y == 0:
        x, y = y, x
    while y != 0:
        x, y, = y, x % y
    return print(x)

Personally I love using the modulus operator in coding - I remember the first time I tried it in a coursera on Python and I was like wow, this is a really fun operator. I don't know why it's just very useful to isolate that remainder value in the most random situations I've found. I think I used it to do Snake because I used a 1D array so it had to be n % width == 0 to test for whether it was on a left or right border or not (although I ended up iceboxing that feature because it was too difficult and I hadn't created a border...maybe I can go back to correct that but I kind of like the way my Snake runs at the moment).

In any case, this concludes going through the Algorithms part of The Self Taught Computer Scientist - super glad to be making progress and thanks to this DevDojo blogging practice! Time to go through Data Structures next. :)

Catt