fork download
  1. module main;
  2.  
  3. import std.algorithm;
  4. import std.functional;
  5. import std.range;
  6. import std.stdio;
  7. import std.string;
  8. import std.typecons;
  9.  
  10. void main(){
  11. invFizzBuzz;
  12. }
  13.  
  14. auto invFizzBuzz(){
  15. return stdin.byLine.map!(a => a.split)
  16. .map!(ln =>
  17. (a => (a > 6) ? [] : ((b, s) =>
  18. (c =>
  19. (c.popFrontN(b), c)
  20. )
  21. (
  22. recurrence!"a[n-1] + 1"(1)
  23. .map!(c => tuple(c, (!(c % 3) ? "fizz" : "") ~ (!(c % 5) ? "buzz" : "")))
  24. .filter!"a[1].length"
  25. )
  26. .take(s)
  27. .map!"a[0]"
  28. .array
  29. )(a, ln.length)
  30. )
  31. (
  32. iota(0, 7)
  33. .map!(a =>
  34. tuple(
  35. iota(1, 16).map!q{(!(a % 3) ? "fizz" : "") ~ (!(a % 5) ? "buzz" : "")}
  36. .array
  37. .cycle
  38. .zip(recurrence!"a[n-1] + 1"(1))
  39. .filter!"a[0].length",
  40. a
  41. )
  42. )
  43. .map!(a => (a[0].popFrontN(a[1]), a))
  44. .map!(a =>
  45. tuple(
  46. a[0].zip(ln).map!"a[0][0] == a[1]".reduce!"a && b",
  47. a[1],
  48. a[0].front[1],
  49. a[0].take(ln.length).curry!(reduce!"max(a, b[1])", 0)
  50. )
  51. )
  52. .chain([tuple(true, 7, 0, 0)])
  53. .filter!"a[0]"
  54. .reduce!((a, b) => (a[3] - a[2]) <= (b[3] - b[2]) ? a : (b[1] == 7 ? a : b))[1]
  55. )
  56. )
  57. .map!(a => a.empty ? iota(0, 0) : iota(a[0], a[$-1] + 1))
  58. .map!(a => (a.writeln, 0)).reduce!"a + b";
  59. }
  60.  
Not running #stdin #stdout 0s 0KB
stdin
Standard input is empty
stdout
Standard output is empty