Repository navigation
Expand file tree
/
Copy pathDay_four.cs
More file actions
64 lines (58 loc) · 2.03 KB
/
Copy pathDay_four.cs
File metadata and controls
64 lines (58 loc) · 2.03 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
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Avent_du_code_2019
{
class Day_four : Day
{
int inputMIN = 359282, inputMAX = 820401;
public override int Puzzle1()
{
int possibilities = inputMAX - inputMIN + 1;
for(int i = inputMIN; i<=inputMAX; i++)
{
bool verif = true;
if(i.ToString().Count() == i.ToString().Distinct().Count())
{
verif = false;
}
for(int pos = 0; pos<i.ToString().Length-1; pos++)
{
if (Int32.Parse(i.ToString().ElementAt(pos).ToString()) > Int32.Parse(i.ToString().ElementAt(pos + 1).ToString()))
verif = false;
}
if (!verif)
possibilities--;
}
return possibilities;
}
public override int Puzzle2()
{
int possibilities = inputMAX - inputMIN + 1;
for (int i = inputMIN; i <= inputMAX; i++)
{
bool verif = true;
if (i.ToString().Count() == i.ToString().Distinct().Count())
verif = false;
for (int pos = 0; pos < i.ToString().Length - 1; pos++)
{
if (Int32.Parse(i.ToString().ElementAt(pos).ToString()) > Int32.Parse(i.ToString().ElementAt(pos + 1).ToString()))
verif = false;
}
bool element = true;
for (int pos = 0; pos < i.ToString().Length - 1; pos++)
{
if (i.ToString().Count(p => p == i.ToString().ElementAt(pos)) == 2)
element = false;
}
if (!element)
verif = false;
if (!verif)
possibilities--;
}
return possibilities;
}
}
}