2 added 88 characters in body
source | link

Multiplivision

Hopefully a nice simple challenge that's not trivial.

Given an input list of positive integers, alternately multiply and divide them to yield a single numerical answer, according to the following rules:

  • start with the first number;
  • with the remaining numbers, alternate between dividing and multiplying, one at a time (that is, in a left-associative way), with the last operation being multiplication

For example, the input {3, 4, 2, 7} would start with 3, then successively compute 3 * 4 = 12, then 12 / 2 = 6, then 6 * 7 = 42 and output 42. (In other words, the input {3, 4, 2, 7} yields the output (((3 * 4) / 2) * 7) = 42.) The first operation had to be a multiplication, because if we'd started with a division, then the last operation would have been division as well, which isn't right.

If the answer is not an integer, then it can be output either as an exact fraction, or as a decimal equivalent, accurate to at least 6 significant figures (including decimals that terminate before the 6th significant figure). Eithereither truncating or rounding the end of the decimal is fine). For decimals that terminate before 6 significant figures, either the terminating decimal alone (1.5) or a version with trailing zeros (1.50000) is fine.

Other test cases (only the numerical answer needs to be output, not the intermediate parsed expression):

{3} -> 3
{3, 4} -> 3 * 4 = 12
{3, 4, 2} -> 3 / 4 * 2 = 3/2 or 1.5
{5, 4, 3, 2} -> 5 * 4 / 3 * 2 = 40/3 or 13.3333
{1, 2, 3, 4, 5, 6, 7, 8} -> 1 * 2 / 3 * 4 / 5 * 6 / 7 * 8 = 128/35 or 3.65714
{42, 42, 42, 42, 42, 42} -> 42 * 42 / 42 * 42 / 42 * 42 = 1764
{42, 42, 42, 42, 42, 42, 42} -> 42 / 42 * 42 / 42 * 42 / 42 * 42 = 42

This is , so the shortest code in bytes wins! Golfed answers in all languages are welcome.

Multiplivision

Hopefully a nice simple challenge that's not trivial.

Given an input list of positive integers, alternately multiply and divide them to yield a single numerical answer, according to the following rules:

  • start with the first number;
  • with the remaining numbers, alternate between dividing and multiplying, one at a time (that is, in a left-associative way), with the last operation being multiplication

For example, the input {3, 4, 2, 7} would start with 3, then successively compute 3 * 4 = 12, then 12 / 2 = 6, then 6 * 7 = 42 and output 42. (In other words, the input {3, 4, 2, 7} yields the output (((3 * 4) / 2) * 7) = 42.) The first operation had to be a multiplication, because if we'd started with a division, then the last operation would have been division as well, which isn't right.

If the answer is not an integer, then it can be output either as an exact fraction, or as a decimal equivalent, accurate to at least 6 significant figures (including decimals that terminate before the 6th significant figure). Either truncating or rounding the end of the decimal is fine.

Other test cases (only the numerical answer needs to be output, not the intermediate parsed expression):

{3} -> 3
{3, 4} -> 3 * 4 = 12
{3, 4, 2} -> 3 / 4 * 2 = 3/2 or 1.5
{5, 4, 3, 2} -> 5 * 4 / 3 * 2 = 40/3 or 13.3333
{1, 2, 3, 4, 5, 6, 7, 8} -> 1 * 2 / 3 * 4 / 5 * 6 / 7 * 8 = 128/35 or 3.65714
{42, 42, 42, 42, 42, 42} -> 42 * 42 / 42 * 42 / 42 * 42 = 1764
{42, 42, 42, 42, 42, 42, 42} -> 42 / 42 * 42 / 42 * 42 / 42 * 42 = 42

This is , so the shortest code in bytes wins! Golfed answers in all languages are welcome.

Multiplivision

Hopefully a nice simple challenge that's not trivial.

Given an input list of positive integers, alternately multiply and divide them to yield a single numerical answer, according to the following rules:

  • start with the first number;
  • with the remaining numbers, alternate between dividing and multiplying, one at a time (that is, in a left-associative way), with the last operation being multiplication

For example, the input {3, 4, 2, 7} would start with 3, then successively compute 3 * 4 = 12, then 12 / 2 = 6, then 6 * 7 = 42 and output 42. (In other words, the input {3, 4, 2, 7} yields the output (((3 * 4) / 2) * 7) = 42.) The first operation had to be a multiplication, because if we'd started with a division, then the last operation would have been division as well, which isn't right.

If the answer is not an integer, then it can be output either as an exact fraction, or as a decimal equivalent, accurate to at least 6 significant figures (either truncating or rounding the end of the decimal is fine). For decimals that terminate before 6 significant figures, either the terminating decimal alone (1.5) or a version with trailing zeros (1.50000) is fine.

Other test cases (only the numerical answer needs to be output, not the intermediate parsed expression):

{3} -> 3
{3, 4} -> 3 * 4 = 12
{3, 4, 2} -> 3 / 4 * 2 = 3/2 or 1.5
{5, 4, 3, 2} -> 5 * 4 / 3 * 2 = 40/3 or 13.3333
{1, 2, 3, 4, 5, 6, 7, 8} -> 1 * 2 / 3 * 4 / 5 * 6 / 7 * 8 = 128/35 or 3.65714
{42, 42, 42, 42, 42, 42} -> 42 * 42 / 42 * 42 / 42 * 42 = 1764
{42, 42, 42, 42, 42, 42, 42} -> 42 / 42 * 42 / 42 * 42 / 42 * 42 = 42

This is , so the shortest code in bytes wins! Golfed answers in all languages are welcome.

1
source | link

Multiplivision

Hopefully a nice simple challenge that's not trivial.

Given an input list of positive integers, alternately multiply and divide them to yield a single numerical answer, according to the following rules:

  • start with the first number;
  • with the remaining numbers, alternate between dividing and multiplying, one at a time (that is, in a left-associative way), with the last operation being multiplication

For example, the input {3, 4, 2, 7} would start with 3, then successively compute 3 * 4 = 12, then 12 / 2 = 6, then 6 * 7 = 42 and output 42. (In other words, the input {3, 4, 2, 7} yields the output (((3 * 4) / 2) * 7) = 42.) The first operation had to be a multiplication, because if we'd started with a division, then the last operation would have been division as well, which isn't right.

If the answer is not an integer, then it can be output either as an exact fraction, or as a decimal equivalent, accurate to at least 6 significant figures (including decimals that terminate before the 6th significant figure). Either truncating or rounding the end of the decimal is fine.

Other test cases (only the numerical answer needs to be output, not the intermediate parsed expression):

{3} -> 3
{3, 4} -> 3 * 4 = 12
{3, 4, 2} -> 3 / 4 * 2 = 3/2 or 1.5
{5, 4, 3, 2} -> 5 * 4 / 3 * 2 = 40/3 or 13.3333
{1, 2, 3, 4, 5, 6, 7, 8} -> 1 * 2 / 3 * 4 / 5 * 6 / 7 * 8 = 128/35 or 3.65714
{42, 42, 42, 42, 42, 42} -> 42 * 42 / 42 * 42 / 42 * 42 = 1764
{42, 42, 42, 42, 42, 42, 42} -> 42 / 42 * 42 / 42 * 42 / 42 * 42 = 42

This is , so the shortest code in bytes wins! Golfed answers in all languages are welcome.