private decimal ProcessOperation(string operation) //222222222222222 { ArrayList arr = new ArrayList(); string s = ""; for (int i = 0; i < operation.Length; i++) { string currentCharacter = operation.Substring(i, 1); if (OperationOrder.IndexOf(currentCharacter) > -1) { if (s != "") { arr.Add(s); } arr.Add(currentCharacter); s = ""; } else { s += currentCharacter; } } arr.Add(s); s = ""; foreach (string op in OperationOrder) { while (arr.IndexOf(op) > -1) { int operatorIndex = arr.IndexOf(op); if (arr.Count > 2) { if (operatorIndex > 0) { decimal digitBeforeOperator = Convert.ToDecimal(arr[operatorIndex - 1]); decimal digitAfterOperator = 0; if (arr[operatorIndex + 1].ToString() == "-") { arr.RemoveAt(operatorIndex + 1); digitAfterOperator = Convert.ToDecimal(arr[operatorIndex + 1]) * -1; } else { digitAfterOperator = Convert.ToDecimal(arr[operatorIndex + 1]); } arr[operatorIndex] = CalculateByOperator(digitBeforeOperator, digitAfterOperator, op); arr.RemoveAt(operatorIndex - 1); arr.RemoveAt(operatorIndex); } } else { arr.RemoveAt(operatorIndex); } } } return(Convert.ToDecimal(arr[0])); }
public void TestPart1() { Assert.AreEqual(71, OperationOrder.CalculateLineForPartOne("1 + 2 * 3 + 4 * 5 + 6")); Assert.AreEqual(51, OperationOrder.CalculateLineForPartOne("1 + (2 * 3) + (4 * (5 + 6))")); Assert.AreEqual(26, OperationOrder.CalculateLineForPartOne("2 * 3 + (4 * 5)")); Assert.AreEqual(437, OperationOrder.CalculateLineForPartOne("5 + (8 * 3 + 9 + 3 * 4 * 3)")); Assert.AreEqual(12240, OperationOrder.CalculateLineForPartOne("5 * 9 * (7 * 3 * 3 + 9 * 3 + (8 + 6 * 4))")); Assert.AreEqual(13632, OperationOrder.CalculateLineForPartOne("((2 + 4 * 9) * (6 + 9 * 8 + 6) + 6) + 2 + 4 * 2")); }
private static long ComputeFlatEquation(string equation, OperationOrder order) { equation = Regex.Replace(equation, @"\s+", ""); Operation operation = new Operation(); operation.Parse(equation, order); var result = operation.Solve(); return(result); }
static void Main(string[] args) { var days = new List <IDay>() { ExpenseReport.LoadFromFile("Day01/ExpenseReport.txt"), PasswordValidator.LoadFromFile("Day02/Passwords.txt"), Map.LoadFromFile("Day03/Map.txt"), PassportValidator.LoadFromFile("Day04/PassportData.txt"), BoardingPasses.LoadFromFile("Day05/Seats.txt"), Declerations.LoadFromFile("Day06/Declerations.txt"), LuggageRules.LoadFromFile("Day07/LuggageRules.txt"), GameConsole.LoadFromFile("Day08/BootCode.txt"), AdditionSystem.LoadFromFile("Day09/Data.txt"), JoltAdapters.LoadFromFile("Day10/JoltAdapters.txt"), SeatingLayout.LoadFromFile("Day11/SeatingLayout.txt"), Navigation.LoadFromFile("Day12/NavigationInstructions.txt"), Buses.LoadFromFile("Day13/Buses.txt"), DockingProgram.LoadFromFile("Day14/DockingProgram.txt"), MemoryGame.Create("15,12,0,14,3,1"), TicketAnalyser.LoadFromFile("Day16/TicketData.txt"), ConwayCube.LoadFromFile("Day17/ConwayCube.txt"), OperationOrder.LoadFromFile("Day18/Expressions.txt"), JurassicJigsaw.LoadFromFile("Day20/Tiles.txt"), Combat.LoadFromFile("Day22/Cards.txt") }; var invalidCount = 0; foreach (var day in days) { var part1 = day.Part1(); var part2 = day.Part2(); var part1Invalid = !string.IsNullOrWhiteSpace(day.ValidatedPart1) && part1 != day.ValidatedPart1; var part2Invalid = !string.IsNullOrWhiteSpace(day.ValidatedPart2) && part2 != day.ValidatedPart2; invalidCount += part1Invalid ? 1 : 0; invalidCount += part2Invalid ? 1 : 0; var part1InvalidString = part1Invalid ? " INVALID" : ""; var part2InvalidString = part2Invalid ? " INVALID" : ""; Console.WriteLine($"Day {day.DayNumber} Part 1: {part1}{part1InvalidString}"); Console.WriteLine($"Day {day.DayNumber} Part 2: {part2}{part2InvalidString}"); } Console.WriteLine($"{invalidCount} INVALID Results"); }
public void ConnectAndDisconnect(string connectSpec, string disconnectSpec, MulticonnectMode multiconnectMode, OperationOrder operationOrder, bool waitForDebounce) { ushort localWaitForDebounce = waitForDebounce ? IVIConstants.VI_TRUE : IVIConstants.VI_FALSE; TestForError( niSE_ConnectAndDisconnect( _sessionHandle, connectSpec, disconnectSpec, (int)multiconnectMode, (int)operationOrder, localWaitForDebounce)); }
public void ConnectAndDisconnect(string connectSpec, string disconnectSpec, MulticonnectMode multiconnectMode, OperationOrder operationOrder, bool waitForDebounce) { }
public decimal Calculate(string Formula) //111111111111111 { try { string[] arr = Formula.Split("/+-*()^".ToCharArray(), StringSplitOptions.RemoveEmptyEntries); foreach (KeyValuePair <Microsoft.Office.Interop.Excel.Parameters, decimal> de in _Parameters) { foreach (string s in arr) { if (s != de.Key.ToString() && s.EndsWith(de.Key.ToString())) { Formula = Formula.Replace(s, (Convert.ToDecimal(s.Replace(de.Key.ToString(), "")) * de.Value).ToString()); } } Formula = Formula.Replace(de.Key.ToString(), de.Value.ToString()); } while (Formula.LastIndexOf("(") > -1) { int lastOpenPhrantesisIndex = Formula.LastIndexOf("("); int firstClosePhrantesisIndexAfterLastOpened = Formula.IndexOf(")", lastOpenPhrantesisIndex); decimal result = ProcessOperation(Formula.Substring(lastOpenPhrantesisIndex + 1, firstClosePhrantesisIndexAfterLastOpened - lastOpenPhrantesisIndex - 1)); bool AppendAsterix = false; if (lastOpenPhrantesisIndex > 0) { if (Formula.Substring(lastOpenPhrantesisIndex - 1, 1) != "(" && !OperationOrder.Contains(Formula.Substring(lastOpenPhrantesisIndex - 1, 1))) { AppendAsterix = true; } } Formula = Formula.Substring(0, lastOpenPhrantesisIndex) + (AppendAsterix ? "*" : "") + result.ToString() + Formula.Substring(firstClosePhrantesisIndexAfterLastOpened + 1); } return(ProcessOperation(Formula)); } catch (Exception ex) { throw new Exception("Error Occured While Calculating. Check Syntax", ex); } }
/// <summary> /// Seeds the specified context. /// </summary> /// <param name="context">The context.</param> protected override void Seed(PpmmContext context) { #region InitializeShifts Shift waterJetShift = new Shift { Name = "Water Jet Shift", Code = "B01" }; Shift uniponyShift = new Shift { Name = "Unipony Shift", Code = "B02" }; Shift radilDrillBredaShift = new Shift { Name = "Radial Drill Breda Shift", Code = "B03" }; Shift machiningInspectionShift = new Shift { Name = "Machining Inspection Shift", Code = "B04" }; Shift sawDustShift = new Shift { Name = "Sawdust Shift", Code = "B05" }; Shift metalJoineryShift = new Shift { Name = "Metal Joinery Shift", Code = "B06" }; context.Shifts.Add(waterJetShift); context.Shifts.Add(uniponyShift); context.Shifts.Add(radilDrillBredaShift); context.Shifts.Add(machiningInspectionShift); context.Shifts.Add(sawDustShift); context.Shifts.Add(metalJoineryShift); #endregion #region InitializeProductGenuses ProductGenus missileProductType = new ProductGenus { Name = "Missile" }; ProductGenus radarProductType = new ProductGenus { Name = "Radar" }; ProductGenus weaponProductType = new ProductGenus { Name = "Weapon" }; ProductGenus attachableWeaponProductType = new ProductGenus { Name = "Attachable Weapon", Parent = weaponProductType }; context.ProductGenus.Add(missileProductType); context.ProductGenus.Add(radarProductType); context.ProductGenus.Add(weaponProductType); context.ProductGenus.Add(attachableWeaponProductType); #endregion #region InitializeProducts Product akashProduct = new Product { Name = "Akash", ProductGenus = missileProductType, StockCode = "ABC1230" }; Product asterProduct = new Product { Name = "Aster", ProductGenus = missileProductType, StockCode = "ABC1231" }; Product mim3nikeAjaxProduct = new Product { Name = "MIM-3 Nike Ajax", ProductGenus = missileProductType, StockCode = "ABC1232" }; Product rim2terrierProduct = new Product { Name = "RIM-2 Terrier", ProductGenus = missileProductType, StockCode = "ABC1233" }; Product sa1guildProduct = new Product { Name = "SA-1 Guild", ProductGenus = missileProductType, StockCode = "ABC1234" }; Product rolandProduct = new Product { Name = "MIM-115 Roland", ProductGenus = missileProductType, StockCode = "ABC1235" }; Product seaWolfProduct = new Product { Name = "Sea Wolf", ProductGenus = missileProductType, StockCode = "ABC1236" }; context.Products.Add(akashProduct); context.Products.Add(asterProduct); context.Products.Add(mim3nikeAjaxProduct); context.Products.Add(rim2terrierProduct); context.Products.Add(sa1guildProduct); context.Products.Add(rolandProduct); context.Products.Add(seaWolfProduct); #endregion #region InitializeResources #endregion #region InitializeOperations Operation waterJetOperation = new Operation { Definition = "WATER JET (FLOW)", ProcessSpan = new TimeSpan(2, 15, 0), Shift = waterJetShift }; Operation uniponyMillOperation = new Operation { Definition = "UNIPONY MILL", ProcessSpan = new TimeSpan(1, 0, 0), Shift = uniponyShift }; Operation radialDrillBredaOperation = new Operation { Definition = "RADIAL DRILL BREDA I (BIG)", ProcessSpan = new TimeSpan(1, 30, 0), Shift = radilDrillBredaShift }; Operation machiningInspectionOperation = new Operation { Definition = "MACHINING INSPECTION", ProcessSpan = new TimeSpan(3, 0, 0), Shift = machiningInspectionShift }; context.Operations.Add(waterJetOperation); context.Operations.Add(uniponyMillOperation); context.Operations.Add(radialDrillBredaOperation); context.Operations.Add(machiningInspectionOperation); #endregion #region InitializeWorks Work keepingPlateWork = new Work { Note = "", Product = mim3nikeAjaxProduct, Title = "PLATE, CONVERSATIVE ATALETSEL NAVIGATION SYSTEM", Operations = new List <Operation>() { waterJetOperation, radialDrillBredaOperation, uniponyMillOperation, machiningInspectionOperation } }; context.Works.Add(keepingPlateWork); #endregion #region InitializeWorkOrders WorkOrder keepingPlateWorkOrder = new WorkOrder { DeliveryDate = DateTime.Now.AddDays(67), Number = "123456", Quantity = 1, StateType = Model.Enumerations.WorkStateType.Waiting, Work = keepingPlateWork }; context.WorkOrders.Add(keepingPlateWorkOrder); #endregion #region InitializeWorkOrders OperationOrder keepingPlateWorkOrder1 = new OperationOrder { Operation = waterJetOperation, Work = keepingPlateWork, Order = 1 }; OperationOrder keepingPlateWorkOrder2 = new OperationOrder { Operation = uniponyMillOperation, Work = keepingPlateWork, Order = 2 }; OperationOrder keepingPlateWorkOrder3 = new OperationOrder { Operation = radialDrillBredaOperation, Work = keepingPlateWork, Order = 3 }; OperationOrder keepingPlateWorkOrder4 = new OperationOrder { Operation = machiningInspectionOperation, Work = keepingPlateWork, Order = 4 }; context.OperationOrders.Add(keepingPlateWorkOrder1); context.OperationOrders.Add(keepingPlateWorkOrder2); context.OperationOrders.Add(keepingPlateWorkOrder3); context.OperationOrders.Add(keepingPlateWorkOrder4); #endregion base.Seed(context); }