Solve Robot Paths using backtracking

I got this problem during a mock interview, and I would like to get code review for the backtracking solution. I include 7 test cases, and my solution passes 7 out of 7 test cases. See the online code compiler here

Robot Paths

Prompt: Given a matrix of zeroes, determine how many unique paths exist from the top left corner to the bottom right corner

Input: An Array of Array of Integers (matrix)

Output: Integer


matrix = [[0,0,0,0],           [0,0,0,0],           [0,0,0,0]] robotPaths(matrix) = 38 
matrix = [[0,0,0],           [0,0,0]] robotPaths(matrix) = 4 
# Note:     From any point, you can travel in the four cardinal directions. I decided to do backtracking approach to solve this problem. #           (north, south, east, west). A path is valid as long as it travels #           from the top left corner to the bottom right corner, does not go #           off of the matrix, and does not travel back on itself   def robot_paths(matrix):   num_of_rows = len(matrix)   num_of_cols = len(matrix[0])    def traverse(row, col):     nonlocal num_of_rows      nonlocal num_of_cols     # is row and col in bounds?      if row < 0 or row >= num_of_rows or col < 0 or col >= num_of_cols:       return 0       # has row, col already been visited?      if matrix[row][col] == 1:        return 0       # is row, col the destination?      if row == num_of_rows - 1 and col == num_of_cols - 1:       return 1       # mark coordinate as visited      matrix[row][col] = 1       # initialize sum of total unique paths to end from that coordinate     s  = traverse(row, col + 1) + traverse(row + 1, col) + traverse(row - 1, col) + traverse(row, col - 1)      # backtrack; mark coordinate as unvisited so it can be      matrix[row][col] = 0       return s     return traverse(0, 0)    ############################################# ########  DO NOT TOUCH TEST BELOW!!!  ####### #############################################  def expect(count, name, test):     if (count == None or not isinstance(count, list) or len(count) != 2):         count = [0, 0]     else:         count[1] += 1      result = 'false'     errMsg = None     try:         if test():             result = ' true'             count[0] += 1     except Exception as err:         errMsg = str(err)      print('  ' + (str(count[1]) + ')   ') + result + ' : ' + name)     if errMsg != None:         print('       ' + errMsg + '\n')  def lists_equal(lst1, lst2):     if len(lst1) != len(lst2):         return False     for i in range(0, len(lst1)):         if lst1[i] != lst2[i]:             return False     return True  print('Robot Paths Tests') test_count = [0, 0]   def test():     matrix = [[0, 0, 0, 0],               [0, 0, 0, 0],               [0, 0, 0, 0]]     example = robot_paths(matrix)     return example == 38   expect(test_count, 'should work on first example input', test)   def test():     matrix = [[0, 0, 0],               [0, 0, 0]]     example = robot_paths(matrix)     return example == 4   expect(test_count, 'should work on second example input', test)   def test():     matrix = [[0]]     example = robot_paths(matrix)     return example == 1   expect(test_count, 'should work on single-element input', test)   def test():     matrix = [[0, 0, 0, 0, 0, 0]]     example = robot_paths(matrix)     return example == 1   expect(test_count, 'should work on single-row input', test)   def test():     matrix = [[0],               [0],               [0],               [0],               [0]]     example = robot_paths(matrix)     return example == 1   expect(test_count, 'should work on a 5 x 8 matrix input', test)   def test():     matrix = [[0, 0, 0, 0, 0, 0, 0, 0],               [0, 0, 0, 0, 0, 0, 0, 0],               [0, 0, 0, 0, 0, 0, 0, 0],               [0, 0, 0, 0, 0, 0, 0, 0],               [0, 0, 0, 0, 0, 0, 0, 0]]     print("  Please be patient, test 6 may take longer to run")     example = robot_paths(matrix)     return example == 7110272   print('PASSED: ' + str(test_count[0]) + ' / ' + str(test_count[1]) + '\n\n') 

HAProxy Load Balancing for Multiple URI Paths on the Same Server

I have an application “process-engine” that can run more than one instance in same container (in this case it is WildFly 10). The application’s client use a standard URL like the following to start a process:

However, the “second” process engine must be accessed like this:

Note the change of the word “default” to “engine_2”.

I want HAProxy to load balance the two different URL paths, but I want the client to be able to use only the “default” URL every time. In other words, I want X amount of requests to go to the “default” path, and X amount of requests to go to the “engine_2” path.

There are no ACLs, proxies, etc. involved here. While I have no idea if such a configuration would work, conceptually I’m thinking about something like this in the “backend” section of the configuration:

server myserver  server myserver reqrep ^(https:\/\/[a-zA-Z0-9\-]*\.mydomain\.com:[0-9]{2,5}\/engine-rest\/engine\/)([a-zA-Z0-9_]*)\/(.*)  engine_2/ 

In the conceptual example above, requests would be balanced across both servers, but the URI path would be modified prior to sending them to the send server.

Thank you.

How to disable core JS aggregation and AdvAgg just for admin paths

I help look after a site which uses $ settings['file_public_base_url'] to serve files from a different subdomain on the frontend, but on the backend (admin paths like node/add and node/edit) this causes our JS to be loaded with absolute rather than relative URLs which seems to cause an issue with JS loaded via AJAX not executing correctly. There are no JS errors in my devtools console, but I suspect the cause is that the JS is being loaded from differing subdomains, as turning AdvAgg and core’s JS aggregation off makes the JS files load via relative paths and function as intended.

Without any errors showing in my console or server logs I’m not sure I’m going to be able to get to the bottom of the AJAX issue, so for now a compromise seems to be to turn off aggregation for admin and content editing routes.

What would be the best way to do that? I know I can set $ config['system.performance']['js']['preprocess'] = FALSE; and presumably a similar config key for AdvAgg’s own setting (we have AdvAgg set to optimise/compress JS, so even with system.performance.js.preprocess turned off AdvAgg will still manage the files and use absolute paths to include them. Can config settings be altered on a per route/path basis?

Body, files, and paths problems

I was suggested so many times to migrate my old project from D6, so I finally decided to jump into this. And as it always happens with Drupal, things never work as expected at first attempt.

The old Drupal 6 site has 180 modules (I’ve switched off a vast majority of them), 100K users, about 3K nodes (within 4 content types), 170 taxonomy terms, more than 5K different node relationships, 34K comments, 7K path aliases, 6K user pictures, 5K files (most of them attached to nodes through file fields) and some other stuff.

The new Drupal 8 site was installed with composer create-project drupal-composer/drupal-project:8.x-dev <FOLDER> --stability dev --no-interaction. I also installed all the suggested migration modules and ran the migration process through Drush. The Drush launcher version is 0.6.0 and Drush is version 9.6.0.

drush migrate-import --all command didn’t go well, because it found some missing modules, which are not ported to D8 yet, so my only choice was to use something like drush migrate-import upgrade_d6_taxonomy_term --feedback="100 items" for each migration.

Data was ported, but with some problems.


Some files are not attached to nodes, as they should, especially node images.

Moreover, on /admin/content/files page many of them appear with strange strings, instead of names and are linked to empty files: All these files are actually empty.

As I understood, all of them are node attached images, used as cover image, supposed to represent an article on taxonomy or views pages.

Body field

It is also ported but with two issues:

1) All HTML tags are converted to <p> tags. E.g. if there was H2 heading, it is <p> tag now. The same thing for <li>, images, youtube embedded videos… all inline tags are deleted completely with their contents or replaced by paragraphs. Class names were wiped as well.

Full HTML is enabled for body fileds on both sites.

2) Body is not showing up, when I view a node. If I go to edit – it is in right place, I can even cahnge it. But on node view <div>, which should be containing body, is empty.

I’ve googeled it, and some say that they changed site default language or edited body teaser, because it cannot be null… but all these things are fine in my case – site language is the same, as it was in D6 version and node teasers are not empty.


All 7243 path redirect entries are migrated without errors. I can see all of them on /admin/config/search/path page of new site. However, all node urls are default (node/1234) and if I click on url alias it redirects me back to node/whatever-number.

Also on migrated node, path field is empty.

Creation of a new node doesn’t have any of described problems, everything works fine.

Loading new paths from text with eval file dont update $PATH variable on bash

Having to set a lot of paths on $ PATH then wrote this code to load it from a text file:

  #!/bin/bash   echo '#++++++' >> ./pathlstbkp   cat ./pathlst >> ./pathlstbkp   while read pth; do      cmd='export PATH="'$  pth':$  PATH"'     eval $  {cmd}   done < ./pathlst   echo '' > ./pathlst  

But it dont change the $ PATH variable

Prove that every simple connected graph with $2k$ edges can be partitioned in paths of size 2

I need to prove the theorem on title by induction in $ k$ with $ k>1$ . To add I must show if the theorem holds if the simple graph is not connected.

To show what happens when it is not connected I used this: for any graph with $ 2k$ edges I make a graph with $ 4k$ vertices such that the degree of any vertex is $ 1$ . Therefore, there cannot be any path of size 2.

For the connected part, I would like to know how to show the basis for the induction. Should I draw all the five graphs that can be built with 4 edges and show the partition with drawing? Maybe do the same written? Or is there a way to show the basis of induction that does not rely on the graphs?

hashfile for files in define paths using BATCH

I am trying to get the MD5 values of all files in sub folders that are in external file PathList.txt. I can’t make the script use the path names as define in %%i.
In the example I used "C:\Temp\example\" in the place of %%i so the script will work.

@ECHO off echo Files MD5 > MD5_log.txt  FOR /F %%i IN (PathList.txt) DO (     @FOR /R "C:\Temp\example\" %%G in (*) DO (      for  %%a in (%%G) do certutil -hashfile "%%~a" MD5 | find /i /v "certutil">> MD5_log.txt      ) ) 


C:\folder1\ C:\folder2\ 

This is for old computer, s I don’t have Powershell option.

How can I make it work? Thanks

Term for the tree of all paths starting from a given vertex in a graph

What is the term for the tree (or a part of the tree) of all possible paths in a graph that start from a given (source) vertex?

This is the tree that is implicitly or explicitly constructed when doing shortest path search. It appears, for example, in a lecture on search of an MIT Artificial Intelligence course, but I didn’t understand if it has a name.

This is not a search tree and not really a decision tree.

Mathematically, it is a covering tree, but is there a more appropriate term in the context of shortest path search?