Maximize the number of factorials in your solution to 6 5 4 3 = 1

The name of the pictureThe name of the pictureThe name of the pictureClash Royale CLAN TAG#URR8PPP











up vote
9
down vote

favorite
1












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.







share|improve this question






















  • I'm guessing we shouldn't take the factorial of 2 either
    – Bennett Bernardoni
    Aug 28 at 14:11










  • @BennettBernardoni Thanks, yes.
    – Neil G
    Aug 28 at 14:11










  • Is the answer really different than wolfram42's answer to the other puzzle? (3 factorials)
    – xhienne
    Aug 28 at 14:17











  • @xhienne That was my opinion but if he found 8 that is probably precise enough for another question.
    – Saeïdryl
    Aug 28 at 14:18






  • 1




    @Saeïdryl I understand that you can not use (6 - 5)! nor (6 - 4)!
    – xhienne
    Aug 28 at 14:21















up vote
9
down vote

favorite
1












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.







share|improve this question






















  • I'm guessing we shouldn't take the factorial of 2 either
    – Bennett Bernardoni
    Aug 28 at 14:11










  • @BennettBernardoni Thanks, yes.
    – Neil G
    Aug 28 at 14:11










  • Is the answer really different than wolfram42's answer to the other puzzle? (3 factorials)
    – xhienne
    Aug 28 at 14:17











  • @xhienne That was my opinion but if he found 8 that is probably precise enough for another question.
    – Saeïdryl
    Aug 28 at 14:18






  • 1




    @Saeïdryl I understand that you can not use (6 - 5)! nor (6 - 4)!
    – xhienne
    Aug 28 at 14:21













up vote
9
down vote

favorite
1









up vote
9
down vote

favorite
1






1





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.







share|improve this question














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.









share|improve this question













share|improve this question




share|improve this question








edited Aug 28 at 14:31

























asked Aug 28 at 14:08









Neil G

19419




19419











  • I'm guessing we shouldn't take the factorial of 2 either
    – Bennett Bernardoni
    Aug 28 at 14:11










  • @BennettBernardoni Thanks, yes.
    – Neil G
    Aug 28 at 14:11










  • Is the answer really different than wolfram42's answer to the other puzzle? (3 factorials)
    – xhienne
    Aug 28 at 14:17











  • @xhienne That was my opinion but if he found 8 that is probably precise enough for another question.
    – Saeïdryl
    Aug 28 at 14:18






  • 1




    @Saeïdryl I understand that you can not use (6 - 5)! nor (6 - 4)!
    – xhienne
    Aug 28 at 14:21

















  • I'm guessing we shouldn't take the factorial of 2 either
    – Bennett Bernardoni
    Aug 28 at 14:11










  • @BennettBernardoni Thanks, yes.
    – Neil G
    Aug 28 at 14:11










  • Is the answer really different than wolfram42's answer to the other puzzle? (3 factorials)
    – xhienne
    Aug 28 at 14:17











  • @xhienne That was my opinion but if he found 8 that is probably precise enough for another question.
    – Saeïdryl
    Aug 28 at 14:18






  • 1




    @Saeïdryl I understand that you can not use (6 - 5)! nor (6 - 4)!
    – xhienne
    Aug 28 at 14:21
















I'm guessing we shouldn't take the factorial of 2 either
– Bennett Bernardoni
Aug 28 at 14:11




I'm guessing we shouldn't take the factorial of 2 either
– Bennett Bernardoni
Aug 28 at 14:11












@BennettBernardoni Thanks, yes.
– Neil G
Aug 28 at 14:11




@BennettBernardoni Thanks, yes.
– Neil G
Aug 28 at 14:11












Is the answer really different than wolfram42's answer to the other puzzle? (3 factorials)
– xhienne
Aug 28 at 14:17





Is the answer really different than wolfram42's answer to the other puzzle? (3 factorials)
– xhienne
Aug 28 at 14:17













@xhienne That was my opinion but if he found 8 that is probably precise enough for another question.
– Saeïdryl
Aug 28 at 14:18




@xhienne That was my opinion but if he found 8 that is probably precise enough for another question.
– Saeïdryl
Aug 28 at 14:18




1




1




@Saeïdryl I understand that you can not use (6 - 5)! nor (6 - 4)!
– xhienne
Aug 28 at 14:21





@Saeïdryl I understand that you can not use (6 - 5)! nor (6 - 4)!
– xhienne
Aug 28 at 14:21











6 Answers
6






active

oldest

votes

















up vote
10
down vote



accepted










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




$$frac6!(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(frac6!(5!div4!)!! - 3!!right)!$$ works since 0! = 1 by definition.







share|improve this answer






















  • Missing one pair of parentheses I think, but yes amazing! How did you do it?
    – Neil G
    Aug 28 at 16:44










  • Actually i made a quick edit and I confused myself. I'll readjust in a minute
    – wolfram42
    Aug 28 at 16:46










  • Nice, you're pretty close to 8
    – Neil G
    Aug 28 at 16:57






  • 3




    Presumably by $n!!$ you mean $(n!)!$, not the double factorial operation $prod_k in mathbb N, n - 2 k > 0 (n - 2 k)$?
    – wchargin
    Aug 28 at 22:44






  • 1




    I assumed that the double factorial operation was not allowed since it would be easy to get more than 8 that way.
    – wolfram42
    Aug 29 at 14:07

















up vote
43
down vote













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.







share|improve this answer




















  • Wow, that's brilliant
    – Neil G
    Aug 28 at 14:28






  • 1




    (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.)
    – Neil G
    Aug 28 at 16:46






  • 7




    @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!
    – Jeremy Weirich
    Aug 29 at 12:16











  • @jeremy well I upvoted him ?
    – Neil G
    Aug 29 at 12:24

















up vote
11
down vote













How about




Infinitely many factorials?

A basic example would be : $frac6 * (5-4) 3! = 1$

But you could add some factorials in the lot : $frac6! * (5-4) 3!! = 1 $
Or even : $frac6!!!!!!!times (5-4) (3!)!!!!!!! = 1 $
Really, as long as there is one more factorial behind the 3, we're good!







share|improve this answer


















  • 2




    Damn you, @Bennett Bernardoni ! :p
    – Keelhaul
    Aug 28 at 14:29







  • 1




    Great answer! And congratz on the $7k$ rep! :D
    – user477343
    Aug 29 at 22:01

















up vote
6
down vote













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






share|improve this answer





























    up vote
    2
    down vote













    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.wayr.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!)!)!





    share|improve this answer


















    • 1




      This code just bounced off my head. It would be great if will add some explanations in comments.
      – haccks
      Aug 29 at 9:33






    • 1




      So what does this output?
      – aschepler
      Aug 30 at 2:08










    • @aschepler Added
      – Neil G
      Aug 30 at 5:09










    • @haccks I added some comments.
      – Neil G
      Aug 30 at 5:09

















    up vote
    1
    down vote













    9 factorials, following the rules (answer below)



    Some tricks to use



    First trick:




    $0!=1$ (by definition). We will use the fact that $forall xinmathbbR:0cdot x=0 Rightarrow (0cdot 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 $xinmathbbR$.




    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-54right)!approx -4.9$.
    The second factorial $left(left(frac-54right)!right)!approx 0.50$.
    The third factorial $left(left(left(frac-54right)!right)!right)!approx 0.89$.
    The fourth factorial $left(left(left(left(frac-54right)!right)!right)!right)!approx 0.96$.
    The fifth factorial $left(left(left(left(left(frac-54right)!right)!right)!right)!right)!approx 0.983$.
    The sixth factorial $left(left(left(left(left(left(frac-54right)!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-54right)!right)!right)!right)!right)!approx 0.983$$
    $$textitfinal answer=(xcdot y)!=0!=1$$







    share|improve this answer




















      Your Answer




      StackExchange.ifUsing("editor", function ()
      return StackExchange.using("mathjaxEditing", function ()
      StackExchange.MarkdownEditor.creationCallbacks.add(function (editor, postfix)
      StackExchange.mathjaxEditing.prepareWmdForMathJax(editor, postfix, [["$", "$"], ["\\(","\\)"]]);
      );
      );
      , "mathjax-editing");

      StackExchange.ready(function()
      var channelOptions =
      tags: "".split(" "),
      id: "559"
      ;
      initTagRenderer("".split(" "), "".split(" "), channelOptions);

      StackExchange.using("externalEditor", function()
      // Have to fire editor after snippets, if snippets enabled
      if (StackExchange.settings.snippets.snippetsEnabled)
      StackExchange.using("snippets", function()
      createEditor();
      );

      else
      createEditor();

      );

      function createEditor()
      StackExchange.prepareEditor(
      heartbeatType: 'answer',
      convertImagesToLinks: false,
      noModals: false,
      showLowRepImageUploadWarning: true,
      reputationToPostImages: null,
      bindNavPrevention: true,
      postfix: "",
      noCode: true, onDemand: true,
      discardSelector: ".discard-answer"
      ,immediatelyShowMarkdownHelp:true
      );



      );













       

      draft saved


      draft discarded


















      StackExchange.ready(
      function ()
      StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fpuzzling.stackexchange.com%2fquestions%2f70838%2fmaximize-the-number-of-factorials-in-your-solution-to-6-5-4-3-1%23new-answer', 'question_page');

      );

      Post as a guest






























      6 Answers
      6






      active

      oldest

      votes








      6 Answers
      6






      active

      oldest

      votes









      active

      oldest

      votes






      active

      oldest

      votes








      up vote
      10
      down vote



      accepted










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




      $$frac6!(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(frac6!(5!div4!)!! - 3!!right)!$$ works since 0! = 1 by definition.







      share|improve this answer






















      • Missing one pair of parentheses I think, but yes amazing! How did you do it?
        – Neil G
        Aug 28 at 16:44










      • Actually i made a quick edit and I confused myself. I'll readjust in a minute
        – wolfram42
        Aug 28 at 16:46










      • Nice, you're pretty close to 8
        – Neil G
        Aug 28 at 16:57






      • 3




        Presumably by $n!!$ you mean $(n!)!$, not the double factorial operation $prod_k in mathbb N, n - 2 k > 0 (n - 2 k)$?
        – wchargin
        Aug 28 at 22:44






      • 1




        I assumed that the double factorial operation was not allowed since it would be easy to get more than 8 that way.
        – wolfram42
        Aug 29 at 14:07














      up vote
      10
      down vote



      accepted










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




      $$frac6!(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(frac6!(5!div4!)!! - 3!!right)!$$ works since 0! = 1 by definition.







      share|improve this answer






















      • Missing one pair of parentheses I think, but yes amazing! How did you do it?
        – Neil G
        Aug 28 at 16:44










      • Actually i made a quick edit and I confused myself. I'll readjust in a minute
        – wolfram42
        Aug 28 at 16:46










      • Nice, you're pretty close to 8
        – Neil G
        Aug 28 at 16:57






      • 3




        Presumably by $n!!$ you mean $(n!)!$, not the double factorial operation $prod_k in mathbb N, n - 2 k > 0 (n - 2 k)$?
        – wchargin
        Aug 28 at 22:44






      • 1




        I assumed that the double factorial operation was not allowed since it would be easy to get more than 8 that way.
        – wolfram42
        Aug 29 at 14:07












      up vote
      10
      down vote



      accepted







      up vote
      10
      down vote



      accepted






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




      $$frac6!(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(frac6!(5!div4!)!! - 3!!right)!$$ works since 0! = 1 by definition.







      share|improve this answer














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




      $$frac6!(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(frac6!(5!div4!)!! - 3!!right)!$$ works since 0! = 1 by definition.








      share|improve this answer














      share|improve this answer



      share|improve this answer








      edited Aug 28 at 19:01









      Community♦

      1




      1










      answered Aug 28 at 16:43









      wolfram42

      2,185119




      2,185119











      • Missing one pair of parentheses I think, but yes amazing! How did you do it?
        – Neil G
        Aug 28 at 16:44










      • Actually i made a quick edit and I confused myself. I'll readjust in a minute
        – wolfram42
        Aug 28 at 16:46










      • Nice, you're pretty close to 8
        – Neil G
        Aug 28 at 16:57






      • 3




        Presumably by $n!!$ you mean $(n!)!$, not the double factorial operation $prod_k in mathbb N, n - 2 k > 0 (n - 2 k)$?
        – wchargin
        Aug 28 at 22:44






      • 1




        I assumed that the double factorial operation was not allowed since it would be easy to get more than 8 that way.
        – wolfram42
        Aug 29 at 14:07
















      • Missing one pair of parentheses I think, but yes amazing! How did you do it?
        – Neil G
        Aug 28 at 16:44










      • Actually i made a quick edit and I confused myself. I'll readjust in a minute
        – wolfram42
        Aug 28 at 16:46










      • Nice, you're pretty close to 8
        – Neil G
        Aug 28 at 16:57






      • 3




        Presumably by $n!!$ you mean $(n!)!$, not the double factorial operation $prod_k in mathbb N, n - 2 k > 0 (n - 2 k)$?
        – wchargin
        Aug 28 at 22:44






      • 1




        I assumed that the double factorial operation was not allowed since it would be easy to get more than 8 that way.
        – wolfram42
        Aug 29 at 14:07















      Missing one pair of parentheses I think, but yes amazing! How did you do it?
      – Neil G
      Aug 28 at 16:44




      Missing one pair of parentheses I think, but yes amazing! How did you do it?
      – Neil G
      Aug 28 at 16:44












      Actually i made a quick edit and I confused myself. I'll readjust in a minute
      – wolfram42
      Aug 28 at 16:46




      Actually i made a quick edit and I confused myself. I'll readjust in a minute
      – wolfram42
      Aug 28 at 16:46












      Nice, you're pretty close to 8
      – Neil G
      Aug 28 at 16:57




      Nice, you're pretty close to 8
      – Neil G
      Aug 28 at 16:57




      3




      3




      Presumably by $n!!$ you mean $(n!)!$, not the double factorial operation $prod_k in mathbb N, n - 2 k > 0 (n - 2 k)$?
      – wchargin
      Aug 28 at 22:44




      Presumably by $n!!$ you mean $(n!)!$, not the double factorial operation $prod_k in mathbb N, n - 2 k > 0 (n - 2 k)$?
      – wchargin
      Aug 28 at 22:44




      1




      1




      I assumed that the double factorial operation was not allowed since it would be easy to get more than 8 that way.
      – wolfram42
      Aug 29 at 14:07




      I assumed that the double factorial operation was not allowed since it would be easy to get more than 8 that way.
      – wolfram42
      Aug 29 at 14:07










      up vote
      43
      down vote













      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.







      share|improve this answer




















      • Wow, that's brilliant
        – Neil G
        Aug 28 at 14:28






      • 1




        (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.)
        – Neil G
        Aug 28 at 16:46






      • 7




        @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!
        – Jeremy Weirich
        Aug 29 at 12:16











      • @jeremy well I upvoted him ?
        – Neil G
        Aug 29 at 12:24














      up vote
      43
      down vote













      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.







      share|improve this answer




















      • Wow, that's brilliant
        – Neil G
        Aug 28 at 14:28






      • 1




        (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.)
        – Neil G
        Aug 28 at 16:46






      • 7




        @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!
        – Jeremy Weirich
        Aug 29 at 12:16











      • @jeremy well I upvoted him ?
        – Neil G
        Aug 29 at 12:24












      up vote
      43
      down vote










      up vote
      43
      down vote









      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.







      share|improve this answer












      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.








      share|improve this answer












      share|improve this answer



      share|improve this answer










      answered Aug 28 at 14:26









      Bennett Bernardoni

      2,073415




      2,073415











      • Wow, that's brilliant
        – Neil G
        Aug 28 at 14:28






      • 1




        (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.)
        – Neil G
        Aug 28 at 16:46






      • 7




        @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!
        – Jeremy Weirich
        Aug 29 at 12:16











      • @jeremy well I upvoted him ?
        – Neil G
        Aug 29 at 12:24
















      • Wow, that's brilliant
        – Neil G
        Aug 28 at 14:28






      • 1




        (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.)
        – Neil G
        Aug 28 at 16:46






      • 7




        @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!
        – Jeremy Weirich
        Aug 29 at 12:16











      • @jeremy well I upvoted him ?
        – Neil G
        Aug 29 at 12:24















      Wow, that's brilliant
      – Neil G
      Aug 28 at 14:28




      Wow, that's brilliant
      – Neil G
      Aug 28 at 14:28




      1




      1




      (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.)
      – Neil G
      Aug 28 at 16:46




      (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.)
      – Neil G
      Aug 28 at 16:46




      7




      7




      @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!
      – Jeremy Weirich
      Aug 29 at 12:16





      @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!
      – Jeremy Weirich
      Aug 29 at 12:16













      @jeremy well I upvoted him ?
      – Neil G
      Aug 29 at 12:24




      @jeremy well I upvoted him ?
      – Neil G
      Aug 29 at 12:24










      up vote
      11
      down vote













      How about




      Infinitely many factorials?

      A basic example would be : $frac6 * (5-4) 3! = 1$

      But you could add some factorials in the lot : $frac6! * (5-4) 3!! = 1 $
      Or even : $frac6!!!!!!!times (5-4) (3!)!!!!!!! = 1 $
      Really, as long as there is one more factorial behind the 3, we're good!







      share|improve this answer


















      • 2




        Damn you, @Bennett Bernardoni ! :p
        – Keelhaul
        Aug 28 at 14:29







      • 1




        Great answer! And congratz on the $7k$ rep! :D
        – user477343
        Aug 29 at 22:01














      up vote
      11
      down vote













      How about




      Infinitely many factorials?

      A basic example would be : $frac6 * (5-4) 3! = 1$

      But you could add some factorials in the lot : $frac6! * (5-4) 3!! = 1 $
      Or even : $frac6!!!!!!!times (5-4) (3!)!!!!!!! = 1 $
      Really, as long as there is one more factorial behind the 3, we're good!







      share|improve this answer


















      • 2




        Damn you, @Bennett Bernardoni ! :p
        – Keelhaul
        Aug 28 at 14:29







      • 1




        Great answer! And congratz on the $7k$ rep! :D
        – user477343
        Aug 29 at 22:01












      up vote
      11
      down vote










      up vote
      11
      down vote









      How about




      Infinitely many factorials?

      A basic example would be : $frac6 * (5-4) 3! = 1$

      But you could add some factorials in the lot : $frac6! * (5-4) 3!! = 1 $
      Or even : $frac6!!!!!!!times (5-4) (3!)!!!!!!! = 1 $
      Really, as long as there is one more factorial behind the 3, we're good!







      share|improve this answer














      How about




      Infinitely many factorials?

      A basic example would be : $frac6 * (5-4) 3! = 1$

      But you could add some factorials in the lot : $frac6! * (5-4) 3!! = 1 $
      Or even : $frac6!!!!!!!times (5-4) (3!)!!!!!!! = 1 $
      Really, as long as there is one more factorial behind the 3, we're good!








      share|improve this answer














      share|improve this answer



      share|improve this answer








      edited Aug 30 at 2:18









      JonMark Perry

      13.8k42667




      13.8k42667










      answered Aug 28 at 14:29









      Keelhaul

      7,1132473




      7,1132473







      • 2




        Damn you, @Bennett Bernardoni ! :p
        – Keelhaul
        Aug 28 at 14:29







      • 1




        Great answer! And congratz on the $7k$ rep! :D
        – user477343
        Aug 29 at 22:01












      • 2




        Damn you, @Bennett Bernardoni ! :p
        – Keelhaul
        Aug 28 at 14:29







      • 1




        Great answer! And congratz on the $7k$ rep! :D
        – user477343
        Aug 29 at 22:01







      2




      2




      Damn you, @Bennett Bernardoni ! :p
      – Keelhaul
      Aug 28 at 14:29





      Damn you, @Bennett Bernardoni ! :p
      – Keelhaul
      Aug 28 at 14:29





      1




      1




      Great answer! And congratz on the $7k$ rep! :D
      – user477343
      Aug 29 at 22:01




      Great answer! And congratz on the $7k$ rep! :D
      – user477343
      Aug 29 at 22:01










      up vote
      6
      down vote













      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






      share|improve this answer


























        up vote
        6
        down vote













        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






        share|improve this answer
























          up vote
          6
          down vote










          up vote
          6
          down vote









          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






          share|improve this answer














          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







          share|improve this answer














          share|improve this answer



          share|improve this answer








          edited Aug 28 at 14:38

























          answered Aug 28 at 14:29









          xhienne

          2,854526




          2,854526




















              up vote
              2
              down vote













              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.wayr.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!)!)!





              share|improve this answer


















              • 1




                This code just bounced off my head. It would be great if will add some explanations in comments.
                – haccks
                Aug 29 at 9:33






              • 1




                So what does this output?
                – aschepler
                Aug 30 at 2:08










              • @aschepler Added
                – Neil G
                Aug 30 at 5:09










              • @haccks I added some comments.
                – Neil G
                Aug 30 at 5:09














              up vote
              2
              down vote













              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.wayr.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!)!)!





              share|improve this answer


















              • 1




                This code just bounced off my head. It would be great if will add some explanations in comments.
                – haccks
                Aug 29 at 9:33






              • 1




                So what does this output?
                – aschepler
                Aug 30 at 2:08










              • @aschepler Added
                – Neil G
                Aug 30 at 5:09










              • @haccks I added some comments.
                – Neil G
                Aug 30 at 5:09












              up vote
              2
              down vote










              up vote
              2
              down vote









              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.wayr.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!)!)!





              share|improve this answer














              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.wayr.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!)!)!






              share|improve this answer














              share|improve this answer



              share|improve this answer








              edited Aug 30 at 6:51

























              answered Aug 28 at 18:25









              Neil G

              19419




              19419







              • 1




                This code just bounced off my head. It would be great if will add some explanations in comments.
                – haccks
                Aug 29 at 9:33






              • 1




                So what does this output?
                – aschepler
                Aug 30 at 2:08










              • @aschepler Added
                – Neil G
                Aug 30 at 5:09










              • @haccks I added some comments.
                – Neil G
                Aug 30 at 5:09












              • 1




                This code just bounced off my head. It would be great if will add some explanations in comments.
                – haccks
                Aug 29 at 9:33






              • 1




                So what does this output?
                – aschepler
                Aug 30 at 2:08










              • @aschepler Added
                – Neil G
                Aug 30 at 5:09










              • @haccks I added some comments.
                – Neil G
                Aug 30 at 5:09







              1




              1




              This code just bounced off my head. It would be great if will add some explanations in comments.
              – haccks
              Aug 29 at 9:33




              This code just bounced off my head. It would be great if will add some explanations in comments.
              – haccks
              Aug 29 at 9:33




              1




              1




              So what does this output?
              – aschepler
              Aug 30 at 2:08




              So what does this output?
              – aschepler
              Aug 30 at 2:08












              @aschepler Added
              – Neil G
              Aug 30 at 5:09




              @aschepler Added
              – Neil G
              Aug 30 at 5:09












              @haccks I added some comments.
              – Neil G
              Aug 30 at 5:09




              @haccks I added some comments.
              – Neil G
              Aug 30 at 5:09










              up vote
              1
              down vote













              9 factorials, following the rules (answer below)



              Some tricks to use



              First trick:




              $0!=1$ (by definition). We will use the fact that $forall xinmathbbR:0cdot x=0 Rightarrow (0cdot 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 $xinmathbbR$.




              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-54right)!approx -4.9$.
              The second factorial $left(left(frac-54right)!right)!approx 0.50$.
              The third factorial $left(left(left(frac-54right)!right)!right)!approx 0.89$.
              The fourth factorial $left(left(left(left(frac-54right)!right)!right)!right)!approx 0.96$.
              The fifth factorial $left(left(left(left(left(frac-54right)!right)!right)!right)!right)!approx 0.983$.
              The sixth factorial $left(left(left(left(left(left(frac-54right)!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-54right)!right)!right)!right)!right)!approx 0.983$$
              $$textitfinal answer=(xcdot y)!=0!=1$$







              share|improve this answer
























                up vote
                1
                down vote













                9 factorials, following the rules (answer below)



                Some tricks to use



                First trick:




                $0!=1$ (by definition). We will use the fact that $forall xinmathbbR:0cdot x=0 Rightarrow (0cdot 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 $xinmathbbR$.




                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-54right)!approx -4.9$.
                The second factorial $left(left(frac-54right)!right)!approx 0.50$.
                The third factorial $left(left(left(frac-54right)!right)!right)!approx 0.89$.
                The fourth factorial $left(left(left(left(frac-54right)!right)!right)!right)!approx 0.96$.
                The fifth factorial $left(left(left(left(left(frac-54right)!right)!right)!right)!right)!approx 0.983$.
                The sixth factorial $left(left(left(left(left(left(frac-54right)!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-54right)!right)!right)!right)!right)!approx 0.983$$
                $$textitfinal answer=(xcdot y)!=0!=1$$







                share|improve this answer






















                  up vote
                  1
                  down vote










                  up vote
                  1
                  down vote









                  9 factorials, following the rules (answer below)



                  Some tricks to use



                  First trick:




                  $0!=1$ (by definition). We will use the fact that $forall xinmathbbR:0cdot x=0 Rightarrow (0cdot 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 $xinmathbbR$.




                  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-54right)!approx -4.9$.
                  The second factorial $left(left(frac-54right)!right)!approx 0.50$.
                  The third factorial $left(left(left(frac-54right)!right)!right)!approx 0.89$.
                  The fourth factorial $left(left(left(left(frac-54right)!right)!right)!right)!approx 0.96$.
                  The fifth factorial $left(left(left(left(left(frac-54right)!right)!right)!right)!right)!approx 0.983$.
                  The sixth factorial $left(left(left(left(left(left(frac-54right)!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-54right)!right)!right)!right)!right)!approx 0.983$$
                  $$textitfinal answer=(xcdot y)!=0!=1$$







                  share|improve this answer












                  9 factorials, following the rules (answer below)



                  Some tricks to use



                  First trick:




                  $0!=1$ (by definition). We will use the fact that $forall xinmathbbR:0cdot x=0 Rightarrow (0cdot 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 $xinmathbbR$.




                  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-54right)!approx -4.9$.
                  The second factorial $left(left(frac-54right)!right)!approx 0.50$.
                  The third factorial $left(left(left(frac-54right)!right)!right)!approx 0.89$.
                  The fourth factorial $left(left(left(left(frac-54right)!right)!right)!right)!approx 0.96$.
                  The fifth factorial $left(left(left(left(left(frac-54right)!right)!right)!right)!right)!approx 0.983$.
                  The sixth factorial $left(left(left(left(left(left(frac-54right)!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-54right)!right)!right)!right)!right)!approx 0.983$$
                  $$textitfinal answer=(xcdot y)!=0!=1$$








                  share|improve this answer












                  share|improve this answer



                  share|improve this answer










                  answered Aug 29 at 15:08









                  JJJ

                  1505




                  1505



























                       

                      draft saved


                      draft discarded















































                       


                      draft saved


                      draft discarded














                      StackExchange.ready(
                      function ()
                      StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fpuzzling.stackexchange.com%2fquestions%2f70838%2fmaximize-the-number-of-factorials-in-your-solution-to-6-5-4-3-1%23new-answer', 'question_page');

                      );

                      Post as a guest













































































                      Comments

                      Popular posts from this blog

                      What does second last employer means? [closed]

                      List of Gilmore Girls characters

                      One-line joke