Posts

Week 13

Image
Below is a copy and paste of my code in python and java. Interestingly enough it made the background and colors the same as my IDE. Hopefully, this is better than my copy pastes in the past so you can see the code much better, I think. This python code is for my minilab 2. I came into this thinking this would be easy enough and it sorta was until I got to coding random integers to fill an array. Everything else was more or less review from what I did in the first one but I needed to look up how to initialize random class. I did that and came across a bit of a hold up when my code worked but it printed the same number( when I used the randint that I learned in an article). EX 3,3,3,3 (if array size was 4 and seed was 3). From there I tried to look up how to fill an array with random unique numbers and I came across a you tube video that was helpful until I ran the code and it was working because my tempRand was making my boolArray go out of bounds with the index. After many fixes and re...

Week 12

Image
  This week I felt a sudden urge to try to convert my minlab1 into python to try to learn the language. The first photo is the python code and the second is the java that I did during 205. As you can see in the code it is very different in java then in python. You can sorta till the idea and goal is the same but the code and grammar is different. Python needs no semi colons, which is so weird but convenient because its one less thing I need to worry about. Print doesnt need the system.out. I need to my int variables in to string in order to print, which is interesting. Conditional statements done need parenthesis and after its condition there is a colon instead of a pair of brackets. Input is set to take  in string so I was getting a lot of errors until I found out you have to type cast it to an int. Conveniently, it makes the left side variable a float if the right has division. Down below we see the results when given the same data. In addition to this little side quest, we ...

Week 11

Image
 Today I did another leetcode problem. Like last week I found a similar problem to one I've done in class but with a different language but instead of mips this time it is in C++. I'm starting to think my 240 teacher was making us do these problems on purpose haha... anyway, the problem this time is called valid parenthesis or matching brackets is what my 240 teacher called it. I knew the basic rundown of the problem and tried to code it. But to give a brief rundown we are checking if all brackets "("  or "{"  or "[" are closed correctly. Fortunately, I was able to directly translate the code for the most part, so we can see the tiny differences between c++ and java.  We see in the two pictures below that c++ looks a little different. In java we see the stack as new stack but in C++ #include stack and we dont need to new. In C++ the string as treated a char arrays so we dont need to do charAt in C++ they already are characters and in this respect i...

Week 10

Image
 This week I found an interesting problem that was exactly like a problem I did in my class this semester, csc 230, but instead of mips I did it in java. The problem is fizzbuzz where you take a number and if the number is a multiple of 3 print fizz and it its a multiple of 5 print buzz and if its a multiple of both print fizzbuzz. There are two method one(first one) is the one that was in a video where I discovered the problem and the second one is me doing it the way I thought of. The problem was pretty easy but the way it did intrigued me because It was different than mine his felt much more clever than mine. What he does is creates variable fizz and buzz so when fizz equals 3 and buzz equals 5 we reset and add to the arraylist but its cool that he does this by using variables to keep track of the fizz and buzz. So fizz for the first 10 will look like this 0,1,2,0,1,2,0,1,2,0,1 for buzz its 0,1,2,3,4,0,1,2,3,4,0 at all zeros after the first zero will add the respective word....

Week 9

Image
 Today I looked at some interesting videos of some leetcode videos, which use problems that show up at coding interviews. I watched a guy who was prepping for interviews by running through these problems and talking about them. First Video was about locating islands. (pic of the instructions below) So hopefully you can see how the first input has only one island because all the ones are surrounded by zeros. It's kinda hard to see at first but it helped when he points out why in the video. He talks about the problem and comes up with a pretty straightforward solution. He says he will use a breadth first search(BFS), which I've done a bit of research on before in my week 6 of last years blog. Breadth first search when used on binary search trees takes a node and searches all of its nodes, so I can see how it can apply to this problem. Breadth first search will take one island(1) and search all the 1s connected, which is an island, so when it can't find anymore it means there ...

Week 8

Image
 This week I went over some interesting videos. One video was from the playlist I mentioned in a previous blog and it was titled "Will it stop?". The video is about a problem that asks you to determine if the code will terminate(stop). To determine if it will stop we can mentally plug in numbers. n being less than or equal to 1 will stop the code so the first number we can try is 2.  2 goes in the loop and we get if ( 2%2 =0 )(true)  2/2 =1  and the code stops. So if n is 2 the code will stop.  3 goes in,  if (3%2 =0) (false)  3*3+3=12  if (12 %2=0) (true) 12/2 = 6 n if (6%2 =0) (true)  6/2 =3 and we get a loop.  we plug in 4 we get if (4%2=0) (true) 4/2 =2 and we know 2 stops the code. So from what we see it looks like even numbers will stop the code but if we look at the number 6 it turns out that is not true and we can see if when we can see that when we plug in 3. But when we plug in 8 it stops the code, which makes it look like that...

Week 7

Image
 This week I didn't do to much coding I did a couple of the intermediate "basic programming" problems. What I did do was look at the competitive programming playlist. First couple videos were about reversing a list and the algorithm for doing so. But what I really found interesting was the video "numbers game" where they go through this problem where 2 people play a game where there are two numbers, A and B, you can subtract A-xB or B -xA, but the first player to get <=0 is the loser. So the video goes through cases like what threshold would mean that (A,B) would be losing or winning for player 1. We looked at examples like (12, 15) where player one can take 15- (1)12 and get (12,3) and player two can make player one lose by 12-(3)3 which gives us (3,3) meaning that that player one will lose no matter what. we then look at if (b<a<2b,b) so if a is more than b but less than 2b and we try to figure out if this is winning. We find out that we don't hav...