• (cs)

    This reminds me of a school maths project we had.

    You could use any mathmatical operator (root, power etc)

    You had 4 4s and had to use all 4 to get every number between 1 and 100.

    I was apparently the only person to get all of them in the 3 years it had been running though I think some questioned the way I used factorial but I was only 14-15 at the time.

  • Buddy (unregistered) in reply to Alex
    Alex:
    Go ahead, I for one would like to see a prolog solution..

    And my final submission. 3rd time's the charm..

    My final one, too: _24x.cc

    This exhaustively permutes all numeric arguments and operators and runs them through dc to check the output. A true hack!

    Upsides: guaranteed to find a solution if it exists, any number of parameters are allowed.

    Downsides: slow, I mean slooOOoow, and many duplicate solutions are generated.

    Requires *nix utility dc and optionally sort and uniq. To use more effectively, the output should be sorted and filtered to remove exact duplicates:

    echo '1 3 5 7' | ./_24x | sort | uniq 1 5 + 7 3 - * 3 1 - 5 7 + * 3 1 - 7 5 + * 5 1 + 7 3 - * 5 7 + 3 1 - * 7 3 - 1 5 + * 7 3 - 5 1 + * 7 5 + 3 1 - *

    Which through inspection leaves two unique solutions, all the others are equivalent to these two: 1 5 + 7 3 - * 3 1 - 5 7 + *

    Overall, lots of fun. Would like to see a Haskell or APL solution.

  • Lew Ayotte (unregistered)

    Sounds like a game I use to play with License Plate numbers (I lived in a state with mostly numbers on the plate). My goal was to use the numbers to create two equal numbers.

    Example: 16784

    8 - 6 = 2 7 - 4 - 1 = 2

    2 = 2

    Use to have a contest with my friends to see who could get the most.

    Lew

  • (cs)

    Prolog-Version (with duplicates, output in Polish notation):

    krypto(X, X) :- atomic(X), !.
    krypto([Op, X, Y], Z) :- atomic(X), atomic(Y), Expr =.. [Op, X, Y], !, 
    	(Op \= /; Y \= 0, Y \= 0.0), Z is Expr, !.
    krypto([Op, XTree, YTree], Z) :- krypto(XTree, X),
    	krypto(YTree, Y), krypto([Op, X, Y], Z).
    
    split([X, Y], [X], [Y]) :- !.
    split([Nh|Nr], [Nh|LL], RR) :- split(Nr, LL, RR).
    split([Nh|Nr], [Nh], Nr).
    
    oper(+). oper(-). oper(*). oper(/).
    combi([X], X).
    combi([X, Y], [Op, X, Y]) :- oper(Op).
    combi(N, NC) :- length(N, Nl), Nl > 2, split(N, L, R),
    	combi(L, LC), combi(R, RC), combi([LC, RC], NC).
    
    solution(Numbers, Result, Combi) :- 
    	permutation(Numbers, PNumbers), 
    	combi(PNumbers, Combi), krypto(Combi, Result).
    

    For example, calling

    :- solution([2,3,10], 24, X).
    

    yields:

    Combi = [*, 3, [-, 10, 2]] ;
    Combi = [*, [-, 10, 2], 3]
    
  • Mr.'; Drop Database -- (unregistered) in reply to asdf
    asdf:
    Mr.'; Drop Database --:
    6,7,7,7,8 = 24 has two solutions. One is 6*7*8/(7+7). What's the other one?
    Which of these do you like?

    6 / ((7 + 7) / 7) * 8 = 24 6 * 7 / ((7 + 7) / 8) = 24 ... 8 * 7 / ((7 + 7) / 6) = 24 8 / ((7 + 7) / 7 / 6) = 24

    Those are all duplicates of 6*7*8/(7+7). If you have X*Y/Z then you don't need Y/(Z/X). There is a very interesting alternative solution, but your solver unfortunately hasn't found it.
  • (cs)

    Looks like I am the only one who read it like this:

    8♥ + 5♦ = 8♥ + 5♦

    8♥ + 5♥ = 13♥

  • Chris J (unregistered) in reply to Mr.'; Drop Database --

    My solver finds 7/(7/6 - 7/8)

  • (cs) in reply to Chris J
    Chris J:
    My solver finds 7/(7/6 - 7/8)

    That's an interesting one indeed.

  • kopos (unregistered)

    Interesting. A favorite numbers game of mine is to form pairs out of 4 digit vehicle registration numbers. The allowed operations are +, -, *, /, ^.

    For eg: 5312 would have the two pairs (5 & 1): 5, 3 + 2 or 1, 3 - 2. or 4863 would have pairs of 4: 4, 6 * 8 = 14 = 1 * 4 = 4.

    What would be fun is to find if we can have 4 digit numbers that cannot be built as pairs.

  • Stefan W. (unregistered)

    It's similar to project euler No. 93: http://projecteuler.net/index.php?section=problems&id=93

    There you don't glue ciphers together, but use 4 operators, braces, reorder the numbers, but don't repeat them.

    Then you have to find a mix of ciphers to produce the largest increasing set of numbers, starting from 1. Look yourself for the details.

  • asdf (unregistered) in reply to Mr.'; Drop Database --
    Mr.'; Drop Database --:
    asdf:
    Mr.'; Drop Database --:
    6,7,7,7,8 = 24 has two solutions. One is 6*7*8/(7+7). What's the other one?
    Which of these do you like?

    6 / ((7 + 7) / 7) * 8 = 24 6 * 7 / ((7 + 7) / 8) = 24 ... 8 * 7 / ((7 + 7) / 6) = 24 8 / ((7 + 7) / 7 / 6) = 24

    Those are all duplicates of 6*7*8/(7+7). If you have X*Y/Z then you don't need Y/(Z/X). There is a very interesting alternative solution, but your solver unfortunately hasn't found it.

    I get 37 solutions using the least number of parenthesis for a given order of operators, is it not in this list?

    6 * 7 / (7 + 7) * 8 = 24 6 / (7 + 7) * 7 * 8 = 24 6 / ((7 + 7) / 7) * 8 = 24 6 * 7 / ((7 + 7) / 8) = 24 6 / ((7 + 7) / 7 / 8) = 24 6 / (7 + 7) * 8 * 7 = 24 6 / ((7 + 7) / 8) * 7 = 24 6 / ((7 + 7) / 8 / 7) = 24 6 * 7 * 8 / (7 + 7) = 24 6 * 8 * 7 / (7 + 7) = 24 6 * 8 / (7 + 7) * 7 = 24 6 * 8 / ((7 + 7) / 7) = 24 7 * 6 / (7 + 7) * 8 = 24 7 * 6 / ((7 + 7) / 8) = 24 7 * 6 * 8 / (7 + 7) = 24 7 / (7 / 6 - 7 / 8) = 24 7 / (7 + 7) * 6 * 8 = 24 7 / ((7 + 7) / 6) * 8 = 24 7 / ((7 + 7) / 6 / 8) = 24 7 / (7 + 7) * 8 * 6 = 24 7 / ((7 + 7) / 8) * 6 = 24 7 / ((7 + 7) / 8 / 6) = 24 7 * 8 * 6 / (7 + 7) = 24 7 * 8 / (7 + 7) * 6 = 24 7 * 8 / ((7 + 7) / 6) = 24 8 * 6 * 7 / (7 + 7) = 24 8 * 6 / (7 + 7) * 7 = 24 8 * 6 / ((7 + 7) / 7) = 24 8 * 7 * 6 / (7 + 7) = 24 8 / (7 + 7) * 6 * 7 = 24 8 / ((7 + 7) / 6) * 7 = 24 8 / ((7 + 7) / 6 / 7) = 24 8 * 7 / (7 + 7) * 6 = 24 8 / (7 + 7) * 7 * 6 = 24 8 / ((7 + 7) / 7) * 6 = 24 8 * 7 / ((7 + 7) / 6) = 24 8 / ((7 + 7) / 7 / 6) = 24

  • Buddy (unregistered) in reply to asdf
    asdf:

    I get 37 solutions using the least number of parenthesis for a given order of operators, is it not in this list?

    6 * 7 / (7 + 7) * 8 = 24 6 / (7 + 7) * 7 * 8 = 24 6 / ((7 + 7) / 7) * 8 = 24 6 * 7 / ((7 + 7) / 8) = 24 6 / ((7 + 7) / 7 / 8) = 24 6 / (7 + 7) * 8 * 7 = 24 6 / ((7 + 7) / 8) * 7 = 24 6 / ((7 + 7) / 8 / 7) = 24 6 * 7 * 8 / (7 + 7) = 24 6 * 8 * 7 / (7 + 7) = 24 6 * 8 / (7 + 7) * 7 = 24 6 * 8 / ((7 + 7) / 7) = 24 7 * 6 / (7 + 7) * 8 = 24 7 * 6 / ((7 + 7) / 8) = 24 7 * 6 * 8 / (7 + 7) = 24 7 / (7 / 6 - 7 / 8) = 24 7 / (7 + 7) * 6 * 8 = 24 7 / ((7 + 7) / 6) * 8 = 24 7 / ((7 + 7) / 6 / 8) = 24 7 / (7 + 7) * 8 * 6 = 24 7 / ((7 + 7) / 8) * 6 = 24 7 / ((7 + 7) / 8 / 6) = 24 7 * 8 * 6 / (7 + 7) = 24 7 * 8 / (7 + 7) * 6 = 24 7 * 8 / ((7 + 7) / 6) = 24 8 * 6 * 7 / (7 + 7) = 24 8 * 6 / (7 + 7) * 7 = 24 8 * 6 / ((7 + 7) / 7) = 24 8 * 7 * 6 / (7 + 7) = 24 8 / (7 + 7) * 6 * 7 = 24 8 / ((7 + 7) / 6) * 7 = 24 8 / ((7 + 7) / 6 / 7) = 24 8 * 7 / (7 + 7) * 6 = 24 8 / (7 + 7) * 7 * 6 = 24 8 / ((7 + 7) / 7) * 6 = 24 8 * 7 / ((7 + 7) / 6) = 24 8 / ((7 + 7) / 7 / 6) = 24

    No, the alternate solution will have a subtraction operator. It has no associative operators, so it has only one format:

    7 / (7 / 6 - 7 / 8) = 24

    If you're using floating point it's important to be careful with equalities.

    To illustrate, can use a floating point type with 6 decimal digits of accuracy:

    7 / (7 / 6 - 7 / 8)

    = 7 / (1.16667 - 0.875000)

    = 7 / 0.291670

    = 23.9997 != 24.0000

    Better to take the absolute value of a difference to the value and compare against some tolerance.

    The simplest is something like this:

    | calculated - target | < tolerance

    Or for targets <> 0:

    | (calculated - target) / target | < tolerance

  • asdf (unregistered) in reply to Buddy
    Buddy:
    asdf:

    I get 37 solutions using the least number of parenthesis for a given order of operators, is it not in this list?

    6 * 7 / (7 + 7) * 8 = 24 ... 7 / (7 / 6 - 7 / 8) = 24 ... 8 / ((7 + 7) / 7 / 6) = 24

    No, the alternate solution will have a subtraction operator. It has no associative operators, so it has only one format:

    7 / (7 / 6 - 7 / 8) = 24

    If you're using floating point it's important to be careful with equalities.

    To illustrate, can use a floating point type with 6 decimal digits of accuracy:

    7 / (7 / 6 - 7 / 8)

    = 7 / (1.16667 - 0.875000)

    = 7 / 0.291670

    = 23.9997 != 24.0000

    Better to take the absolute value of a difference to the value and compare against some tolerance.

    The simplest is something like this:

    | calculated - target | < tolerance

    Or for targets <> 0:

    | (calculated - target) / target | < tolerance

    You are correct. The result was in the solution set and I did have to use double precision for the calculation with a tolerance. It was buried in the middle of the solution set.

  • Buddy (unregistered) in reply to asdf
    asdf:
    You are correct. The result was in the solution set and I did have to use double precision for the calculation with a tolerance. It was buried in the middle of the solution set.
    I see it now. Very good.
  • gedit (unregistered) in reply to asdf
    asdf:
    Mr.'; Drop Database --:
    asdf:
    Mr.'; Drop Database --:
    6,7,7,7,8 = 24 has two solutions. One is 6*7*8/(7+7). What's the other one?
    Which of these do you like?

    6 / ((7 + 7) / 7) * 8 = 24 6 * 7 / ((7 + 7) / 8) = 24 ... 8 * 7 / ((7 + 7) / 6) = 24 8 / ((7 + 7) / 7 / 6) = 24

    Those are all duplicates of 6*7*8/(7+7). If you have X*Y/Z then you don't need Y/(Z/X). There is a very interesting alternative solution, but your solver unfortunately hasn't found it.

    I get 37 solutions using the least number of parenthesis for a given order of operators, is it not in this list?

    ... 7 / (7 / 6 - 7 / 8) = 24 ...

    I was pleased to find this solution too. But I no longer know what would pass Mr.'; Drop Database --'s test as "interesting". Is the solution really different? Using grade school maths to calculate the fraction:

    7 / (7/6 - 7/8) = 7 / ((78 - 76)/(68)) = 7 / ((72) / (68)) = 7(68) / (72) = 678 / (7+7)

  • JohnnyKnova (unregistered)
  • Stevenfaubs (unregistered)
    Comment held for moderation.
  • ppu-prof_Si (unregistered)

    Наша бригада искусных специалистов приготовлена предъявить вам перспективные средства, которые не только обеспечивают надежную охрану от холодильности, но и преподнесут вашему зданию изысканный вид. Мы практикуем с современными материалами, сертифицируя продолжительный срок службы работы и отличные результаты. Теплоизоляция нар&

Leave a comment on “Krypto and 24”

Log In or post as a guest

Replying to comment #:

« Return to Article