Looks like no one’s replied in a while. To start the conversation again, simply ask a new question.

[AppleScript]Can someone help me to complete this equation solver?

Hello, I am building a equation solver but I really need help. Example: x = (12+2)/2 ---------my solver can deal with this type of equation

Example2: 1+x = (12+2)/2-------------my solver cannot deal with this type of equation






display dialog "First part of the Equation" default answer ""

set oneEquation to text returned of result

display dialog "Second part of the Equation" default answer ""

set secondEquation to run script (text returned of result)



--The If/else block is in case the user enter 3x , for example


if oneEquation = "x" then

set x to secondEquation

else if oneEquation = "2x" then

set x to secondEquation / 2

else if oneEquation = "3x" then

set x to secondEquation / 3

else if oneEquation = "4x" then

set x to secondEquation / 4

else if oneEquation = "5x" then

set x to secondEquation / 5

else if oneEquation = "6x" then

set x to secondEquation / 6

else if oneEquation = "7x" then

set x to secondEquation / 7

else if oneEquation = "8x" then

set x to secondEquation / 8

else if oneEquation = "9x" then

set x to secondEquation / 9

else if oneEquation = "10x" then

set x to secondEquation / 10

end if

-- I know that there was probably a fastest way to write these numbers

if oneEquation contains 1 or 2 or 3 or 4 or 5 or 6 or 7 or 8 or 9 or 10 or 11 or 12 or 13 or 14 or 15 or 16 or 17 or 18 or 19 or 20 or 21 or 22 or 23 or 24 or 25 or 26 or 27 or 28 or 29 or 30 or 31 or 32 or 33 or 34 or 35 or 36 or 37 or 38 or 39 or 40 or 41 or 42 or 43 or 44 or 45 or 46 or 47 or 48 or 49 or 50 or 51 or 52 or 53 or 54 or 55 or 56 or 57 or 58 or 59 or 60 or 61 or 62 or 63 or 64 or 65 or 66 or 67 or 68 or 69 or 70 or 71 or 72 or 73 or 74 or 75 or 76 or 77 or 78 or 79 or 80 or 81 or 82 or 83 or 84 or 85 or 86 or 87 or 88 or 99 or 90 or 92 or 92 or 93 or 94 or 95 or 96 or 97 or 98 or 99 or 100 or 101 or 102 or 103 or 104 or 105 or 106 or 107 or 108 or 109 or 110 or 111 or 112 or 113 or 114 or 115 or 116 or 117 or 118 or 119 or 120 or 121 or 122 or 123 or 124 or 125 or 126 or 127 or 128 or 129 or 130 or 131 or 132 or 133 or 134 or 135 or 136 or 137 or 138 or 139 or 140 or 141 or 142 or 143 or 144 or 145 or 146 or 147 or 148 or 149 or 150 or 151 or 152 or 153 or 154 or 155 or 156 or 157 or 158 or 159 or 160 or 161 or 162 or 163 or 164 or 165 or 166 or 167 or 168 or 169 or 170 or 171 or 172 or 173 or 174 or 175 or 176 or 177 or 178 or 179 or 180 or 181 or 182 or 183 or 184 or 185 or 186 or 187 or 188 or 189 or 190 or 191 or 192 or 193 or 194 or 195 or 196 or 197 or 198 or 199 or 200 or 201 or 202 or 203 or 204 or 205 or 206 or 207 or 208 or 209 or 210 or 211 or 212 or 213 or 214 or 215 or 216 or 217 or 218 or 219 or 220 or 221 or 222 or 223 or 224 or 225 or 226 or 227 or 228 or 229 or 230 or 231 or 232 or 233 or 234 or 235 or 236 or 237 or 238 or 239 or 240 or 241 or 242 or 243 or 244 or 245 or 246 or 247 or 248 or 249 or 250 or 251 or 252 or 253 or 254 or 255

end

-- What can I do now in order to my solver be able to solve "x+1 =2 "



display dialog (x)

Mac mini

Posted on Jan 8, 2014 7:08 PM

Reply
2 replies

Jan 9, 2014 12:00 AM in response to Pira666

I think you dan grep and sed through "do shell scipt". Therefore you have access to regular expressions and you can simplify this considerably.


Perhaps you can use shell to process this sort of expressions as well ? Knowing you equations are linear it is ufficient to substitute x=0 to get the x-independent part. Then subtract from the equation lides evaluated for x=1 the x=0 value, and you have coefficient corresponding to x.

Jan 9, 2014 7:22 AM in response to Pira666

You are going to need to define exactly what you are looking to do. I'm no expert, but a general purpose expression evaluator like what I think you are talking about can involve hundreds of lines of code, which would not be AppleScript if you wanted to come out of it with any hair left.


For the second part, you can check for membership in a list (AppleScript doesn't have ranges), for example:

setxto3

if x is in {1, 2, 3, 4, 5, 6, 7, 8, 9, 10} then beep

[AppleScript]Can someone help me to complete this equation solver?

Welcome to Apple Support Community
A forum where Apple customers help each other with their products. Get started with your Apple ID.