Skip to main content
1 of 3
jayprich
  • 421
  • 2
  • 8

J, 40 bytes

output is from evaluating this expression, e.g in a repl

u:30+2>.(+:@i.@(2&+)(-*(>+:))"0 _|@i:)47

TIO

thanks to +Galen Ivanov & +Conor O'Brien for the ideas in their solutions

jayprich
  • 421
  • 2
  • 8