SHARE
TWEET

Untitled

a guest Oct 12th, 2017 41 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. use v6;
  2.  
  3. my @a = 10, 5, 7, 6, 1;
  4. # my @a = 10;
  5. # my @a = [];
  6.  
  7. # First approach
  8.  
  9. my @result;
  10. for @a.reverse.rotor(2 => -1) -> ($a, $b) {
  11.     FIRST @result.push($a);
  12.     state $drop = 0;
  13.     $drop += ($b + 1 - $a) max 0;
  14.     @result.push($b - $drop);
  15. };
  16. say @result ?? @result.reverse !! @a.List;
  17.  
  18. # Second approach
  19.  
  20. my @diffs = [\+] @a.reverse.rotor(2 => -1).map: -> ($a, $b) { ($b + 1 - $a) max 0 };
  21. say !@diffs ?? @a.List !! (@a.reverse Z- (0, |@diffs)).reverse;
RAW Paste Data
Top