Register

If this is your first visit, please click the Sign Up now button to begin the process of creating your account so you can begin posting on our forums! The Sign Up process will only take up about a minute of two of your time.

Results 1 to 2 of 2
  1. #1
    Member
    Join Date
    Dec 2004
    Posts
    67
    Member #
    8452
    Liked
    1 times
    I have a krypto solver, and I wanted to know the easiest way to print out all unsolvable kryptos from 1-50 with no double numbers. Kryptos work like this:

    A B C D E
    F

    You can use each of letters A-E once to create letter F. For example:

    1 2 3 4 5
    15

    The krypto solver would output this:
    5 + 4 = 9
    9 + 3 = 12
    12 + 2 = 14
    14 + 1 = 15

    If there are no answers it just doesn't output anything except the normal "There are _ solutions" which is 0. Is there any way to print out every unsolvable krypto 1-50 with no double numbers (so 1 1 1 1 1 = 1 wouldn't work, neither would 1 2 3 4 5 = 4) here is the code (modded by me for exponents, originally made by snurgle.org):
    PHP Code:
    $opError 0;
    $found "";
    $count=0;
    $operands = array("+""-""*""/""^");
    $calculate 1;

    function 
    applyOperation($cOp$fA$fB){
        global 
    $opError;
        
    $opError 0;

        switch(
    $cOp){
            case 
    "^":
            
    $ex $fA;
                 while (
    $fB>1)
                 {
                  
    $ex = ($fA*$ex);
                  
    $fB--;
                 }
                
    $fRet $ex;      break;
            case 
    "*":
                
    $fRet $fA $fB;  break;
            case 
    "/":
            if(
    $fB){
            
    $fRet $fA $fB;
            if(
    $fRet != floor($fRet)){
                
    $opError 1;
            }
            }
            else{
            
    $fRet 0;
            
    $opError 1;
            }
            break;
            case 
    "+":
                
    $fRet $fA $fB; break;
        case 
    "-":
            
    $fRet $fA $fB; break;
          default:
            print 
    "Err: Operation '$cOp' not recognized<br>\n";
            
    $fRet 0;
            break;
        }
        return 
    $fRet;
    }


    # count the number of POSTed variables, minus the submit button
    $inputs count($HTTP_POST_VARS);

    $values["Num1"] =  preg_replace("/[^0-9]/"""$HTTP_POST_VARS["Num1"]);  
    $values["Num2"] =  preg_replace("/[^0-9]/"""$HTTP_POST_VARS["Num2"]);  
    $values["Num3"] =  preg_replace("/[^0-9]/"""$HTTP_POST_VARS["Num3"]);
    $values["Num4"] =  preg_replace("/[^0-9]/"""$HTTP_POST_VARS["Num4"]);  
    $values["Num5"] =  preg_replace("/[^0-9]/"""$HTTP_POST_VARS["Num5"]);  
    $solution =  preg_replace("/[^0-9]/"""$HTTP_POST_VARS["Solution"]);  
    $find_all $HTTP_POST_VARS["FindAll"];


    # look for post'ed data
    if($values["Num1"] == "" ||
       
    $values["Num2"] == "" ||
       
    $values["Num3"] == "" ||
       
    $values["Num4"] == "" ||
       
    $values["Num5"] == "" ||
       
    $solution == ""){

        
    # incomplete or no posted data.
        
    if($inputs != 0){
        
    # they entered some data, but not all
        
    print "<p><i>Didn't get complete numeric data. Try again</i></p>\n";
        }
        print 
    "<h2 align=center>Enter the 5 numbers and the solution below</h2>\n";
        
    $calculate 0;
    }

    print 
    "<center>\n";
    print 
    "  <form action='./krypto.php' method='post'>\n";
    print 
    "    <INPUT type=text value='$values[Num1]' name='Num1' size='3'>\n";
    print 
    "    <INPUT type=text value='$values[Num2]' name='Num2' size='3'>\n";
    print 
    "    <INPUT type=text value='$values[Num3]' name='Num3' size='3'>\n";
    print 
    "    <INPUT type=text value='$values[Num4]' name='Num4' size='3'>\n";
    print 
    "    <INPUT type=text value='$values[Num5]' name='Num5' size='3'>\n";
    print 
    "      =?\n";
    print 
    "    <INPUT type=text value='$solution' name='Solution' size='3'>\n";
    print 
    "    <INPUT NAME='submit' TYPE='SUBMIT' VALUE='Calculate'><br>\n";
    print 
    "    <INPUT type=checkbox name='FindAll'";
    if(
    $find_all)
        print 
    " CHECKED";
    print 
    ">Find all solutions (takes longer)\n";
    print 
    "  </form>\n";
    print 
    "</center>\n";


    if(
    $calculate)
    {
        
    # got complete, calculate possible solution
        # use decimals?  Does this work in the form?
        
    foreach($values as $valName1 => $val1){
        foreach(
    $operands as $opName1 => $op1){
            foreach(
    $values as $valName2 => $val2){
            if(
    $valName2 == $valName1)
                continue;
            foreach(
    $operands as $opName2 => $op2){
                foreach(
    $values as $valName3 => $val3){
                if(
    $valName3 == $valName1 ||
                   
    $valName3 == $valName2)
                    continue;
                foreach(
    $operands as $opName3 => $op3){
                    foreach(
    $values as $valName4 => $val4){
                    if(
    $valName4 == $valName1 ||
                       
    $valName4 == $valName2 ||
                       
    $valName4 == $valName3)
                        continue;
                    foreach(
    $operands as $opName4 => $op4){
                        foreach(
    $values as $valName5 => $val5){
                        if(
    $valName5 == $valName1 ||
                           
    $valName5 == $valName2 ||
                           
    $valName5 == $valName3 ||
                           
    $valName5 == $valName4)
                            continue;
                        
    $res1 applyOperation($op4$val5$val4);
                        if(
    $opError) continue;
                        
    $res2 applyOperation($op3$res1$val3);
                        if(
    $opError) continue;
                        
    $res3 applyOperation($op2$res2$val2);
                        if(
    $opError) continue;
                        
    $res4 applyOperation($op1$res3$val1);
                        if(
    $opError) continue;
                        if(
    $solution == $res4){
                            
    $count++;
                            if(
    $find_all){
                            print 
    "Solution: (((" $val5 " " $op4 " " $val4 ") " .
                                
    $op3 " " $val3 ") " $op2 " " $val2 ") " $op1 " " $val1 "<br>\n";
                            }
                            else{
                            
    # print out a nicer looking solution, since we are only going to print one
                            
    if($count == 1){
                                print 
    "One solution is:<br>\n";
                                print 
    $val5 " " $op4 " " $val4 " = " $res1 "<br>\n";
                                print 
    $res1 " " $op3 " " $val3 " = " $res2 "<br>\n";
                                print 
    $res2 " " $op2 " " $val2 " = " $res3 "<br>\n";
                                print 
    $res3 " " $op1 " " $val1 " = " $res4 "<br>\n";
                            }
                            break;
                            }
                        }
                        }
                        if(!
    $find_all && $count) break;
                    }
                    if(!
    $find_all && $count) break;
                    }
                    if(!
    $find_all && $count) break;
                }
                if(!
    $find_all && $count) break;
                }
                if(!
    $find_all && $count) break;
            }
            if(!
    $find_all && $count) break;
            }
            if(!
    $find_all && $count) break;
        }
        if(!
    $find_all && $count) break;
        }

        if(!
    $count || $find_all){
        print 
    "Found " $count " solutions.";
        }

    Brian : This must be the physics department.
    Chris : That explains all the gravity.

  2.  

  3. #2
    WDF Staff Wired's Avatar
    Join Date
    Apr 2003
    Posts
    7,672
    Member #
    1234
    Liked
    142 times
    Sounded familiar, had to look it up, I've played the + - X / version in puzzle books in square form.

    http://www.math.niu.edu/~rusin/uses-math/games/krypto/
    http://mphgames.com/krypto/index.htm

    Those links may help. Your code seems bulky to me, although that may be because it's 5:30 AM and I'm tired
    The Rules
    Was another WDF member's post helpful? Click the like button below the post.

    Admin at houseofhelp.com


Remove Ads

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  

Search tags for this page

krypto solutions unsolvable series
,
math krypto solver using decimals
,

unsolvable krypto

Click on a term to search for related topics.
All times are GMT -6. The time now is 10:19 AM.
Powered by vBulletin® Version 4.2.3
Copyright © 2021 vBulletin Solutions, Inc. All rights reserved.
vBulletin Skin By: PurevB.com