Math solver formula

let’s say I have a text column with this input “4*10+2”
is there any to have the result in another column?

Are you going to have the exact same structure every time?

Meaning will it always be:
number*number+number

Nope, it must handle any number of addends and factors in any combination

Hmmmm ok. I think @Paul_Danyliuk might have had some way to do it utilizing his “black-magic” tricks.

There might also be a way to do it with some complex regex()/switchIf() formulas. So the short answer is yes, I believe its feasibly possible but not an easy route towards that end.

Any other geniuses on this community have ideas?

I think Max had it done earlier. It can indeed be done with black magic but only in a button, not a live formula for a column.

It is probably possible to build either an ASL or a shunting yard / stack machine impl in a formula for simple [a1*b1]+[a2*b2]+...+[aN*bN] polynomials if all that’s required is multiplication and addition, no brackets or other operators.

2 Likes

UPD: Here’s the solution for just the additions and multiplications:

The formula is:

thisRow.Expression.RegexReplace("\s", "").Split("+").FormulaMap(
  CurrentValue.Split("*").FormulaMap(CurrentValue.ToNumber()).Product()
).Sum()

where RegexReplace("\s", "") removes spaces within the expression, then we split it by additions to get numbers and sequences of multiplications, then for each of those pieces we split by multiplication sign and find a product, and finally sum all those together.

2 Likes

@Paul_Danyliuk, this is brilliant

well done sir

not a sparkle nor a whiff of dark magic in sight!

but unfortunately, i cant access the document, can you look at the permissions?

max

1 Like

Ugh sorry. Expert or not, I still fall victim to forgetting to set sharing settings :sweat_smile:

2 Likes

@Paul_Danyliuk, your clever trick inspired me to do this…

This table allows you to enter simple formulas and give then names so you can refer to those names as variables in other formulas.

Absolutely no Black Magic, Dark-Side Forces or Occultic Voodoo used at all! Just pure, clean, supported Coda formulas is all!

enjoy
Max

2 Likes

that is very clever @Xyzor_Max , thanks for sharing
certainly those who migrate from spreadsheets might benefit from this!
elegant is word, nice!

thisRow.Expression
  .Split('-').Join('+-')
  .Split('/').Join('*!')
  .Split('+').FormulaMap(
  CurrentValue.Split('*').FormulaMap(
    If(CurrentValue.StartsWith('!'),
      1/CurrentValue.Slice(2)
      ,CurrentValue)
  ).Product()
).Sum()