-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathday3.cs
More file actions
84 lines (63 loc) · 2.41 KB
/
day3.cs
File metadata and controls
84 lines (63 loc) · 2.41 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
using System;
using System.Collections.Generic;
using System.IO;
class Day3Class
{
public void Start()
{
// https://adventofcode.com/2020/day/3
Console.WriteLine("****** DIA 3 ******");
string[] lines = File.ReadAllLines(@"./inputs/inputs_dia3.txt");
//generar matriz
List<char[]> inputs = new List<char[]>();
for (ushort j = 0; j < lines.Length; j++)
{
for (uint i = 0; i < 15; i++)
{
lines[j] += lines[j];
}
inputs.Add(lines[j].ToCharArray());
}
//fase 1
Console.WriteLine("****** FASE 1 ******");
uint contador = calcularmatriz(lines.Length, inputs, 3, 1);
Console.WriteLine("contador=" + contador);
//fase 2
Console.WriteLine("****** FASE 2 ******");
uint contador_slope1 = calcularmatriz(lines.Length, inputs, 1, 1);
uint contador_slope2 = calcularmatriz(lines.Length, inputs, 3, 1);
uint contador_slope3 = calcularmatriz(lines.Length, inputs, 5, 1);
uint contador_slope4 = calcularmatriz(lines.Length, inputs, 7, 1);
uint contador_slope5 = calcularmatriz(lines.Length, inputs, 1, 2);
Console.WriteLine("contador slope1=" + contador_slope1);
Console.WriteLine("contador slope2=" + contador_slope2);
Console.WriteLine("contador slope3=" + contador_slope3);
Console.WriteLine("contador slope4=" + contador_slope4);
Console.WriteLine("contador slope5=" + contador_slope5);
uint multiplicacion = (contador_slope1 * contador_slope2 * contador_slope3 * contador_slope4 * contador_slope5);
Console.WriteLine("Multiplicacion slopes=" + multiplicacion);
ushort calcularmatriz(int longitudLines, List<char[]> inputs, ushort sumaX, ushort sumaY)
{
ushort contador = 0;
ushort posX = 0;
ushort posY = 0;
for (ushort i = 0; i < longitudLines; i++)
{
posX += sumaX;
posY += sumaY;
if (posY < longitudLines)
{
if (inputs[posY][posX] == '#')
{
contador++;
}
}
if (posY > longitudLines)
{
break;
}
}
return contador;
}
}
}