fork download
  1. # Haskellwhores sosnooley.
  2. # No need to handle special cases like 'Nothing'.
  3. inf = float('inf')
  4.  
  5.  
  6. def yoba(map, start, end):
  7. # Haskellwhores sosnooley again.
  8. # 'bounds'? Hah.
  9. w = len(map)
  10. h = w and len(map[0])
  11. # And again. This lambda was borrowed from the Reifag's code.
  12. value = lambda x, y: 0 if y == start \
  13. else inf if not x \
  14. else min(arr[x - 1][n] + map[n][y] for n in range(h))
  15.  
  16. # Pythonwhores sosnooley.
  17. # Much more readable variant:
  18. # arr = [[value(x, y) for y in range(h)] for x in range(w)]
  19. # Unfortunately, it does not work because value() tries to access
  20. # the arr list.
  21. arr = []
  22. for x in range(w): arr.append([value(x, y) for y in range(h)])
  23. return min(arr[x][end] for x in range(w))
  24.  
  25. rank = 10 ** 10000
  26.  
  27. if __name__ == '__main__':
  28. # Haskellwhores sosnooley again.
  29. toArray2D = lambda arr: list(zip(*arr))
  30. graph = [[inf, 7 * rank, 9 * rank, inf, inf, 14 * rank],
  31. [ 7 * rank, inf, 10 * rank, 15 * rank, inf, inf],
  32. [ 9 * rank, 10 * rank, inf, 11 * rank, inf, 2 * rank],
  33. [inf, 15 * rank, 11 * rank, inf, 6 * rank, inf],
  34. [inf, inf, inf, 6 * rank, inf, 9 * rank],
  35. [ 14 * rank, inf, 2 * rank, inf, 9 * rank, inf]]
  36. print(yoba(toArray2D(graph), 0, 4))
  37.  
Success #stdin #stdout 0.02s 5868KB
stdin
Standard input is empty
stdout
Standard output is empty