Skip to main content
new explanation for Bubbler's changes
Source Link
chunes
  • 27.8k
  • 3
  • 32
  • 55

Factor + math.unicode, 3535 24 bytes

[ [1,b] swap '[ _0 ^rot -1 ^ ] mapv^n Σ ] 

Try it online!Try it online!

-11 thanks to @Bubbler!

Explanation:

It's a quotation (anonymous function) that takes two integers from the data stack (in m, n order) as input and leaves a fully-reduced mixed fraction (it's simply the way that Factor is) on the data stack as output.

  • [1,b] swap Make a range from 1 to n and bring m to the top of the stack.
  • '[ _ ^ -1 ^0 ]rot Push a quotation to the stack for map0 to use later.and bring '[ _m says to slot whatever is onthe top of the data stack.
  • - Subtract (m) into the from _0.
  • map Apply a quotation to each element of a sequence, mapping the results into a sequence of the same size.
  • ^v^n Raise a sequenceevery element in the range to the -m power.
  • -1 ^ Take the reciprocal. This is shorter than recip and 1 swap /.
  • Σ Sum.

Factor + math.unicode, 35 bytes

[ [1,b] swap '[ _ ^ -1 ^ ] map Σ ] 

Try it online!

Explanation:

It's a quotation (anonymous function) that takes two integers from the data stack (in m, n order) as input and leaves a fully-reduced mixed fraction (it's simply the way that Factor is) on the data stack as output.

  • [1,b] swap Make a range from 1 to n and bring m to the top of the stack.
  • '[ _ ^ -1 ^ ] Push a quotation to the stack for map to use later. '[ _ says to slot whatever is on top of the data stack (m) into the _.
  • map Apply a quotation to each element of a sequence, mapping the results into a sequence of the same size.
  • ^ Raise a sequence element to the m power.
  • -1 ^ Take the reciprocal. This is shorter than recip and 1 swap /.
  • Σ Sum.

Factor + math.unicode, 35 24 bytes

[ [1,b] 0 rot - v^n Σ ] 

Try it online!

-11 thanks to @Bubbler!

Explanation:

It's a quotation (anonymous function) that takes two integers from the data stack as input and leaves a fully-reduced mixed fraction (it's simply the way that Factor is) on the data stack as output.

  • [1,b] Make a range from 1 to n.
  • 0 rot Push 0 and bring m to the top of the stack.
  • - Subtract m from 0.
  • v^n Raise every element in the range to the -m power.
  • Σ Sum.
Source Link
chunes
  • 27.8k
  • 3
  • 32
  • 55

Factor + math.unicode, 35 bytes

[ [1,b] swap '[ _ ^ -1 ^ ] map Σ ] 

Try it online!

Explanation:

It's a quotation (anonymous function) that takes two integers from the data stack (in m, n order) as input and leaves a fully-reduced mixed fraction (it's simply the way that Factor is) on the data stack as output.

  • [1,b] swap Make a range from 1 to n and bring m to the top of the stack.
  • '[ _ ^ -1 ^ ] Push a quotation to the stack for map to use later. '[ _ says to slot whatever is on top of the data stack (m) into the _.
  • map Apply a quotation to each element of a sequence, mapping the results into a sequence of the same size.
  • ^ Raise a sequence element to the m power.
  • -1 ^ Take the reciprocal. This is shorter than recip and 1 swap /.
  • Σ Sum.