titer10.nim 940 B

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. discard """
  2. output: '''3
  3. 2
  4. 5
  5. 1
  6. @[@[0, 0], @[0, 1]]
  7. @[@[0, 0], @[0, 1]]
  8. @[@[2, 2], @[2, 3]]
  9. @[@[2, 2], @[2, 3]]'''
  10. """
  11. when true:
  12. # bug #2604
  13. import algorithm
  14. iterator byDistance*[int]( ints: openArray[int], base: int ): int =
  15. var sortable = @ints
  16. sortable.sort do (a, b: int) -> int:
  17. result = cmp( abs(base - a), abs(base - b) )
  18. for val in sortable:
  19. yield val
  20. when true:
  21. proc main =
  22. for val in byDistance([2, 3, 5, 1], 3):
  23. echo val
  24. main()
  25. when true:
  26. # bug #1527
  27. import sequtils
  28. let thread = @[@[0, 0],
  29. @[0, 1],
  30. @[2, 2],
  31. @[2, 3]]
  32. iterator threadUniqs(seq1: seq[seq[int]]): seq[seq[int]] =
  33. for i in 0 ..< seq1.len:
  34. block:
  35. let i = i
  36. yield seq1.filter do (x: seq[int]) -> bool: x[0] == seq1[i][0]
  37. proc main2 =
  38. for uniqs in thread.threadUniqs:
  39. echo uniqs
  40. main2()