Skip to main content
1 of 3
xash
  • 11.3k
  • 1
  • 14
  • 39

J, 46 bytes

Takes input as k on the left side and n, luck on the right side.

[:(+/%#){:@]+/@}.&|:[:>:@/:~"1[#.inv(i.@^+&|/)

How it works

[:(+/%#){:@]+/@}.&|:[:>:@/:~"1[#.inv(i.@^+&|/)
                                     i.@^+&|/ 0..k^(|n| + |luck|)
                              [#.inv          to base k 0 0 0..5 5 5
                         /:~"1                sort each roll
                      >:                      0 0 0 -> 1 1 1
        {:@]   }.&|:                          transpose and drop luck rows
                                              negative values drop from end
            +/                                sum each roll
  (+/%#)                                      average of all rolls                   
           

Try it online!

xash
  • 11.3k
  • 1
  • 14
  • 39