shortest

Finding the shortest string in a string of words in python

自闭症网瘾萝莉.ら 提交于 2019-12-02 08:27:23
I want to write a function that would return the length of the shortest string in a string of words. Sample: "I eat apples" would return 1 since "I" is the shorted string. This is what I did but mincount does neither increment nor set up to 0 at the end of each string. What is wrong with it? def find_short(s): min=99 for i in s: mincount = 0 for j in i: print(j) mincount += 1 print(mincount) if (mincount < min): min = mincount return min line = "I eat apples" mins = min(len(word) for word in line.split()) print(mins) line.split() will split line into list of words and then just finding the

Shortest path in matrix with obstacles with cheat paths

馋奶兔 提交于 2019-12-02 08:08:03
问题 First of all this is an assingment and I am not looking for direct answers but instead the complexity of the best solution as you might be thinking it . This is the known problem of shortest path between 2 points in a matrix (Start and End) while having obstacles in the way. Moves acceptables is up,down,left and right . Lets say when moving i carry sth and the cost of each movement is 2 . There are points in the matrix (lets name them B points) where I can leave this sth in one B point and

Shortest path in matrix with obstacles with cheat paths

被刻印的时光 ゝ 提交于 2019-12-02 05:46:39
First of all this is an assingment and I am not looking for direct answers but instead the complexity of the best solution as you might be thinking it . This is the known problem of shortest path between 2 points in a matrix (Start and End) while having obstacles in the way. Moves acceptables is up,down,left and right . Lets say when moving i carry sth and the cost of each movement is 2 . There are points in the matrix (lets name them B points) where I can leave this sth in one B point and pick it up from another B point . Cost of dumping sth in B point is 1 and cost of picking sth up from a B

C# finding the shortest and longest word in a array

本小妞迷上赌 提交于 2019-12-01 12:23:52
I am trying to find the shortest and longest string value based on length and im getting stuck. As of now the script exits after the writeline. I think the code needs some help, I dont think a for loop can work on its own. Any assistance would be appreciated. for (int i = 5; i <0; i++) { string[] word = new string[5]; Console.WriteLine("Type in a word"); word[i] = Console.ReadLine(); int length = word[i].Length; int min = word[0].Length; int max = word[0].Length; string maxx; string minn; if (length > max) { maxx = word[i]; Console.Write("Shortest"); } if (length < min) { minn = word[i];

C# finding the shortest and longest word in a array

房东的猫 提交于 2019-12-01 10:20:58
问题 I am trying to find the shortest and longest string value based on length and im getting stuck. As of now the script exits after the writeline. I think the code needs some help, I dont think a for loop can work on its own. Any assistance would be appreciated. for (int i = 5; i <0; i++) { string[] word = new string[5]; Console.WriteLine("Type in a word"); word[i] = Console.ReadLine(); int length = word[i].Length; int min = word[0].Length; int max = word[0].Length; string maxx; string minn; if

Java - Find shortest path between 2 points in a distance weighted map

喜夏-厌秋 提交于 2019-11-27 17:32:50
I need an algorithm to find shortest path between two points in a map where road distance is indicated by a number. what is given: Start City A Destination City Z List of Distances between Cities: A - B : 10 F - K : 23 R - M : 8 K - O : 40 Z - P : 18 J - K : 25 D - B : 11 M - A : 8 P - R : 15 I thought I could use Dijkstra's algorithm , however it finds shortest distance to all destinations. not just one. Any suggestion is appreciated. luke Like SplinterReality said: There's no reason not to use Dijkstra's algorithm here. The code below I nicked from here and modified it to solve the example

Java - Find shortest path between 2 points in a distance weighted map

时光总嘲笑我的痴心妄想 提交于 2019-11-26 19:04:02
问题 I need an algorithm to find shortest path between two points in a map where road distance is indicated by a number. what is given: Start City A Destination City Z List of Distances between Cities: A - B : 10 F - K : 23 R - M : 8 K - O : 40 Z - P : 18 J - K : 25 D - B : 11 M - A : 8 P - R : 15 I thought I could use Dijkstra's algorithm , however it finds shortest distance to all destinations. not just one. Any suggestion is appreciated. 回答1: Like SplinterReality said: There's no reason not to