public object PartOne(string input) { var ds = (from dx in new[] { -1, 0, 1 } from dy in new[] { -1, 0, 1 } from dz in new[] { -1, 0, 1 } where dx != 0 || dy != 0 || dz != 0 select(dx, dy, dz)).ToArray(); return(Solve( input, (x, y) => (x: x, y: y, z: 0), (p) => ds.Select(d => (p.x + d.dx, p.y + d.dy, p.z + d.dz)))); }
/// <summary> /// Base constructor for a Project Euler problem. /// </summary> /// <param name="num">The problem number.</param> /// /// <param name="title">The title of the problem.</param> /// <param name="input">True if the problem has an associated input file and false otherwise.</param> /// <param name="solMethod">Method used to solve the problem.</param> public ProjectEulerProblem(uint num, string title, bool input, Solve solMethod) { this.myTitle = title; this.problemNumber = num; this.requiresInputFile = input; this.solutionMethod = solMethod; }
public void AI() { int side = boat.GetBoatSign() == 1 ? 0 : 1; LandModel land = side == 0 ? start_land : end_land; int p = (start_land.GetRoleNum())[0] + (1 - side) * (boat.GetRoleNumber())[0]; int d = (start_land.GetRoleNum())[1] + (1 - side) * (boat.GetRoleNumber())[1]; SolverState cur_state = new SolverState(p, d, side); SolverState next_state = Solve.solve(cur_state); int move_p = next_state.p - p > 0 ? next_state.p - p : p - next_state.p; int move_d = next_state.d - d > 0 ? next_state.d - d : d - next_state.d; while (move_p < boat.GetRoleNumber()[0]) { MoveRole(boat.GetRoleByType(0)); return; } while (move_d < boat.GetRoleNumber()[1]) { MoveRole(boat.GetRoleByType(1)); return; } while (move_p > boat.GetRoleNumber()[0]) { MoveRole(land.GetRoleByType(0)); return; } while (move_d > boat.GetRoleNumber()[1]) { MoveRole(land.GetRoleByType(1)); return; } MoveBoat(); }
static void Main(string[] args) { Solve cars = new Solve(); int n = int.Parse(Console.ReadLine()); for (int i = 0; i < n; i++) { string[] tokens = Console.ReadLine().Split(); List <Tire> temp = new List <Tire>(); temp.Add(new Tire(decimal.Parse(tokens[5]), int.Parse(tokens[6]))); temp.Add(new Tire(decimal.Parse(tokens[7]), int.Parse(tokens[8]))); temp.Add(new Tire(decimal.Parse(tokens[9]), int.Parse(tokens[10]))); temp.Add(new Tire(decimal.Parse(tokens[11]), int.Parse(tokens[12]))); cars.AddCars(new Car(tokens[0] , new Engine(int.Parse(tokens[1]), int.Parse(tokens[2])) , new Cargo(int.Parse(tokens[3]), tokens[4]) , new List <Tire>(temp))); } string type = Console.ReadLine(); if (type == "fragile") { cars.PrintResultsFragile(); } else { cars.PrintResultsFlamable(); } }
public void QuadraticNegativeValue() { Assert.Throws <Exception>(() => { Solve.Quadratic(1, 1, 1); }); }
public ActionResult Solve(string firstNumber, string secondNumber, string returnUrl) { double FirstNumber = Math.Sqrt(Int32.Parse(firstNumber)); double SecondNumber = Math.Sqrt(Int32.Parse(secondNumber)); var model = new Solve(); if (FirstNumber < 0 || SecondNumber < 0) { model.ErrorMessage = "One or two of the numbers you entered was negative. Please put another number"; return(View(model)); } if (FirstNumber > SecondNumber) { model.SuccessMessage = "The number " + " " + firstNumber + " " + "with Square root " + " " + FirstNumber + " " + "has a higher square root than the number " + " " + secondNumber + " " + "with square root " + " " + SecondNumber + "."; return(View(model)); } else if (FirstNumber == SecondNumber) { model.ErrorMessage = "The 2 numbers you entered has the same square root. Please enter another value"; return(View(model)); } else { model.SuccessMessage = "The number " + " " + secondNumber + " " + "with Square root " + " " + SecondNumber + " " + "has a higher square root than the number " + " " + firstNumber + " " + "with square root " + " " + FirstNumber + "."; return(View(model)); } }
static void Main(string[] args) { cin = new Scanner(); Solve.cin = cin; int T = cin.nextInt(); Solve[] SV = new Solve[T]; for (int i = 0; i < T; i++) { SV[i] = new Solve(); SV[i].input(); } //high speed; /* * string[] ans = new string[T]; * Parallel.For(0, T, i => * { * ans[i] = SV[i].calc(); * }); * * for (int i = 0; i < T; i++) * { * Console.WriteLine("Case #{0}:\n{1}", i + 1, ans[i]); * } */ //low speed for (int i = 0; i < T; i++) { Console.WriteLine("Case #{0}: {1}", i + 1, SV[i].calc()); } }
public void SortEmptyArray() { var array = new int[0]; Solve.QuickSort(array); Assert.AreEqual(array.Length, 0); }
static void Main(string[] args) { char ch = '0'; ISolve solve = new Solve(); IInputOutput prog = new InputOutput(solve); do { Console.WriteLine("Press [N] to count the numbers\n"); Console.WriteLine("Press [P] to print the numbers in the bound\n"); Console.WriteLine("Press [T] to print the triangle numbers\n"); Console.WriteLine("Press [Q] to quit the program\n"); ch = Console.ReadKey().KeyChar; if ((ch == 'P') || (ch == 'p')) { prog.PrintNumbers(); } else if ((ch == 'T') || (ch == 't')) { prog.PrintTriangleNumbers(); } else if ((ch == 'N') || (ch == 'n')) { prog.InputNumbers(); } }while ((ch != 'Q') && (ch != 'q')); Console.ReadKey(); }
static void Main(string[] args) { Solve people = new Solve(); string input = Console.ReadLine(); while (input != "End") { string[] tokens = input.Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries); if (tokens[1] == "company") { people.AddCompany(tokens[0], new Company(tokens[2], tokens[3], decimal.Parse(tokens[4]))); } else if (tokens[1] == "car") { people.AddCar(tokens[0], new Car(tokens[2], int.Parse(tokens[3]))); } else if (tokens[1] == "pokemon") { people.AddPokemon(tokens[0], new Pokemon(tokens[2], tokens[3])); } else if (tokens[1] == "parents") { people.AddParent(tokens[0], new Parents(tokens[2], tokens[3])); } else if (tokens[1] == "children") { people.AddChild(tokens[0], new Children(tokens[2], tokens[3])); } input = Console.ReadLine(); } string name = Console.ReadLine(); people.Print(name); }
public void Solve_EmptyBoard_SolutionIsEmpty() { var board = new Board(new Box[] { }); var solver = new Solve(); var solution = solver.FindSolution(board, 1); Assert.IsTrue(solution.Moves.Count == 0); }
public void ThreeElements() //Сортировка массива из трёх элементов. { var array = GenerateArray.Generate(3); Solve.Sort(array, 0, array.Length - 1); //После сортировки второй элемент больше первого, третий больше второго Assert.IsTrue(array[1] >= array[0], "Второй элемент больше (или равен) первого"); Assert.IsTrue(array[2] >= array[1], "Тетий элемент больше (или равен) второго"); }
private void GetAnswerMenu_Click(object sender, EventArgs e)// событие рассчета периметра и площади квадрата из контекстного меню { if ((int)sideSquare.Value == 0) { MessageBox.Show("Введите данные"); } perimeter.Text = Solve.Perimeter((int)sideSquare.Value).ToString(); area.Text = Solve.Area((int)sideSquare.Value).ToString(); sideSquare.Focus(); }
public Form1() { InitializeComponent(); board = new Board(new Box[] { }); boardEditor = new BoardEditor(board); solver = new Solver.Solve(); maxMoves = 2; boardImage = new BoardImage(); pictureBox1.Image = boardImage.CreateBitmap(board); }
static void Main(string[] args) { var reflectionWorker = new AssemblyWorker(); var typeWorker = new TypeWorker(); var seacher = new Searcher(); var solve = new Solve(); var answer = solve.GetSolve <IPlugin>(reflectionWorker, typeWorker, seacher); answer.ForEach(Console.WriteLine); }
// Runs when a tile is clicked & the game isn't won yet public void GetNextHint() { if (_solverCoroutine != null) { StopCoroutine(_solverCoroutine); } _solverCoroutine = Solve.GetNextHint(Level.CurrentLevel); StartCoroutine(_solverCoroutine); }
private string GenerateSingleSolveContent(Solve solve, int index) { return(string.Format(ApplicationResources.Reports.Texts.Solve, index, ConvertDateTimeToString(solve.FinishTimeSpan), ConvertTimeSpanToString(solve.Duration), BooleanToString(solve.DNF), BooleanToString(solve.PenaltyTwoSeconds), CheckScrambleLength(solve.Scramble))); }
public void QuadraticPositiveValue() { var result = Solve.Quadratic(1, 10, 16); Assert.Multiple(() => { Assert.That(result.Item1, Is.EqualTo(-2)); Assert.That(result.Item2, Is.EqualTo(-13)); }); }
public void OneHundredIdenticalElements() //Сортировка массива из 100 одинаковых чисел { var array = new int[100]; for (var i = 0; i < array.Length - 1; i++) { array[i] = 10; } Solve.Sort(array, 0, array.Length - 1); }
private void Power2_CheckedChanged(object sender, EventArgs e) { //set operation, units, and show the formula and solve button op = 3; label1.Show(); label2.Show(); label1.Text = "A"; label2.Text = "Ohm"; label5.Text = "J"; Solve.Show(); pictureBox1.Image = Properties.Resources.Power_IR; }
public void Ctr_ShouldCreate(CubeType cubetype) { var expectedIsDNF = false; var expectedSolveTime = 0; var expectedTypeOfCube = cubetype; Solve actual = new Solve(cubetype); Assert.Equal(expectedIsDNF, actual.IsDNF); Assert.Equal(expectedSolveTime, actual.SolveTime); Assert.Equal(expectedTypeOfCube, actual.TypeOfCube); }
private void Pressure_CheckedChanged(object sender, EventArgs e) { //set operation, units, and show the formula and solve button op = 1; label1.Show(); label2.Show(); label1.Text = "N"; label2.Text = "m^2"; label5.Text = "Pa"; Solve.Show(); pictureBox1.Image = Properties.Resources.Pressure; }
private void Speed_CheckedChanged(object sender, EventArgs e) { //set operation, units, and show the formula and solve button op = 2; label1.Show(); label2.Show(); label1.Text = "km"; label2.Text = "h"; label5.Text = "km/h"; Solve.Show(); pictureBox1.Image = Properties.Resources.Speed; }
public SegTree(int N, Solve So) { Sol = So; X = new int[2 * N - 1]; for (depth = 1; (1 << depth) <= N; depth++) { ; } segf = N - 1; borderP = (1 << depth) - 2; border = 2 * N - borderP - 2; segfb = border / 2; }
public void Solve_SimpleMoveRight_SolutionIsFound() { var box1 = new Box(1, new Position(1, 0)); var box2 = new Box(1, new Position(3, 0)); var box3 = new Box(1, new Position(4, 0)); var board = new Board(new Box[] { box1, box2, box3 }); var solver = new Solve(); var solution = solver.FindSolution(board, 1); Assert.IsTrue(solution.Moves.Count == 1); Assert.AreEqual(Move.Create(new Position(1, 0), Move.MoveDirectionEnum.Right), solution.Moves[0]); }
public void OneThousandDifferentElements() //Сортировка массива из 1000 разных чисел { var array = GenerateArray.Generate(100); Solve.Sort(array, 0, array.Length - 1); //Проверить что 10 случайных пар элементов массива после сортировки упорядочены (из пары больший тот, чей индекс больше) for (var i = 0; i < 10; i++) { int firstIndex = random.Next(0, (array.Length - 1) / 2); int secondIndex = random.Next((array.Length - 1) / 2, array.Length - 1); Assert.IsTrue(array[firstIndex] <= array[secondIndex], "из пары больший тот, чей индекс больше"); } }
public void FindSolution_MapSeattleLevel3_SolutionIsFound() { //Arrange var board = new BoardTestBuilder() .FromFile(@"TestData\SeattleLevel3.json") .Build(); var solve = new Solve(); //Act var result = solve.FindSolution(board, 2); //Assert Assert.IsTrue(result.Found); }
public void FindSolution_SemiAdvancedSetup_SolutionIsFound() { //Arrange var board = new BoardTestBuilder() .FromFile(@"TestData\SemiAdvancedSetup.json") .Build(); var solve = new Solve(); //Act var result = solve.FindSolution(board, 2); //Assert Assert.IsTrue(result.Found); }
public void AdvancedMoveTheBoxLevel() { //Arrange var board = new BoardTestBuilder() .FromFile(@"TestData\AdvancedMoveTheBoxLevel.json") .Build(); var solve = new Solve(); //Act var result = solve.FindSolution(board, 4); //Assert Assert.IsTrue(result.Found); }
public void SortEqualElements() { var array = new int[100]; for (int i = 0; i < array.Length; i++) { array[i] = 1; } Solve.QuickSort(array); for (var j = 1; j < 100; j++) { Assert.IsTrue(array[j - 1] == array[j]); } }
//Create a graph of N nodes with each node having k nearest neighbors public Graph(int n, int k, Collider[] Obstacles) { start = new Node(GameObject.Find("Start").transform.position, k); goal = new Node(GameObject.Find("Goal").transform.position, k); contents = new Node[n]; for(int i = 0; i < n; i++){ contents[i] = new Node(minimum, maximum, k); } // in our contents of the graph, we find the k-nearest neighbors for each node // we first go through each node for(int i = 0; i < n; i++){ // for each node we go through each other node and add if it is one of our nearest neighbors for (int j = 0; j < n; j ++){ if (i != j) { contents[i].addNeighbor(contents[j], Obstacles); } } contents[i].addNeighbor(goal, Obstacles); } // Find neighbors for starting node for (int i = 0; i < n; i++) { start.addNeighbor(contents[i], Obstacles); } start.addNeighbor(goal, Obstacles); foreach (Node neighbor in start.neighbors.Values) { Debug.DrawLine(start.position, neighbor.position); } Solve soln = new Solve(start, goal); solnDijkstra = soln.Dijkstra(); solnAStar = soln.AStar(); }
//Create a graph of N nodes with each node having k nearest neighbors public Graph(int n, int k, Collider[] Obstacles) { start = new Node(GameObject.Find("Start").transform.position, k); goal = new Node(GameObject.Find("Goal").transform.position, k); contents = new Node[n]; for(int i = 0; i < n; i++){ contents[i] = new Node(minimum, maximum, k); } // in our contents of the graph, we find the k-nearest neighbors for each node // we first go through each node for(int i = 0; i < n; i++){ // for each node we go through each other node and add if it is one of our nearest neighbors for (int j = 0; j < n; j ++){ if (i != j) { contents[i].addNeighbor(contents[j], Obstacles); } } contents[i].addNeighbor(goal, Obstacles); } // Find neighbors for starting node for (int i = 0; i < n; i++) { start.addNeighbor(contents[i], Obstacles); } start.addNeighbor(goal, Obstacles); for (int i = 0; i < n; i++){ //Instantiate the node so we have a visual representation Instantiate(NodePrefab, contents[i].position, Quaternion.identity); Node[] neighbors = contents[i].neighbors.Values.ToArray(); for (int j = 0; j < k; j++){ //Create lines from the node to each nearest neighbor //Total of i*j*2 elements Lines.GetComponent<LineRenderer>().SetPosition((2*(i*neighbors.Length+j)), contents[i].position); Lines.GetComponent<LineRenderer>().SetPosition((2*(i*neighbors.Length+j)+1), neighbors[j].position); //Debug.DrawLine(contents[i].position, neighbors[j].position); } } Node[] startNeighbors = start.neighbors.Values.ToArray(); for (int i = 0; i < startNeighbors.Length; i++) { Lines.GetComponent<LineRenderer>().SetPosition((2*n*k)+2*i, startNeighbors[i].position); Lines.GetComponent<LineRenderer>().SetPosition((2*n*k)+2*i+1, start.position); } Solve soln = new Solve(start, goal); solnDijkstra = soln.Dijkstra(); solnAStar = soln.AStar(); }