caubert

random_request

Nov 14th, 2020 (edited)
68
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. {{ $slice := cslice 0 1 2 3 4 5 6 7 8 9 }} {{ $x := randInt (len $slice) }}
  2. for {{ $x }}
  3. oneWay > {{ template "nonsense" (sdict "x" $x "slice" $slice) }}
  4. {{- define "nonsense" }}
  5.     {{- $new_slice := cslice }}
  6.     {{- if eq .x 0 }}
  7.         {{- ($z := $new_slice.AppendSlice (slice .slice (add .x 1) (len .slice) ) ) | len }} {{ $z }}      
  8.     {{- else if eq .x (sub (len .slice) 1) }}
  9.         {{- ($z := $new_slice.AppendSlice (slice .slice 0 (sub (len .slice) 1) ) ) | len }} {{ $z }}
  10.     {{- else }}
  11.         {{- ($z := ( ($new_slice.AppendSlice (slice .slice 0 .x) ).AppendSlice (slice .slice (add .x 1) (len .slice) ) ) ) | len  }} {{ $z }}
  12.     {{- end }}
  13. {{- end }}
  14. otherWay > {{ $compactSlice := $slice.Del $x true -}} {{ len $slice }} {{ $slice }}
  15. {{ len $compactSlice }} {{ $compactSlice }}
  16.  
RAW Paste Data