public static int SolvePart2(int[,] input) { var vektors = Vektor.Transform(input).ToList(); var map = new int[vektors.Max(v => v.X) + 1, vektors.Max(v => v.Y) + 1]; for (var x = 0; x < map.GetLength(0); x++) { for (var y = 0; y < map.GetLength(1); y++) { // Find closest vektor(s) var distanceToAll = vektors.Sum(v => v.Distance(x, y)); map[x, y] = distanceToAll; } } // Debug printing to image CreateDistanceImage(map); var sumArea = 0; foreach (var point in map) { if (point > 0 && point < 10000) { sumArea += 1; } } return(sumArea); }
public static double noktaUret(Vektor v1, Vektor v2) { Vektor v3 = v1.normalize(); Vektor v4 = v2.normalize(); return(v3.X * v4.X + v3.Y * v4.Y); }
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET: //ORIGINAL LINE: public Algebraic integrate(Variable var) throws JasymcaException public override Algebraic integrate(Variable @var) { if (!den.depends(@var)) { return(nom.integrate(@var).div(den)); } Algebraic quot = den.deriv(@var).div(nom); if (quot.deriv(@var).Equals(Zahl.ZERO)) { return(FunctionVariable.create("log", den).div(quot)); } Algebraic[] q = new Algebraic[] { nom, den }; Poly.polydiv(q, @var); if (!q[0].Equals(Zahl.ZERO) && nom.ratfunc(@var) && den.ratfunc(@var)) { return(q[0].integrate(@var).add(q[1].div(den).integrate(@var))); } if (ratfunc(@var)) { Algebraic r = Zahl.ZERO; Vektor h = horowitz(nom, den, @var); if (h.get(0) is Rational) { r = r.add(h.get(0)); } if (h.get(1) is Rational) { r = r.add((new TrigInverseExpand()).f_exakt(((Rational)h.get(1)).intrat(@var))); } return(r); } throw new JasymcaException("Could not integrate Function " + this); }
public static float Cosinus(Vektor first, Vektor second) { var result = (first.OX * second.OX + first.OY * second.OY) / (Math.Abs(first.OX + second.OX) * Math.Abs(first.OY + second.OY)); return(result); }
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET: //ORIGINAL LINE: public static Vektor Gauss(Matrix a, Vektor c) throws JasymcaException public static Vektor Gauss(Matrix a, Vektor c) { int n = c.length(); Algebraic[] x = new Algebraic[n]; for (int k = 0; k < n - 1; k++) { pivot(a, c, k); if (!a.get(k, k).Equals(Zahl.ZERO)) { for (int i = k + 1; i < n; i++) { Algebraic factor = a.get(i, k).div(a.get(k, k)); for (int j = k + 1; j < n; j++) { a.set(i, j, a.get(i, j).sub(factor.mult(a.get(k, j)))); } c.set(i, c.get(i).sub(factor.mult(c.get(k)))); } } } x[n - 1] = c.get(n - 1).div(a.get(n - 1, n - 1)); for (int i = n - 2; i >= 0; i--) { Algebraic sum = Zahl.ZERO; for (int j = i + 1; j < n; j++) { sum = sum.add(a.get(i, j).mult(x[j])); } x[i] = c.get(i).sub(sum).div(a.get(i, i)); } return(new Vektor(x)); }
internal static Vektor teiler(long X) { ArrayList teiler = new ArrayList(); while (X % 2L == 0) { teiler.Add(Zahl.TWO); X /= 2L; } while (X % 3L == 0) { teiler.Add(Zahl.THREE); X /= 3L; } while (X % 5L == 0) { teiler.Add(new Unexakt(5.0)); X /= 5L; } long f = 7L; while (X != 1L) { f = kleinsterTeiler(X, f); if (f < 0) { return(null); } teiler.Add(new Exakt(f, 1L)); X /= f; } return(Vektor.create(teiler)); }
private static void CreateVektorImage(int[,] map, Vektor biggestVektor) { var image = new Bitmap(map.GetLength(0), map.GetLength(1)); for (var x = 0; x < map.GetLength(0); x++) { for (var y = 0; y < map.GetLength(1); y++) { var val = map[x, y]; Color color; if (val == -2) { color = Color.Black; } else if (val == -1) { color = Color.White; } else if (val == biggestVektor.Index) { color = Color.Red; } else { color = ColorRGB.FromHSL(val / 60d, 1.0, .5); } image.SetPixel(x, y, color); } } image.Save("vektor_map.bmp"); }
public virtual Vektor eigenvalues() { Variable x = SimpleVariable.top; Polynomial p = charpoly(x); Algebraic[] ps = p.square_free_dec(p.v); Vektor r; ArrayList v = new ArrayList(); for (int i = 0; i < ps.Length; i++) { if (ps[i] is Polynomial) { r = ((Polynomial)ps[i]).monic().roots(); for (int k = 0; r != null && k < r.length(); k++) { for (int j = 0; j <= i; j++) { v.Add(r.get(k)); } } } } return(Vektor.create(v)); }
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET: //ORIGINAL LINE: private static int pivot(Matrix a, Vektor c, int k) throws JasymcaException private static int pivot(Matrix a, Vektor c, int k) { int pivot = k, n = c.length(); double maxa = a.get(k, k).norm(); for (int i = k + 1; i < n; i++) { double dummy = a.get(i, k).norm(); if (dummy > maxa) { maxa = dummy; pivot = i; } } if (pivot != k) { for (int j = k; j < n; j++) { var dummy = a.get(pivot, j); a.set(pivot, j, a.get(k, j)); a.set(k, j, dummy); } { var dummy = c.get(pivot); c.set(pivot, c.get(k)); c.set(k, dummy); } } return(pivot); }
private static List <CoorinateFloat> ConvexPolygon(List <CoorinateFloat> coordinates) { var firstPoint = FindStartPoint(coordinates); var pointsList = SortedPointsByCos(coordinates, firstPoint); var niceFigure = new List <CoorinateFloat>(); niceFigure.Add(firstPoint); niceFigure.Add(pointsList.First()); var firstPointForAlgo = firstPoint; var currentVektor = new Vektor(firstPointForAlgo, pointsList.First()); foreach (var point in pointsList) { var nextVektor = new Vektor(firstPointForAlgo, point); if (VektorOperation.IsNiceComposition(currentVektor, nextVektor)) { currentVektor = nextVektor; firstPointForAlgo = point; niceFigure.Add(point); } } niceFigure.Add(firstPoint); return(niceFigure); }
public override int lambda(Stack st) { int narg = getNarg(st); List cond = getList(st); List body = getList(st); pc.process_list(cond, true); if (pc.stack.Count == 0 || !(pc.stack.Peek() is Vektor) || ((Algebraic)pc.stack.Peek()).Name == null) { throw new ParseException("Wrong format in for-loop."); } Vektor vals = (Vektor)pc.stack.Pop(); for (int i = 0; i < vals.length(); i++) { pc.env.putValue(vals.Name, vals.get(i)); int ret = pc.process_list(body, true); switch (ret) { case Processor.BREAK: return(0); case Processor.RETURN: case Processor.EXIT: case Processor.ERROR: return(ret); case Processor.CONTINUE: break; } } return(0); }
private static List <CoorinateFloat> SortedPointsByCos(List <CoorinateFloat> coordinates, CoorinateFloat firstPoint) { var vektorList = GetVektors(coordinates, firstPoint); var verticalVektor = new Vektor(firstPoint, new CoorinateFloat(firstPoint.X, firstPoint.Y + 1)); var sortedVektors = vektorList.OrderByDescending(z => VektorOperation.Cosinus(verticalVektor, z)).Select(z => z.PointEnd).ToList(); return(sortedVektors); }
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET: //ORIGINAL LINE: private static void elim(Vektor expr, Vektor vars, int n) throws JasymcaException private static void elim(Vektor expr, Vektor vars, int n) { if (n >= expr.length()) { return; } double maxc = 0.0; int iv = 0, ie = 0; Variable vp = null; Algebraic f = Zahl.ONE; Polynomial pm = null; for (int i = 0; i < vars.length(); i++) { Variable v = ((Polynomial)vars.get(i)).v; for (int k = n; k < expr.length(); k++) { Algebraic pa = expr.get(k); if (pa is Polynomial) { Polynomial p = (Polynomial)pa; Algebraic c = p.coefficient(v, 1); double nm = c.norm(); if (nm > maxc) { maxc = nm; vp = v; ie = k; iv = i; f = c; pm = p; } } } } if (maxc == 0.0) { return; } expr.set(ie, expr.get(n)); expr.set(n, pm); for (int i = n + 1; i < expr.length(); i++) { Algebraic p = expr.get(i); if (p is Polynomial) { Algebraic fc = ((Polynomial)p).coefficient(vp, 1); if (!fc.Equals(Zahl.ZERO)) { p = p.sub(pm.mult(fc.div(f))); } } expr.set(i, p); } elim(expr, vars, n + 1); }
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET: //ORIGINAL LINE: public Polynomial(Variable var, Vektor v) throws JasymcaException public Polynomial(Variable @var, Vektor v) { this.v = @var; this.a = new Algebraic[v.length()]; for (int i = 0; i < a.Length; i++) { a[i] = v.get(a.Length - 1 - i); } this.a = Poly.reduce(a); }
public static bool IsNiceComposition(Vektor vek1, Vektor vek2) { var result = vek1.OX * vek2.OX + vek1.OY * vek2.OY; if (result > 0) { return(true); } return(false); }
private static List <Vektor> GetVektors(List <CoorinateFloat> coordinates, CoorinateFloat firstPoint) { var vektorList = new List <Vektor>(); foreach (var point in coordinates.Where(z => z != firstPoint)) { var vektor = new Vektor(firstPoint, point); vektorList.Add(vektor); } return(vektorList); }
public static int Sis(Duz a, Tacka C, Tacka D) { Vektor AB = new Vektor(a.A, a.B); Vektor AC = new Vektor(a.A, C); double a_C = Vektor.vektorski(AB, AC); Vektor AD = new Vektor(a.A, D); double a_D = Vektor.vektorski(AB, AD); /* if (a_C * a_D > 0) return true; * else return false;*/ return(Math.Sign(a_C * a_D)); }
public bool isCloseTo(Vektor vek) { int n = 0; for (int i = 0; i < this.size; i++) { if (this.komponente[i] == vek.komponente[i]) { n++; } } return(n >= 2); }
public override zwischenSpeicher scatter(ray r_in, hit_record rec, Vektor attenuation, ray scattered) { zwischenSpeicher zw = new zwischenSpeicher(); Vektor reflected = Vektor.reflect(Vektor.unit_Vektor(r_in.Direction), rec.normal); scattered = new ray(rec.p, reflected + fuzz * Vektor.random_in_unit_sphere()); attenuation = albedo; zw.scattered = scattered; zw.attenuation = attenuation; zw.IsTrue = (Vektor.dot(scattered.Direction, rec.normal) > 0.0); return(zw); }
static void Main(string[] args) { Vektor[] list = new Vektor[6]; Random r = new Random(); for (int i = 0; i < list.Length; i++) { list[i] = new Vektor(r.Next(1, 5), r.Next(1, 5), r.Next(1, 5)); Console.WriteLine(list[i]); } findSimilarVectors(list); findSimilarVectorsFine(list); Console.ReadKey(); }
static Vektor teiler(BigInteger X) { var teiler = new ArrayList(); var b2 = BigInteger.valueOf(2L); while (X.mod(b2).Equals(BigInteger.ZERO)) { teiler.Add(Zahl.TWO); X = X.divide(b2); } var b3 = BigInteger.valueOf(3L); while (X.mod(b3).Equals(BigInteger.ZERO)) { teiler.Add(Zahl.THREE); X = X.divide(b3); } var b5 = BigInteger.valueOf(5L); while (X.mod(b5).Equals(BigInteger.ZERO)) { teiler.Add(new Unexakt(5.0)); X = X.divide(b5); } var f = BigInteger.valueOf(7L); while (!X.Equals(BigInteger.ONE)) { f = kleinsterTeiler(X, f); if (f == null) { return(null); } teiler.Add(new Exakt(f)); X = X.divide(f); } return(Vektor.create(teiler)); }
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET: //ORIGINAL LINE: public int lambda2(Stack st) throws ParseException, JasymcaException public virtual int lambda2(Stack st) { int narg = getNarg(st); if (narg != 2) { throw new ParseException("linsolve requires 2 arguments."); } Vektor expr = (Vektor)getVektor(st).rat(); Vektor vars = getVektor(st); elim(expr, vars, 0); subst(expr, vars, expr.length() - 1); st.Push(expr); return(0); }
public int GenerisiZahtjev(int brojBloka, int brojVektora, int brojElementa) { int ret = -1; IIdentity id = Thread.CurrentPrincipal.Identity; IPrincipal principal = Thread.CurrentPrincipal; WindowsIdentity wId = id as WindowsIdentity; if (principal.IsInRole("Trazi")) { Audit.AuthorizationSuccess(Formatter.VratiIme((principal as CustomPrincipal).Identity.Name), OperationContext.Current.IncomingMessageHeaders.Action); Console.WriteLine("\n-------------------------------------------"); Console.WriteLine("Klijent je generisao brojeve: " + brojBloka.ToString() + "," + brojVektora.ToString() + "," + brojElementa.ToString()); Dictionary <int, Blok> blok = InterniModel.blokovi; Blok b = blok[brojBloka]; Dictionary <int, Vektor> vektor = b.GetVektori; Vektor v = vektor[brojVektora]; Dictionary <int, Alarm> alarm = v.GetElementi; Alarm a = alarm[brojElementa]; if (a == null) { Console.WriteLine("Na zadatoj poziciji nema alarma."); Console.WriteLine("-------------------------------------------\n"); ret = 0; } else { Console.WriteLine("\n-------------------------------------------"); Console.WriteLine("PRONADJENI ALARM: \nPoruka: {0} \nVreme generisanja : {1} \nRizik: {2}", a.PorukaOAlarmu, a.VrijemeGenerisanjaAlarma, a.Rizik); Console.WriteLine("-------------------------------------------\n"); new BazaPodataka().Upisi(a, Formatter.VratiIme((principal as CustomPrincipal).Identity.Name)); ret = 1; } } else { Audit.AuthorizationFailed(Formatter.VratiIme((principal as CustomPrincipal).Identity.Name), OperationContext.Current.IncomingMessageHeaders.Action, "Authorization failed."); MyException ex = new MyException(); ex.Message = "Nemate pravo 'Trazi'!"; throw new FaultException <MyException>(ex); } return(ret); }
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET: //ORIGINAL LINE: public static Vektor substitution(Matrix a, Vektor c) throws JasymcaException public static Vektor substitution(Matrix a, Vektor c) { int n = c.length(); Algebraic[] x = new Algebraic[n]; x[n - 1] = c.get(n - 1).div(a.get(n - 1, n - 1)); for (int i = n - 2; i >= 0; i--) { Algebraic sum = Zahl.ZERO; for (int j = i + 1; j < n; j++) { sum = sum.add(a.get(i, j).mult(x[j])); } x[i] = c.get(i).sub(sum).div(a.get(i, i)); } return(new Vektor(x)); }
public static double Ugao(Vektor a, Vektor b) { double ugao_a = Math.Atan2(a.y, a.x) * 180 / Math.PI; double ugao_b = Math.Atan2(b.y, b.x) * 180 / Math.PI; // Console.WriteLine("u1=" + ugao_a + " u2=" + ugao_b ); if (ugao_b - ugao_a < -180) { return(ugao_b - ugao_a + 360); } if (ugao_b - ugao_a > 180) { return(ugao_b - ugao_a - 360); } return(ugao_b - ugao_a); }
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET: //ORIGINAL LINE: private static void eliminierung(Matrix a, Vektor c) throws JasymcaException private static void eliminierung(Matrix a, Vektor c) { int n = c.length(); for (int k = 0; k < n - 1; k++) { pivot(a, c, k); for (int i = k + 1; i < n; i++) { Algebraic factor = a.get(i, k).div(a.get(k, k)); for (int j = k; j < n; j++) { a.set(i, j, a.get(i, j).sub(factor.mult(a.get(k, j)))); } c.set(i, c.get(i).sub(factor.mult(c.get(k)))); } } }
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET: //ORIGINAL LINE: Algebraic intrat(Variable x) throws JasymcaException internal virtual Algebraic intrat(Variable x) { Algebraic de = den.deriv(x); if (de is Zahl) { return(makelog(nom.div(de), x, den.a[0].mult(Zahl.MINUS).div(de))); } Algebraic r = nom.div(de); Vektor xi = den.monic().roots(); Algebraic rs = Zahl.ZERO; for (int i = 0; i < xi.length(); i++) { Algebraic c = r.value(x, xi.get(i)); rs = rs.add(makelog(c, x, xi.get(i))); } return(rs); }
public override zwischenSpeicher scatter(ray r_in, hit_record rec, Vektor attenuation, ray scattered) { zwischenSpeicher zw = new zwischenSpeicher(); var scatter_direction = rec.normal + Vektor.random_unit_vektor(); //catch degenerate scatter direction if (scatter_direction.near_zero()) { scatter_direction = rec.normal; } scattered = new ray(rec.p, scatter_direction); attenuation = albedo; zw.scattered = scattered; zw.attenuation = attenuation; zw.IsTrue = true; return(zw); }
public virtual Algebraic find() { ArrayList v = new ArrayList(); for (int i = 0; i < nrow(); i++) { for (int k = 0; k < ncol(); k++) { if (!Zahl.ZERO.Equals(a[i][k])) { v.Add(new Unexakt(i * nrow() + k + 1.0)); } } } Vektor vx = Vektor.create(v); if (nrow() == 1) { return(vx); } return(column(vx)); }
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET: //ORIGINAL LINE: private static void subst(Vektor expr, Vektor vars, int n) throws JasymcaException private static void subst(Vektor expr, Vektor vars, int n) { if (n < 0) { return; } Algebraic pa = expr.get(n); if (pa is Polynomial) { Polynomial p = (Polynomial)pa; Variable v = null; Algebraic c1 = null, c0; for (int k = 0; k < vars.length(); k++) { Variable va = ((Polynomial)vars.get(k)).v; c1 = p.coefficient(va, 1); if (!c1.Equals(Zahl.ZERO)) { v = va; break; } } if (v != null) { expr.set(n, p.div(c1)); Algebraic val = p.coefficient(v, 0).mult(Zahl.MINUS).div(c1); for (int k = 0; k < n; k++) { Algebraic ps = expr.get(k); if (ps is Polynomial) { expr.set(k, ((Polynomial)ps).value(v, val)); } } } } subst(expr, vars, n - 1); }
private void boardPanel_Paint(object sender, PaintEventArgs e) { // Spielsteine List<Vektor> z = ReversiLogik.MöglicheZüge(game.Feld, game.AktuellerSpieler); for (int y = 0; y < 6; y++) { for (int x = 0; x < 6; x++) { e.Graphics.FillRectangle(new SolidBrush(Farben[game.Feld[x, y]]), boardPanel.ClientRectangle.Left + x * fieldw, boardPanel.ClientRectangle.Top + y * fieldh, fieldw, fieldh); if (z.Contains(new Vektor(x ,y))) e.Graphics.DrawEllipse(Pens.White, boardPanel.ClientRectangle.Left + x * fieldw, boardPanel.ClientRectangle.Top + y * fieldh, fieldw, fieldh); // evtl. Bewertung Vektor v = new Vektor(x, y); if (game.Bewertungen.ContainsKey(v)) e.Graphics.DrawString(game.Bewertungen[v].ToString(), DefaultFont, Brushes.White, fieldw * x + 2.0f, fieldh * y + 2.0f); } } // Linien for (int i = 1; i <= 6; i++) { e.Graphics.DrawLine(SystemPens.ControlDark, boardPanel.ClientRectangle.Left + i * fieldw, boardPanel.ClientRectangle.Top, boardPanel.ClientRectangle.Left + i * fieldw, boardPanel.ClientRectangle.Top + 6 * fieldh); } for (int i = 0; i <= 6; i++) { e.Graphics.DrawLine(SystemPens.ControlDark, boardPanel.ClientRectangle.Left, boardPanel.ClientRectangle.Top + i * fieldh, boardPanel.ClientRectangle.Left + 6 * fieldw, boardPanel.ClientRectangle.Top + i * fieldh); } }