You love the convinience of google photos but wondering how to use this free unlimited hosting to display images on you own web resources or maybe on livejournal?
I found a pretty easy straitforward solution for that:
Open the photo you need to embed on photos.google.com
Right click on it (context menu) and hit “inspect element”
Copy the line with the src=”…” - it containts the link to the physical addres of where Google stores this photo.
Now just use this src link on your web resource with the img html tag.
Profit!
Here is the screenshoot with what you need to find:
When I was asked to make a program for solving a maze during the job interview for some reason I simply attempted to model a known human-friendly heuristics: follow the right wall. The resulting code was very long and somewhat hard although worked alright.
Now, during the algorithms class and review of DFS I decided to try the recursive approach for solving the maze.
For starters let us create one:
1
2
3
4
5
6
7
8
9
10
11
12
# 0 clear
# 1 wall
# 2 was here
# 8 start
# 9 finish
maze=[[0,0,1,0,1],[0,1,0,0,0],[0,1,0,1,0],[0,0,0,1,0],[1,1,1,0,9]]
Alternatively, we can feed the following txt file:
Finally, the recursive function. The idea is simple: try to go in every direction recursively and if no wall, no out of bounds and was not here before - move on!
defmove(x,y):globalFoundWayOutifFoundWayOut:returnprinttabulate(maze)if(x<0orx>width-1ory<0ory>height-1):print'Out of bounds';returnif(maze[x][y]==9):FoundWayOut=Trueprint'Got it!';returnif(maze[x][y]==1):print'That is wall';returnif(maze[x][y]==2):print'Was here before';returnmaze[x][y]=2move(x+1,y)# East
move(x,y+1)# South
move(x-1,y)# West
move(x,y-1)# North
Now we can find the way out of the maze (if there is a way out):
1
2
3
move(0,0)ifnotFoundWayOut:print'There is no way out of this!'
First call should be made from the start position.
Overall, recursive solution is way more elegant and easier to grasp as well as to implement.
Bellman-Ford algorithm is easy and sufficiently efficient (E*V for straight forward implementation) for finding Shortest Paths (SP). Notably, it finds the shortests paths to ALL the other nodes in the graph.
The idea is simple: for each vertex we mantain the SP (init with inf) and if the precedent vertex + edge weight gives us better sum - then we update current SP value for that vertex.
Caveat: this algorithm fails if graph contains negative cycles since in that case one can obtain arbitrary small (negative) shortest path just by traversing this negative cycle over and over again.
We have tree pegs with the discs on top of one another with decreasing size. Task is to move all disks from one peg to another while moving only one disk pertime and keeping smaller disks on biggers.
Recursive alg with the following idea: if we want to move 8 disks from peg1 to peg2, then we need to move 7 upper disks to the work peg first, then mode last to peg2 and then put 7 disks on top. Fist and last step is just an instance of Hanoi Tower problem once again, so we recursively call the function. Stopping condintion is if we want to move one disk only - then we just move.
N_disks=8basicOperationCounter=0tower1=[N_disks-iforiinxrange(N_disks)]tower2=[]tower3=[]defprintTowers():printtower1printtower2printtower3print'-------------------'defmoveDisk(out,to):disk=out[-1]# top element
out.remove(disk)to.append(disk)globalbasicOperationCounterbasicOperationCounter+=1printTowers()defmove(n,out,to,work):ifn>1:move(n-1,out,work,to)moveDisk(out,to)ifn>1:move(n-1,work,to,out)printTowers()move(N_disks,tower1,tower2,tower3)print'Move completed in %s steps. Theoretical bound is 2^n-1 = % s'%(basicOperationCounter,2**N_disks-1)
Really nice way to check a potential candidate problem-solving skills is to test him as a mouse.
How to find the way out of the maze? Programmically, of course.
From life experience we know, that the simpliest way to get out is to follow the right side
and eventually we will find the exit.
importjava.io.BufferedReader;importjava.io.FileNotFoundException;importjava.io.FileReader;importjava.util.ArrayList;importjava.util.HashMap;importjava.util.Scanner;classcoord{publicinti;publicintj;publiccoord(inti,intj){this.i=i;this.j=j;}}//Directions: 1 - right, 2 - up, 3 - left, 4 - downpublicclassMaze_solver{staticStringmaze_filename="maze.txt";staticStringroute="";staticintlast_move_direction=2;//guess first directionstaticint[]directions=newint[]{4,1,2,3,4,1,2,3,4};staticbooleanfoundWayOut=false;@SuppressWarnings("serial")staticHashMap<Integer,Character>direction_letters=newHashMap<Integer,Character>();publicstaticvoidmain(String[]args)throwsFileNotFoundException{initDirectionLetters()char[][]maze=readMaze(maze_filename);printMaze(maze);getOut(maze);}privatevoidinitDirectionLetters(){direction_letters.put(1,'r');direction_letters.put(2,'u');direction_letters.put(3,'l');direction_letters.put(4,'d');}privatestaticchar[][]readMaze(Stringfilename)throwsFileNotFoundException{Scannersc=newScanner(newBufferedReader(newFileReader(filename)));ArrayList<String>input=newArrayList<String>();while(sc.hasNext())input.add(sc.nextLine());sc.close();intwidth=input.get(0).length();intheight=input.size();char[][]maze=newchar[height][width];for(intj=0;j<height;j++){Stringline=input.get(j);for(inti=0;i<width;i++){maze[j][i]=line.charAt(i);}}returnmaze;}privatestaticvoidprintMaze(char[][]maze){for(inti=0;i<maze.length;i++){for(intj=0;j<maze[0].length;j++){System.out.print((char)maze[i][j]);System.out.print(" ");}System.out.println();}}privatestaticvoidgetOut(char[][]maze){coordcoord=findStart(maze);while(!foundWayOut){coord=makeMove(maze,coord);printMaze(maze);}System.out.println(route);}staticcoordmove(coordcoord,intdirection){coordnew_coord=newcoord(coord.i,coord.j);switch(direction){case1:new_coord.j++;break;case2:new_coord.i--;break;case3:new_coord.j--;break;case4:new_coord.i++;break;}returnnew_coord;}staticbooleancheckIfGoodState(char[][]maze,coordcoord){if(maze[coord.i][coord.j]=='F')foundWayOut=true;return(maze[coord.i][coord.j]==' ')?true:false;}staticcoordmakeMove(char[][]maze,coordcoord){//try to do moves according to priority and break coordnew_coord=null;for(inti=last_move_direction-1;i<=last_move_direction+3;i++){new_coord=move(coord,directions[i]);if(checkIfGoodState(maze,new_coord)){last_move_direction=directions[i];route+=direction_letters.get(directions[i]);maze[new_coord.i][new_coord.j]='S';maze[coord.i][coord.j]=' ';returnnew_coord;}}returnnull;//shouldnt happen by assumption}staticcoordfindStart(char[][]maze){coordcoord=newcoord(0,0);for(inti=0;i<maze.length;i++){for(intj=0;j<maze[1].length;j++){if(maze[i][j]=='S'){coord.i=i;coord.j=j;break;}}}returncoord;}}