public EqualinationRes calcRegularEqualinationFromText(string sideOne, string sideTwo) { SmallEqualination sideOneSymbols = getSmallerEqualinationFromText(sideOne); SmallEqualination sideTwoSymbols = getSmallerEqualinationFromText(sideTwo); return(calcRegularEqualinationFromSymbols(sideOneSymbols, sideTwoSymbols)); }
private SmallEqualination getAfterIndexOnePart(List <Symbol> symbols, ref int endPIndex) { if (endPIndex >= symbols.Count - 1) { return(new SmallEqualination(1, new List <decimal>())); } SmallEqualination res = new SmallEqualination(1, new List <decimal>()); int count = 0; int parenthessis = 0; //get the after numbers for (; endPIndex <= symbols.Count - 1; endPIndex++) { if (symbols[endPIndex].Kind == Symbol.SymbolKinds.parenthesisStart) { parenthessis++; } else if (symbols[endPIndex].Kind == Symbol.SymbolKinds.parenthesisEnd) { parenthessis--; } else if (parenthessis == 0 && (symbols[endPIndex].Kind == Symbol.SymbolKinds.minus || symbols[endPIndex].Kind == Symbol.SymbolKinds.plus || symbols[endPIndex].Kind == Symbol.SymbolKinds.divide || symbols[endPIndex].Kind == Symbol.SymbolKinds.power)) { break; } count++; } if (count > 0) { SmallEqualination smallEqualinationRes = getSmallerEqualinationFromSymbols(symbols.GetRange(endPIndex - count, count), false); res = multiplayTwoSmallEqualinations(res, smallEqualinationRes); } return(res); }
public List <Symbol> getSymbolsFromSmallEqualination(SmallEqualination smallEqualination) { List <Symbol> res = new List <Symbol>(); //add the number if (smallEqualination.Num != 0) { res.Add(new Symbol(Symbol.SymbolKinds.number, smallEqualination.Num)); } //add the x list for (int i = 0; i <= smallEqualination.XList.Count - 1; i++) { if (smallEqualination.XList[i] != 0) { if (res.Count != 0) { res.Add(new Symbol(Symbol.SymbolKinds.plus)); } res.Add(new Symbol(Symbol.SymbolKinds.x, smallEqualination.XList[i], i + 1)); } } return(res); }
private SmallEqualination getBeforeAndAfterOnePart(List <Symbol> symbols, ref int startPIndex, ref int endPIndex) { SmallEqualination res = new SmallEqualination(1, new List <decimal>()); res = multiplayTwoSmallEqualinations(res, getBeforeIndexOnePart(symbols, ref startPIndex)); res = multiplayTwoSmallEqualinations(res, getAfterIndexOnePart(symbols, ref endPIndex)); return(res); }
private SmallEqualination getBeforeIndexOnePart(List <Symbol> symbols, ref int startPIndex) { if (startPIndex == 0) { return(new SmallEqualination(1, new List <decimal>())); } //startPIndex--; SmallEqualination res = new SmallEqualination(1, new List <decimal>()); /*if (symbols[startPIndex].Kind == Symbol.SymbolKinds.number) * { * res.Num = symbols[startPIndex].Num; * } * else if (symbols[startPIndex].Kind == Symbol.SymbolKinds.x) * { * res.XList = addXToTheList(symbols[startPIndex], new List<decimal>()); * }*/ int count = 0; int parenthessis = 0; int addSymbol = 0; //get the before numbers for (; startPIndex > 0; startPIndex--) { if (symbols[startPIndex].Kind == Symbol.SymbolKinds.parenthesisEnd) { parenthessis++; } else if (symbols[startPIndex].Kind == Symbol.SymbolKinds.parenthesisStart) { parenthessis--; } else if (parenthessis == 0) { if (symbols[startPIndex].Kind == Symbol.SymbolKinds.minus) { addSymbol = 1; startPIndex++; break; } else if (symbols[startPIndex].Kind == Symbol.SymbolKinds.plus || symbols[startPIndex].Kind == Symbol.SymbolKinds.divide) { startPIndex++; break; } } count++; } if (count > 0) { SmallEqualination smallEqualinationRes = getSmallerEqualinationFromSymbols(symbols.GetRange(startPIndex - addSymbol, count + addSymbol), false); res = multiplayTwoSmallEqualinations(res, smallEqualinationRes); } return(res); }
private void addToRes(ref SmallEqualination res, Symbol symbol) { if (symbol.Kind == Symbol.SymbolKinds.number) { res.Num += symbol.Num; } else if (symbol.Kind == Symbol.SymbolKinds.x) { res.XList = addXToTheList(symbol, res.XList); } }
private void addSmallEqualinationToListSymbols(ref List <Symbol> res, SmallEqualination smallEqualination) { if (smallEqualination.Num != 0) { res.Add(new Symbol(Symbol.SymbolKinds.number, smallEqualination.Num)); } for (int i = 0; i <= smallEqualination.XList.Count - 1; i++) { if (smallEqualination.XList[i] != 0) { res.Add(new Symbol(Symbol.SymbolKinds.x, smallEqualination.XList[i], i + 1)); } } }
public SmallEqualination getSmallerEqualinationFromText(string text) { error = false; //start solving //get a list of the numbers from the string List <Symbol> symbols = getAListOfNumbersFromString(text); //calc the list of numbers SmallEqualination res = getSmallerEqualinationFromSymbols(symbols, true); //show the answer return(res); }
private void calcParenthessis(ref List <Symbol> symbols) { //check for parenthessis start and if finds check where is the end and then calcs it for (int i = 0; i <= symbols.Count - 1; i++) { if (symbols[i].Kind == Symbol.SymbolKinds.parenthesisStart) { int start = i; int end = i + 1; int count = 0; int parenthessisStart = 0; //check where it ends for (int j = i + 1; j <= symbols.Count - 1; j++) { if (symbols[j].Kind == Symbol.SymbolKinds.parenthesisStart) { parenthessisStart++; } else if (symbols[j].Kind == Symbol.SymbolKinds.parenthesisEnd) { if (parenthessisStart == 0) { //calc the parenthessis and before and after multiplay SmallEqualination res = getSmallerEqualinationFromSymbols(symbols.GetRange(start + 1, count), false); end = start + count + 2; res = multiplayTwoSmallEqualinations(res, getBeforeAndAfterOnePart(symbols, ref start, ref end)); //remove all the parenthessis and put the res symbols.RemoveRange(start, end - start); //putt the res //symbols[start].Kind = Symbol.SymbolKinds.number; //symbols[start].Num = res; symbols.InsertRange(start, getSymbolsFromSmallEqualination(res)); j = symbols.Count - 1; } else { parenthessisStart--; } } count++; } } } }
private void drawTheLastFunc() { draw.drawBasicTable(zoomTrackBar.Value);//50*50 //draw.addToDraw(calc.getSymbolsFromSmallEqualination(calc.getSmallerEqualinationFromText(lastFunc)), (float)0.1); calc.error = false; SmallEqualination symbols = calc.getSmallerEqualinationFromText(lastFunc); if (!calc.error) { draw.addToDraw(calc.getSymbolsFromSmallEqualination(symbols), (float)0.1); } else { lastFunc = ""; wasAnError(); } }
private EqualinationRes calcRegularEqualinationFromSymbols(SmallEqualination sideOne, SmallEqualination sideTwo) { SmallEqualination smallRes = subtractTwoSmallEqualinations(sideOne, sideTwo); //check what kind of equalination is it EqualinationRes res = new EqualinationRes(); if (smallRes.XList.Count == 1) //regular equlination { res.Results.Add((-smallRes.Num) / smallRes.XList[0]); } else if (smallRes.XList.Count == 2) { return(rootFormula(smallRes.XList[1], smallRes.XList[0], smallRes.Num)); } else { res.cantSolve = true; } return(res); }
private SmallEqualination subtractTwoSmallEqualinations(SmallEqualination one, SmallEqualination two) { if (one.XList.Count > two.XList.Count) { one.Num -= two.Num; for (int i = 0; i <= two.XList.Count - 1; i++) { one.XList[i] -= two.XList[i]; } return(one); } else { two.Num -= one.Num; for (int i = 0; i <= one.XList.Count - 1; i++) { two.XList[i] -= one.XList[i]; } return(two); } }
private SmallEqualination multiplayTwoSmallEqualinations(SmallEqualination one, SmallEqualination two) { List <Symbol> res = new List <Symbol>(); List <Symbol> oneSymbol = getSymbolsFromSmallEqualination(one); List <Symbol> twoSymbol = getSymbolsFromSmallEqualination(two); for (int i = 0; i <= oneSymbol.Count - 1; i++) { for (int j = 0; j <= twoSymbol.Count - 1; j++) { if (res.Count != 0) { res.Add(new Symbol(Symbol.SymbolKinds.plus)); } res.Add(getSymbolFromMultiplay(oneSymbol[i], twoSymbol[j])); } } return(calcPlusAndMinus(res)); }
private SmallEqualination calcPlusAndMinus(List <Symbol> symbols) { SmallEqualination res = new SmallEqualination(); if (symbols.Count == 0) { return(res); } //check for minus or plus in the start if (symbols[0].Kind == Symbol.SymbolKinds.minus) { symbols[1].Num = -symbols[1].Num; symbols.RemoveAt(0); } else if (symbols[0].Kind == Symbol.SymbolKinds.plus) { symbols.RemoveAt(0); } //get the number in start addToRes(ref res, symbols[0]); //check for a plus or minus sign and if finds calcs it for (int i = 1; i <= symbols.Count - 2; i++) { if (symbols[i].Kind == Symbol.SymbolKinds.plus) { addToRes(ref res, symbols[i + 1]); } else if (symbols[i].Kind == Symbol.SymbolKinds.minus) { subtractRes(ref res, symbols[i + 1]); } } return(res); }
private List <Symbol> getDevideSymbols(List <Symbol> symbols, int i, ref int startIndex, ref int endIndex) { List <Symbol> res = new List <Symbol>(); //get the before index res.Add(new Symbol(Symbol.SymbolKinds.parenthesisStart)); startIndex = i - 1; SmallEqualination beforeRes = getBeforeIndexOnePart(symbols, ref startIndex); addSmallEqualinationToListSymbols(ref res, beforeRes); res.Add(new Symbol(Symbol.SymbolKinds.parenthesisEnd)); res.Add(new Symbol(Symbol.SymbolKinds.divide)); //get the after index res.Add(new Symbol(Symbol.SymbolKinds.parenthesisStart)); endIndex = i + 1; SmallEqualination afterRes = getBeforeIndexOnePart(symbols, ref endIndex); addSmallEqualinationToListSymbols(ref res, afterRes); res.Add(new Symbol(Symbol.SymbolKinds.parenthesisEnd)); return(res); }
private void subtractRes(ref SmallEqualination res, Symbol symbol) { symbol.Num = -symbol.Num; addToRes(ref res, symbol); }