fork download
  1. import std.stdio;
  2. import std.conv: to;
  3. import std.string: isNumeric;
  4. import std.range: iota, generate, repeat, take, enumerate;
  5. import std.algorithm.iteration: map, each, reduce, joiner;
  6. import std.typecons: Tuple;
  7. import std.array: array;
  8. import std.random: uniform01, uniform;
  9. import std.format: format;
  10. import std.math: sqrt;
  11.  
  12. import std.algorithm.sorting: sort;
  13. import std.algorithm.searching: find;
  14.  
  15. struct Point
  16. {
  17. double x;
  18. double y;
  19. }
  20.  
  21. void main(string[] args)
  22. {
  23. if ((args[1..$].length != 1) || !args[1].isNumeric) {
  24. writeln("usage: ./dots N");
  25. return;
  26. }
  27.  
  28. uint n;
  29. try {
  30. n = args[1].to!uint;
  31. if (n<2) throw new Exception("N is less than two");
  32. }
  33. catch (Exception e) {
  34. writeln("N must be an integer, more than 1");
  35. }
  36.  
  37. Point[] points = new Point[n];
  38. foreach (ref pt; points){
  39. pt.x = uniform01();
  40. pt.y = uniform01();
  41. }
  42.  
  43. double minLen = double.infinity;
  44. Point p1, p2;
  45.  
  46.  
  47. foreach (i, pt1; points[0..$-1]){
  48. foreach (j, pt2; points[i+1..$]){
  49. double len = sqrt((pt2.x - pt1.x)^^2 + (pt2.y - pt1.y)^^2);
  50.  
  51. if (len < minLen){
  52. minLen = len;
  53. p1 = pt1;
  54. p2 = pt2;
  55. }
  56. }
  57. }
  58. points.each!(pt => writefln("%s%s", pt, (p1 is pt) || (p2 is pt) ? " *" : "" ));
  59. }
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
Standard input is empty
compilation info
prog.d(5): Error: module iteration is in file 'std/algorithm/iteration.d' which cannot be read
import path[0] = /usr/include/d/ldc
import path[1] = /usr/include/d
stdout
Standard output is empty