10
$\begingroup$

Using the same rules as Make 6 5 4 3 = 1, but maximize the number of factorials. You may not take the factorial of 1 or 2.

This is harder than it looks. A great answer has six factorials, an amazing answer has seven factorials, and an outstanding answer has eight or more factorials.

Edit: Shoot, I should have blocked factorials of numbers bigger than twenty like I did in my program.

$\endgroup$
12
  • $\begingroup$ I'm guessing we shouldn't take the factorial of 2 either $\endgroup$ Aug 28, 2018 at 14:11
  • $\begingroup$ Is the answer really different than wolfram42's answer to the other puzzle? (3 factorials) $\endgroup$
    – xhienne
    Aug 28, 2018 at 14:17
  • $\begingroup$ @xhienne That was my opinion but if he found 8 that is probably precise enough for another question. $\endgroup$
    – Saeïdryl
    Aug 28, 2018 at 14:18
  • $\begingroup$ @xhienne I found a solution with eight factorials. There are 72 solutions with four or more factorials. $\endgroup$
    – Neil G
    Aug 28, 2018 at 14:19
  • 1
    $\begingroup$ @Saeïdryl I understand that you can not use (6 - 5)! nor (6 - 4)! $\endgroup$
    – xhienne
    Aug 28, 2018 at 14:21

6 Answers 6

10
$\begingroup$

I'll attempt with the rule "No factorials on numbers greater than 20". Here is a solution with 7. Some formatting help is appreciated

$$\frac{6!}{(5!\div4!)!}! \div 3!!$$

Method:

I started with the observation that 6! / 5! = 6, Likewise 5!/4! = 5. 3! = 6 so 6! = 3!! I then built up from there. So 6! = (6!/(5! / 4!))!

Figured out the missing factorial:

$$\left(\frac{6!}{(5!\div4!)!}! - 3!!\right)!$$ works since 0! = 1 by definition.

$\endgroup$
7
  • $\begingroup$ Missing one pair of parentheses I think, but yes amazing! How did you do it? $\endgroup$
    – Neil G
    Aug 28, 2018 at 16:44
  • $\begingroup$ Actually i made a quick edit and I confused myself. I'll readjust in a minute $\endgroup$
    – wolfram42
    Aug 28, 2018 at 16:46
  • $\begingroup$ Nice, you're pretty close to 8 $\endgroup$
    – Neil G
    Aug 28, 2018 at 16:57
  • 3
    $\begingroup$ Presumably by $n!!$ you mean $(n!)!$, not the double factorial operation $\prod_{k \in \mathbb N, n - 2 k > 0} (n - 2 k)$? $\endgroup$
    – wchargin
    Aug 28, 2018 at 22:44
  • 1
    $\begingroup$ I assumed that the double factorial operation was not allowed since it would be easy to get more than 8 that way. $\endgroup$
    – wolfram42
    Aug 29, 2018 at 14:07
43
$\begingroup$

The answer is

Infinite factorials even without factorials of 1 or 2. By this equation $$6!!!\ldots * (5-4) \div 3!!!!\ldots = 1$$ Notice that the 3 has one more factorial. This comes from the fact that $3!=6$ and we can keep adding factorials to both.

$\endgroup$
4
  • $\begingroup$ Wow, that's brilliant $\endgroup$
    – Neil G
    Aug 28, 2018 at 14:28
  • 1
    $\begingroup$ (I know this is the best answer, but I hope you don't mind that I marked the other answer as accepted since it was the one I was shooting for.) $\endgroup$
    – Neil G
    Aug 28, 2018 at 16:46
  • 7
    $\begingroup$ @NeilG Unless this was secretly a riddle, you should accept the best possible answer. It turns out that one of the responders was more clever than you - reward that! $\endgroup$ Aug 29, 2018 at 12:16
  • $\begingroup$ @jeremy well I upvoted him ? $\endgroup$
    – Neil G
    Aug 29, 2018 at 12:24
12
$\begingroup$

How about

Infinitely many factorials?
A basic example would be : $\frac{6 * (5-4)}{ 3!} = 1$
But you could add some factorials in the lot : $\frac{6! * (5-4) }{ 3!!} = 1 $ Or even : $\frac{6!!!!!!!\times (5-4) }{ (3!)!!!!!!!} = 1 $ Really, as long as there is one more factorial behind the 3, we're good!

$\endgroup$
2
  • 2
    $\begingroup$ Damn you, @Bennett Bernardoni ! :p $\endgroup$
    – Keelhaul
    Aug 28, 2018 at 14:29
  • 1
    $\begingroup$ Great answer! And congratz on the $7k$ rep! :D $\endgroup$
    – Mr Pie
    Aug 29, 2018 at 22:01
6
$\begingroup$

Starting from wolfram42's answer to that other puzzle, the maximum number of factorials is:

infinite since you can add any equal number of ! to the numerator and denominator of
(6!) / (5 * 4! * 3!)
Well, since I'm no mathematician, I may say "infinite plus three" actually ;-)

Note: that's also true for any answer to the other puzzle that involved a division, like JonMark Perry's two solutions

$\endgroup$
2
$\begingroup$

Here's the general programming solution to these kinds of problems. It also prints out for every result, how many solutions there are, which is useful in coming up with these kinds of problem:

from enum import IntEnum
from fractions import Fraction
from memoized import memoized
import math


NUMBERS = [6, 5, 4, 3]
RESULT = Fraction(1)


class Levels(IntEnum):
    ADDITION = 0
    MULTIPLICATION = 1
    NEGATION = 2
    POWER = 3
    FACTORIAL = 4
    BARE = 5


class Result:

    def __init__(self, value, way, level):
        """
        * value is the value achieved.
        * way is string representation of an expression.
        * level is the outermost operator applied to the expression, which
          determines how this expression should be braketed when it's part of a
          larger expression.
        """
        assert isinstance(value, Fraction)
        assert isinstance(level, Levels)
        self.value = value
        self.way = way
        self.level = level

    def bracketed(self, for_level):
        if for_level > self.level:
            return f"({self.way})"
        return self.way


def combine(left_rs, right_rs):
    for l in left_rs:
        for r in right_rs:
            if r.level not in (Levels.NEGATION, Levels.ADDITION):
                # We block a - (-b), and a + (-b) since these can be written as
                # a + b, and a - b.  We also block a + (b + c), and a - (b + c)
                # since these can be written as a + b + c, and a - b - c.
                yield Result(l.value + r.value,
                             f"{l.bracketed(Levels.ADDITION)} + {r.bracketed(Levels.ADDITION + 1)}",
                             Levels.ADDITION)
                yield Result(l.value - r.value,
                             f"{l.bracketed(Levels.ADDITION)} - {r.bracketed(Levels.ADDITION + 1)}",
                             Levels.ADDITION)
            if r.level != Levels.MULTIPLICATION:
                # We block a * (b * c) since this can be written as a * b * c.
                # We block a * (b / c) since this can be written as a * b / c.
                yield Result(l.value * r.value,
                             f"{l.bracketed(Levels.MULTIPLICATION)} * {r.bracketed(Levels.MULTIPLICATION + 1)}",
                             Levels.MULTIPLICATION)
            if r.value != 0 and (r.level != Levels.MULTIPLICATION):
                # We block a / (b / c) since this can be written as a / b * c.
                # We block a / (b * c) since this can be written as a / b / c.
                yield Result(l.value / r.value,
                             f"{l.bracketed(Levels.MULTIPLICATION)} / {r.bracketed(Levels.MULTIPLICATION + 1)}",
                             Levels.MULTIPLICATION)
            new_value = None
            power_okay = l.value >= 0 or r.value.denominator % 2 == 1
            if l.value == 1:
                new_value = Fraction(1)
            elif l.value == -1:
                if power_okay:
                    new_value = Fraction(-1
                                         if r.value.numerator % 2 == 1
                                         else 1)
            elif l.value == 0:
                if r.value > 0:
                    new_value = Fraction(0)
            else:
                # Only whole number powers are allowed for numbers other than
                # -1, 0, 1.
                if (power_okay
                        and r.value.denominator == 1
                        and -8 < r.value.numerator < 8):
                    new_value = l.value ** r.value
            if new_value is not None:
                # The left side is bracketed when it's a power because power is
                # right associative.
                yield Result(new_value,
                             f"{l.bracketed(Levels.POWER + 1)} ^ {r.bracketed(Levels.POWER)}",
                             Levels.POWER)
            if (l.level == Levels.BARE
                    and r.level == Levels.BARE and len(r.way) == 1):
                # We concatenate 123 as 1(23), but not as (12)3.
                yield Result(l.value * 10 + r.value,
                             f"{l.way}{r.way}",
                             Levels.BARE)


def negate(rs):
    for r in rs:
        yield r
        if r.level > Levels.MULTIPLICATION:
            # We block -(a + b) since this can be written -a - b.
            # We block -(a - b) since this can be written -a + b.
            # We block -(a * b) since this can be written -a * b.
            # We block -(a / b) since this can be written -a / b.
            yield Result(-r.value,
                         f"-{r.bracketed(Levels.NEGATION)}",
                         Levels.NEGATION)


def factorialize(rs):
    for r in rs:
        yield r
        x = 0
        while (r.value.denominator == 1
               and (r.value.numerator == 0 or (3 <= r.value.numerator <= 20))):
            # We block fractional and negative factorials.
            # We block 1 and 2 factorial.
            # We block gigantic factorials.
            r = Result(Fraction(math.factorial(r.value.numerator)),
                       f"{r.bracketed(Levels.FACTORIAL + 1)}!",
                       Levels.FACTORIAL)
            yield r


# memoization makes the recursive solution into a dynamic programming solution.
@memoized(hashable=False)
def do(digits):
    """
    Given a list of digits, produce a list of Result objects.
    """
    l = len(digits)
    if l == 1:
        # Return a Result object for a single digit.
        new_rs = [Result(Fraction(digits[0]), str(digits[0]), Levels.BARE)]
    else:
        # The list of results for a list of digits is the total results for every contiguous partition.
        new_rs = []
        for i in range(1, l):
            new_rs.extend(list(combine(do(digits[:i]),
                                       do(digits[i:]))))
    return list(factorialize(negate(new_rs)))


rs = do(NUMBERS)
vs = {}
for r in rs:
    vs.setdefault(r.value, []).append(r)
print(f"Solutions to {NUMBERS} = {RESULT}")
for r in sorted(vs[RESULT], key=lambda r: len(r.way)):
    print(r.way)
print()
print(f"                         value solutions")
for v, l in sorted(vs.items(), key=lambda vl: (len(vl[1]), len(str(vl[0])))):
    print(f"{str(v):>30} {len(l):<12}")

prints

Solutions to [6, 5, 4, 3] = 1
65 - 4 ^ 3
(6 - 5) ^ 43
65 + (-4) ^ 3
-(-6 + 5) ^ 43
-6 - 5 + 4 * 3
6 + 5 - 4 - 3!
6 - 5 * (4 - 3)
6 - 5 / (4 - 3)
6 - 5 ^ (4 - 3)
6 / (5 + 4 - 3)
6 - 5! / 4 / 3!
(6 - 5) ^ 4 ^ 3
(6 - 5) ^ (-43)
...
(((-6 + 5 + 4)!)! - (3!)!)!
((6! / (5! / 4!)!)! - (3!)!)!
((-(-6) ^ (5 - 4))! - (3!)!)!
$\endgroup$
4
  • 1
    $\begingroup$ This code just bounced off my head. It would be great if will add some explanations in comments. $\endgroup$
    – haccks
    Aug 29, 2018 at 9:33
  • 1
    $\begingroup$ So what does this output? $\endgroup$
    – aschepler
    Aug 30, 2018 at 2:08
  • $\begingroup$ @aschepler Added $\endgroup$
    – Neil G
    Aug 30, 2018 at 5:09
  • $\begingroup$ @haccks I added some comments. $\endgroup$
    – Neil G
    Aug 30, 2018 at 5:09
1
$\begingroup$

9 factorials, following the rules (answer below)

Some tricks to use

First trick:

$0!=1$ (by definition). We will use the fact that $\forall x\in\mathbb{R}:0\cdot x=0 \Rightarrow (0\cdot x)!=1$.

Second trick:

Since we cannot use $1!$ or $2!$ and we cannot use $n!$ for $n>20$, we have to look the other way: think smaller. Lucky for us, we have $x!=\Gamma(x+1)$ where $\Gamma$ is the gamma function and this holds for $x\in\mathbb{R}$.

Building our answer

First step (using the first trick):

We need zero. That's pretty easy, we have $6!-(3!)!=6!-6!=0$.

Second step (using the second trick):

We need many factorials but we can only use $4$ and $5$ because we used the others in the first step. To get those, we aren't going to worry about the outcome because we will multiply by $0$ anyway. We only have to be careful not to get to close to $0$ or $1$ (we shall stay at least $0.01$ distance away from them) and not to exceed $20$.

Calculations in the second step:

The first factorial $\left(\frac{-5}{4}\right)!\approx -4.9$. The second factorial $\left(\left(\frac{-5}{4}\right)!\right)!\approx 0.50$. The third factorial $\left(\left(\left(\frac{-5}{4}\right)!\right)!\right)!\approx 0.89$. The fourth factorial $\left(\left(\left(\left(\frac{-5}{4}\right)!\right)!\right)!\right)!\approx 0.96$. The fifth factorial $\left(\left(\left(\left(\left(\frac{-5}{4}\right)!\right)!\right)!\right)!\right)!\approx 0.983$. The sixth factorial $\left(\left(\left(\left(\left(\left(\frac{-5}{4}\right)!\right)!\right)!\right)!\right)!\right)!\approx 0.993$. Therefore, we can use 5 factorials here, because with the sixth step we get to close to $1$.

Answer

$$x=6!-(3!)!=0$$ $$y=\left(\left(\left(\left(\left(\frac{-5}{4}\right)!\right)!\right)!\right)!\right)!\approx 0.983$$ $$\textit{final answer}=(x\cdot y)!=0!=1$$

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.