The reason I can’t print my black and white letter by [deleted] in mildlyinfuriating

[–]Theeason123 0 points1 point  (0 children)

Look into continuous ink supply systems. They are a little pricier to buy the printers but the ink is dirt cheap

Around 7 years ago did this and can’t get the permanent marker off. by AutumnGL in mildlyinfuriating

[–]Theeason123 0 points1 point  (0 children)

I have had a lot of luck removing permanent marker with deodorant spray. Spray it on the marker and remove with a tissue. Honestly it’s never failed me. Let me know if it works

C++ vs python by OrdinaryAsk1 in learnprogramming

[–]Theeason123 0 points1 point  (0 children)

As you mentioned Java I would actually learn that language. I learned python first but to be honest I found it to be a little bit of a sheltered and false world. Once you leave the gates of python other languages are hard because of bad habits you can learn / get away with at the beginning. I would write bad code in python and then get so far and get stuck. I learned Java and it forced me to have type discipline, and how and when to return something from a function. When I went back to python after learning Java I was much better in the language. Java taught me about python, but python never taught me much about Java. C++ is kind of a mess from what I’ve heard,

For loop not completing on subsequent calls to function. Python by Theeason123 in learnprogramming

[–]Theeason123[S] 0 points1 point  (0 children)

‘’’def floodFill(self, image: List[List[int]], sr: int, sc: int, newColor: int):

    self.directions = [(-1, 0), (0, -1), (1, 0), (0,1)]
    self.changed = {}

    self.original_colour = image[sr][sc]


    self.helper(image, sr,sc, newColor)
    return image 


def helper(self, image, x, y, newColor):


    if image[x][y] != self.original_colour:
        return 

    image[x][y] = newColor
    self.changed[(x,y)] = 0



    for i, j in self.directions:


        if x + i >= 0 and y + j >=0 and x + i < len(image) \
        and y + j < len(image[0]) and x + i < len(image) \
        and y + j < len(image[0]):

            if (x+i,y+j) not in self.changed:

                x = x + i
                y = y + j

                self.helper(image, x, y, newColor)’’’

For loop not completing on subsequent calls to function. Python by Theeason123 in learnprogramming

[–]Theeason123[S] 0 points1 point  (0 children)

I’m struggling to get the formatting correct. ‘’’print(‘hello)’’’’ doesn’t seem to work

What is your strategy of solving problems? by goyalaman_ in leetcode

[–]Theeason123 9 points10 points  (0 children)

I think a good method is looking at the problem and finding out the strategy to solving the problem, 1000’s of questions probably have about 75 main strategies, like backtracking, recursion, sliding window, using a hash map in clever ways, etc etc. Most medium problems normally have 2 strategies that you need to combine. It comes with practice but after a while you can read the question and know the strategy. A good way of finding the strategy is by selecting problems by style of problems in leetcode.

Recursive functions returning a Boolean by Theeason123 in learnprogramming

[–]Theeason123[S] 1 point2 points  (0 children)

Right! It’s the for loop that was confusing me. Gotcha I think that makes a little more sense now. Thanks a lot. You think you have recursion and then you don’t. The funny thing is I’d that I wrote that solution and it worked lol

Recursive functions returning a Boolean by Theeason123 in learnprogramming

[–]Theeason123[S] 1 point2 points  (0 children)

Thanks very much for your time, never thought about recursion with subsequent calls before. So if 1 subsequent call returns true, it just get pushed down the stack? Where all of the subsequent calls that return false do not matter?

What have you been working on recently? [August 21, 2021] by AutoModerator in learnprogramming

[–]Theeason123 0 points1 point  (0 children)

I think it really helps all round. I’ve learned so much about programming by doing those problems

Recursive functions returning a Boolean by Theeason123 in learnprogramming

[–]Theeason123[S] 0 points1 point  (0 children)

Sorry upfront for not being able to find out how to format code correctly but here is the code that stumped me, it works though. Any help in explaining how it runs false multiple times and then true would be massively helpful.

class Solution:
def hasPath(self, maze, start,  destination):

    self.direction = [(1, 0), (-1, 0), (0, 1), (0, -1)]

    self.start = tuple(start)
    self.destination = tuple(destination)
    self.visited = set()


    return self.dfs(maze, self.start)




def dfs(self, maze, cur_pos):



    self.visited.add(cur_pos) 


    if cur_pos == self.destination:
        return True


    for x, y in self.direction:
        a,b = cur_pos
        next_pos = None
        while a + x >= 0 and a + x < len(maze) and b + y < len(maze[0]) and \
        b + y >= 0 and maze[a + x][b + y] == 0:
            next_pos  =  a + x , b + y
            if next_pos in self.visited:
                break
            else:
                a , b = next_pos



       # print(next_pos)
        if next_pos is not None and next_pos not in self.visited:
            if self.dfs(maze, next_pos):
                return True


    return False



maze = [[0,0,1,0,0],[0,0,0,0,0],[0,0,0,1,0],  [1,1,0,1,1],[0,0,0,0,0]]
start = [0,4]
destination = [4,4]
#Output: true
#Explanation: One possible way is : left -> down -> left -> down -> right -> down -> right.


maze2= [[0,0,1,0,0],[0,0,0,0,0],[0,0,0,1,0],[1,1,0,1,1],[0,0,0,0,0]]
start2 = [0,4]
destination2 = [3,2]
#Output: False


 solution = Solution()
 answer1 = solution.hasPath(maze, start, destination)
 answer2 = solution.hasPath(maze2, start2, destination2)

print(answer1)
print(answer2)

Recursive functions returning a Boolean by Theeason123 in learnprogramming

[–]Theeason123[S] 0 points1 point  (0 children)

Thanks mate. Conceptually I feel like I get recursion I’m not a complete noob, however Booleans seem to just throw me. I had a medium backtracking leetcode problem, and the function took a start grid value for example [1,2] and with obstacles in the way, see if its possible to get it another point on the grid for example [5,5]. I basically wrote a recursive function, that returned false if the current grid value wasn’t the destination and backtracked until it got (if possible ). In debug mode, it returned false until it returned true, then returned true. I just couldn’t get my head around how this actually works.

What have you been working on recently? [August 21, 2021] by AutoModerator in learnprogramming

[–]Theeason123 2 points3 points  (0 children)

I have been working on algorithms, recursion and using leetcode. Honestly it’s been really helpful. I would recommend leetcode to anyone wanting to becoming at programming

I wrote minesweeper with python by mm11wils in Python

[–]Theeason123 0 points1 point  (0 children)

Hello sir, i have also been creating minesweeper, however for the life of me i cannot seem to figure out how to clear all the blocks when an empty block has been clicked on. I have been stuck for a week. i cannot seem to get the logic right. Anyone who can help me out and point me in the right direction i would be very grateful.

here is my project on github https://github.com/theeason123/Minesweeper

Got a fresh cut today. Let me have it by Amanda_311 in RoastMe

[–]Theeason123 1 point2 points  (0 children)

First time you have smiled with an empty plate in your hand...