KickStarter15 Posted November 24, 2018 Share Posted November 24, 2018 (edited) Hi Experts, Hope you're having a great day,. Once again, I need your support and help on this new task given to me. It's kind of new to me doing these computations from number to number (not my field). I have my sample code that do the plus and minus with the input numbers. From the input numbers example "123", I need to get only the last two numbers which is the "2" and "3". Then, from number "2", It should be able to get the minus -1 which would be the answer "1" then from the same number I need to get as well the answer of "3". Anyways, I have my sample scenario below. - Input is "123". - Get the last two numbers "2" and "3" from the input. - From number "2" should be able to get the below: 1 and 3 (which was deducted by 1 and added by 1 from number "2"). - From number "3" should be able to get the below: 2 and 4 (which was deducted by 1 and added by 1 from number "3"). - Combined generated output from "23" should be: "12" (computed by minus "-" from "23") "34" (computed by plus "+" from "23") "14" (computed by minus plus "-+" from "23") "32" (computed by plus minus "+-" from "23") Here's what I have so far and I only have one result. $TimeInput = InputBox("SeriesNumbers", "Enter your specified tracking number: ") $SecondNum = StringMid($TimeInput,2,1) +1 ; here is to add 1 $ThirdNum = StringRight($TimeInput,1) -1 ; here is to minus 1 If StringRight($TimeInput,1) = 0 Then $ThirdNum = "9" EndIf MsgBox(0,"test", "Input: " & $TimeInput & @CRLF & _ "Midle: " & $SecondNum & @CRLF & _ "Last: " & $ThirdNum & @CRLF & _ "Expected: " & $SecondNum & $ThirdNum) ; not sure how to continue using loop to get the combined numbers. Please let me know if you have any clarification/s Experts or suggestions for me to proceed. I posted my concern step by step cause I don't want to mashup my post. Thanks in advance Experts! KS15 Edited November 26, 2018 by KickStarter15 Programming is "To make it so simple that there are obviously no deficiencies" or "To make it so complicated that there are no obvious deficiencies" by C.A.R. Hoare. Link to comment Share on other sites More sharing options...
Subz Posted November 24, 2018 Share Posted November 24, 2018 You mean something like: #include <Array.au3> Local $sTimeInput = InputBox("SeriesNumbers", "Enter your specified tracking number: ") If @error Then Exit Local $aTimeInput = StringSplit($sTimeInput, "") If $aTimeInput[0] < 3 Then MsgBox(4096, "Input Error", "Number Length must be 3 or more") Local $aResults[4] $aResults[0] = ($aTimeInput[$aTimeInput[0] - 1] - 1) & ($aTimeInput[$aTimeInput[0]] - 1) $aResults[1] = ($aTimeInput[$aTimeInput[0] - 1] + 1) & ($aTimeInput[$aTimeInput[0]] + 1) $aResults[2] = ($aTimeInput[$aTimeInput[0] - 1] - 1) & ($aTimeInput[$aTimeInput[0]] + 1) $aResults[3] = ($aTimeInput[$aTimeInput[0] - 1] + 1) & ($aTimeInput[$aTimeInput[0]] - 1) _ArrayDisplay($aResults) Link to comment Share on other sites More sharing options...
mikell Posted November 24, 2018 Share Posted November 24, 2018 (edited) What should be the expected result if the last 2 numbers are 00, 90, 09, 99 ? Edit If the way to do must be the same than the one used in this thread , then the answer could be #include <Array.au3> Local $sTimeInput = "190" $aTimeInput = StringSplit($sTimeInput, "") $a = $aTimeInput[$aTimeInput[0] - 1] +10 $b = $aTimeInput[$aTimeInput[0]] + 10 Local $aResults[4] $aResults[0] = Mod($a-1, 10) & Mod($b-1, 10) $aResults[1] = Mod($a+1, 10) & Mod($b+1, 10) $aResults[2] = Mod($a-1, 10) & Mod($b+1, 10) $aResults[3] = Mod($a+1, 10) & Mod($b-1, 10) _ArrayDisplay($aResults) Edited November 24, 2018 by mikell KickStarter15 1 Link to comment Share on other sites More sharing options...
KickStarter15 Posted November 24, 2018 Author Share Posted November 24, 2018 Yaah right @mikell, if the last numbers are as what you given, example "09", then for "0" should be "9" and "1" mean minus and plus. And if "9" then it should have "8" and "0" means minus and plus. @Subz, Thanks for the quick response and sorry to misunderstood my post. The valid count is 0-9 only means (like mikell's question) if the last number contains 00, 90, 09 and 99. See below: if 00 is the last two numbers then answer should be "99"(--), "11"(++), "19"(+-) and "91"(-+). Subz and Mikell, the adding and subtracting from the input numbers well based on 0-9 only. Means, once it has number "9" then the next number should be "0" for the add 1 and "8" for the minus 1, and the same with if the number input is "0" then the next number should be "1" for the add 1 and "9" for the minus 1. Programming is "To make it so simple that there are obviously no deficiencies" or "To make it so complicated that there are no obvious deficiencies" by C.A.R. Hoare. Link to comment Share on other sites More sharing options...
mikell Posted November 24, 2018 Share Posted November 24, 2018 So my guess was correct - and the code in my previous post is adequate Link to comment Share on other sites More sharing options...
Malkey Posted November 24, 2018 Share Posted November 24, 2018 (edited) This example uses the first number entered to plus and minus and is not necessarily a one. Logically, if plus and minus one is always used then why have three numbers when two numbers only are needed. Then again, logic may have nothing to do with this. #include <Array.au3> Local $sTimeInput = "228" $aTI = StringSplit($sTimeInput, "") Local $aResults[4] $aResults[0] = Mod(10 + $aTI[2] - $aTI[1], 10) & Mod(10 + $aTI[3] - $aTI[1], 10) $aResults[1] = Mod(10 + $aTI[2] + $aTI[1], 10) & Mod(10 + $aTI[3] + $aTI[1], 10) $aResults[2] = Mod(10 + $aTI[2] - $aTI[1], 10) & Mod(10 + $aTI[3] + $aTI[1], 10) $aResults[3] = Mod(10 + $aTI[2] + $aTI[1], 10) & Mod(10 + $aTI[3] - $aTI[1], 10) _ArrayDisplay($aResults) And the same thing. #include <Array.au3> Local $sTimeInput = "228" ; "123" _ArrayDisplay(_NumCombine($sTimeInput)) Func _NumCombine($sInput) Local $aP_M[8] = [-1, -1, 1, 1, -1, 1, 1, -1] ; Plus or Minus Array Local $aTI = StringSplit($sInput, "") Local $aRet[UBound($aP_M) / 2] For $j = 0 To UBound($aP_M) - 1 Step 2 $aRet[$j / 2] = Mod(10 + $aTI[2] + $aTI[1] * $aP_M[$j], 10) & Mod(10 + $aTI[3] + $aTI[1] * $aP_M[$j + 1], 10) Next Return $aRet EndFunc ;==>_NumCombine Edited November 26, 2018 by Malkey Added second example. Link to comment Share on other sites More sharing options...
Aether Posted November 24, 2018 Share Posted November 24, 2018 I like what mikell did, really simple to understand the logic Link to comment Share on other sites More sharing options...
pixelsearch Posted November 24, 2018 Share Posted November 24, 2018 @Aether : your last icon seems a bit sarcastic lol I bet you'd like my logic if I entered the race with that kind of string : $sSoFun = chr(9) & "0123456789" & chr(0) Link to comment Share on other sites More sharing options...
KickStarter15 Posted November 26, 2018 Author Share Posted November 26, 2018 On 11/24/2018 at 5:16 PM, mikell said: So my guess was correct - and the code in my previous post is adequate Yeah... hehehe perfectly baked... thanks mikell. You've got what I need. Hmmm never thought for that and easily to understand. Programming is "To make it so simple that there are obviously no deficiencies" or "To make it so complicated that there are no obvious deficiencies" by C.A.R. Hoare. 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