pluto41 Posted January 9, 2016 Share Posted January 9, 2016 For fun i wrote a little program to find solutions to this puzzle: https://www.youtube.com/watch?v=WiB2_dXSSMgI get 128 solutions in 18 minutes. (Windows XP, virtualized on a iMac). However there should be 136 solutions.I simplified the problem. See code below. Does anyone know whats going wrong here.expandcollapse popup#cs does compute $a = 1 $b = 2 $c = 6 $d = 4 $e = 7 $f = 8 $g = 3 $h = 5 $i = 9 #ce / does compute ;#cs does not Compute $a = 1 $b = 8 $c = 3 $d = 7 $e = 4 $f = 5 $g = 2 $h = 6 $i = 9 ;#ce / does not Compute Local $iSolution $iSolution = ( $a + (13 * $b / $c) + $d + (12 * $e) - $f - 11 + ($g * $h / $i) - 10 ) Msgbox ( 0, "calculates to", $iSolution ) If $iSolution = 66 Then MsgBox ( 0, "found = ", $iSolution ) Else Msgbox ( 0, "not found", $iSolution ) EndIf Link to comment Share on other sites More sharing options...
water Posted January 9, 2016 Share Posted January 9, 2016 After the calculation $iSolution is of type Double. It seems the calculation doesn't exactly return 66 (as an integer) but a floating point like 66.00000001 or whatever.If you know that the result always is an integer then the following script works as expected:#cs does compute $a = 1 $b = 2 $c = 6 $d = 4 $e = 7 $f = 8 $g = 3 $h = 5 $i = 9 #ce / does compute ;#cs does not Compute $a = 1 $b = 8 $c = 3 $d = 7 $e = 4 $f = 5 $g = 2 $h = 6 $i = 9 ;#ce / does not Compute Local $iSolution, $iTargetValue = 66 $iSolution = ($a + (13 * $b / $c) + $d + (12 * $e) - $f - 11 + ($g * $h / $i) - 10) $iSolution = Int($iSolution) MsgBox(0, "calculates to", $iSolution) If $iSolution = $iTargetValue Then MsgBox(0, "found = ", $iSolution) Else MsgBox(0, "not found", $iSolution) EndIf My UDFs and Tutorials: Spoiler UDFs:Active Directory (NEW 2022-02-19 - Version 1.6.1.0) - Download - General Help & Support - Example Scripts - WikiExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example ScriptsOutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - WikiOutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - DownloadOutlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - WikiPowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - WikiTask Scheduler (NEW 2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki Standard UDFs:Excel - Example Scripts - WikiWord - Wiki Tutorials:ADO - WikiWebDriver - Wiki Link to comment Share on other sites More sharing options...
water Posted January 9, 2016 Share Posted January 9, 2016 (edited) Here you see that the exact value is 65.000000000000008579...$a = 1 $b = 8 $c = 3 $d = 7 $e = 4 $f = 5 $g = 2 $h = 6 $i = 9 Local $iSolution = ($a + (13 * $b / $c) + $d + (12 * $e) - $f - 11 + ($g * $h / $i) - 10) MsgBox(0, "Difference of $iSolution - 66",$iSolution - 66) If $iSolution = 66 Then MsgBox(0, "found = ", $iSolution) Else MsgBox(0, "not found", $iSolution) EndIfThat's a result of the algorithm you use plus the internal representation of floating point numbers. Edited January 9, 2016 by water My UDFs and Tutorials: Spoiler UDFs:Active Directory (NEW 2022-02-19 - Version 1.6.1.0) - Download - General Help & Support - Example Scripts - WikiExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example ScriptsOutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - WikiOutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - DownloadOutlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - WikiPowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - WikiTask Scheduler (NEW 2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki Standard UDFs:Excel - Example Scripts - WikiWord - Wiki Tutorials:ADO - WikiWebDriver - Wiki Link to comment Share on other sites More sharing options...
pluto41 Posted January 9, 2016 Author Share Posted January 9, 2016 That indeed did the trick. I checked if it was a float and you are correct.Thanks Water for the explanation Link to comment Share on other sites More sharing options...
czardas Posted January 9, 2016 Share Posted January 9, 2016 You might like to take a look at operator64 in my signature. Whether replacing the mathematical operators with these functions will give the right result depends on a number of factors. operator64 ArrayWorkshop Link to comment Share on other sites More sharing options...
water Posted January 9, 2016 Share Posted January 9, 2016 Thanks Water for the explanation My UDFs and Tutorials: Spoiler UDFs:Active Directory (NEW 2022-02-19 - Version 1.6.1.0) - Download - General Help & Support - Example Scripts - WikiExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example ScriptsOutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - WikiOutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - DownloadOutlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - WikiPowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - WikiTask Scheduler (NEW 2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki Standard UDFs:Excel - Example Scripts - WikiWord - Wiki Tutorials:ADO - WikiWebDriver - Wiki Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now