made some progress
This commit is contained in:
1 parent
f92b3d93ef
commit
125039f7af
23 files changed
+1836
-149
No files matched your search
Binary file not shown.
Binary file not shown.
BIN
Binary file not shown.
BIN
Binary file not shown.
BIN
Binary file not shown.
BIN
Binary file not shown.
BIN
Binary file not shown.
BIN
Binary file not shown.
Binary file not shown.
@@ -7,8 +7,8 @@
|
|||||||
"RelativeMoniker": "D:0:0:{6A74A9DE-500D-46FF-859A-18F4A752D2A5}|Program.csproj|solutionrelative:program.cs||{A6C744A8-0E4A-4FC6-886A-064283054674}"
|
"RelativeMoniker": "D:0:0:{6A74A9DE-500D-46FF-859A-18F4A752D2A5}|Program.csproj|solutionrelative:program.cs||{A6C744A8-0E4A-4FC6-886A-064283054674}"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"AbsoluteMoniker": "D:0:0:{6A74A9DE-500D-46FF-859A-18F4A752D2A5}|Program.csproj|e:\\h\u00E1zi\\13.oszt\u00E1ly\\neumann_verseny\\fordulo_3\\program\\permutationgenerator.cs||{A6C744A8-0E4A-4FC6-886A-064283054674}",
|
"AbsoluteMoniker": "D:0:0:{6A74A9DE-500D-46FF-859A-18F4A752D2A5}|Program.csproj|e:\\h\u00E1zi\\13.oszt\u00E1ly\\neumann_verseny\\fordulo_3\\program\\virus.cs||{A6C744A8-0E4A-4FC6-886A-064283054674}",
|
||||||
"RelativeMoniker": "D:0:0:{6A74A9DE-500D-46FF-859A-18F4A752D2A5}|Program.csproj|solutionrelative:permutationgenerator.cs||{A6C744A8-0E4A-4FC6-886A-064283054674}"
|
"RelativeMoniker": "D:0:0:{6A74A9DE-500D-46FF-859A-18F4A752D2A5}|Program.csproj|solutionrelative:virus.cs||{A6C744A8-0E4A-4FC6-886A-064283054674}"
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
"DocumentGroupContainers": [
|
"DocumentGroupContainers": [
|
||||||
@@ -18,21 +18,8 @@
|
|||||||
"DocumentGroups": [
|
"DocumentGroups": [
|
||||||
{
|
{
|
||||||
"DockedWidth": 200,
|
"DockedWidth": 200,
|
||||||
"SelectedChildIndex": 2,
|
"SelectedChildIndex": 0,
|
||||||
"Children": [
|
"Children": [
|
||||||
{
|
|
||||||
"$type": "Document",
|
|
||||||
"DocumentIndex": 1,
|
|
||||||
"Title": "PermutationGenerator.cs",
|
|
||||||
"DocumentMoniker": "E:\\H\u00E1zi\\13.oszt\u00E1ly\\Neumann_Verseny\\fordulo_3\\Program\\PermutationGenerator.cs",
|
|
||||||
"RelativeDocumentMoniker": "PermutationGenerator.cs",
|
|
||||||
"ToolTip": "E:\\H\u00E1zi\\13.oszt\u00E1ly\\Neumann_Verseny\\fordulo_3\\Program\\PermutationGenerator.cs",
|
|
||||||
"RelativeToolTip": "PermutationGenerator.cs",
|
|
||||||
"ViewState": "AgIAAAAAAAAAAAAAAAAAABMAAAA8AAAAAAAAAA==",
|
|
||||||
"Icon": "ae27a6b0-e345-4288-96df-5eaf394ee369.000738|",
|
|
||||||
"WhenOpened": "2025-03-12T17:31:40.758Z",
|
|
||||||
"EditorCaption": ""
|
|
||||||
},
|
|
||||||
{
|
{
|
||||||
"$type": "Document",
|
"$type": "Document",
|
||||||
"DocumentIndex": 0,
|
"DocumentIndex": 0,
|
||||||
@@ -41,10 +28,23 @@
|
|||||||
"RelativeDocumentMoniker": "Program.cs",
|
"RelativeDocumentMoniker": "Program.cs",
|
||||||
"ToolTip": "E:\\H\u00E1zi\\13.oszt\u00E1ly\\Neumann_Verseny\\fordulo_3\\Program\\Program.cs",
|
"ToolTip": "E:\\H\u00E1zi\\13.oszt\u00E1ly\\Neumann_Verseny\\fordulo_3\\Program\\Program.cs",
|
||||||
"RelativeToolTip": "Program.cs",
|
"RelativeToolTip": "Program.cs",
|
||||||
"ViewState": "AgIAAAMAAAAAAAAAAAAwwBQAAAA6AAAAAAAAAA==",
|
"ViewState": "AgIAABwAAAAAAAAAAAAIwCcAAAAiAAAAAAAAAA==",
|
||||||
"Icon": "ae27a6b0-e345-4288-96df-5eaf394ee369.000738|",
|
"Icon": "ae27a6b0-e345-4288-96df-5eaf394ee369.000738|",
|
||||||
"WhenOpened": "2025-03-12T12:54:16.847Z",
|
"WhenOpened": "2025-03-12T12:54:16.847Z",
|
||||||
"EditorCaption": ""
|
"EditorCaption": ""
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"$type": "Document",
|
||||||
|
"DocumentIndex": 1,
|
||||||
|
"Title": "Virus.cs",
|
||||||
|
"DocumentMoniker": "E:\\H\u00E1zi\\13.oszt\u00E1ly\\Neumann_Verseny\\fordulo_3\\Program\\Virus.cs",
|
||||||
|
"RelativeDocumentMoniker": "Virus.cs",
|
||||||
|
"ToolTip": "E:\\H\u00E1zi\\13.oszt\u00E1ly\\Neumann_Verseny\\fordulo_3\\Program\\Virus.cs",
|
||||||
|
"RelativeToolTip": "Virus.cs",
|
||||||
|
"ViewState": "AgIAAAAAAAAAAAAAAAAAADIAAAABAAAAAAAAAA==",
|
||||||
|
"Icon": "ae27a6b0-e345-4288-96df-5eaf394ee369.000738|",
|
||||||
|
"WhenOpened": "2025-03-13T16:14:18.948Z",
|
||||||
|
"EditorCaption": ""
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -7,8 +7,8 @@
|
|||||||
"RelativeMoniker": "D:0:0:{6A74A9DE-500D-46FF-859A-18F4A752D2A5}|Program.csproj|solutionrelative:program.cs||{A6C744A8-0E4A-4FC6-886A-064283054674}"
|
"RelativeMoniker": "D:0:0:{6A74A9DE-500D-46FF-859A-18F4A752D2A5}|Program.csproj|solutionrelative:program.cs||{A6C744A8-0E4A-4FC6-886A-064283054674}"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"AbsoluteMoniker": "D:0:0:{6A74A9DE-500D-46FF-859A-18F4A752D2A5}|Program.csproj|e:\\h\u00E1zi\\13.oszt\u00E1ly\\neumann_verseny\\fordulo_3\\program\\permutationgenerator.cs||{A6C744A8-0E4A-4FC6-886A-064283054674}",
|
"AbsoluteMoniker": "D:0:0:{6A74A9DE-500D-46FF-859A-18F4A752D2A5}|Program.csproj|e:\\h\u00E1zi\\13.oszt\u00E1ly\\neumann_verseny\\fordulo_3\\program\\virus.cs||{A6C744A8-0E4A-4FC6-886A-064283054674}",
|
||||||
"RelativeMoniker": "D:0:0:{6A74A9DE-500D-46FF-859A-18F4A752D2A5}|Program.csproj|solutionrelative:permutationgenerator.cs||{A6C744A8-0E4A-4FC6-886A-064283054674}"
|
"RelativeMoniker": "D:0:0:{6A74A9DE-500D-46FF-859A-18F4A752D2A5}|Program.csproj|solutionrelative:virus.cs||{A6C744A8-0E4A-4FC6-886A-064283054674}"
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
"DocumentGroupContainers": [
|
"DocumentGroupContainers": [
|
||||||
@@ -18,21 +18,8 @@
|
|||||||
"DocumentGroups": [
|
"DocumentGroups": [
|
||||||
{
|
{
|
||||||
"DockedWidth": 200,
|
"DockedWidth": 200,
|
||||||
"SelectedChildIndex": 2,
|
"SelectedChildIndex": 0,
|
||||||
"Children": [
|
"Children": [
|
||||||
{
|
|
||||||
"$type": "Document",
|
|
||||||
"DocumentIndex": 1,
|
|
||||||
"Title": "PermutationGenerator.cs",
|
|
||||||
"DocumentMoniker": "E:\\H\u00E1zi\\13.oszt\u00E1ly\\Neumann_Verseny\\fordulo_3\\Program\\PermutationGenerator.cs",
|
|
||||||
"RelativeDocumentMoniker": "PermutationGenerator.cs",
|
|
||||||
"ToolTip": "E:\\H\u00E1zi\\13.oszt\u00E1ly\\Neumann_Verseny\\fordulo_3\\Program\\PermutationGenerator.cs",
|
|
||||||
"RelativeToolTip": "PermutationGenerator.cs",
|
|
||||||
"ViewState": "AgIAAAAAAAAAAAAAAAAAABMAAAA8AAAAAAAAAA==",
|
|
||||||
"Icon": "ae27a6b0-e345-4288-96df-5eaf394ee369.000738|",
|
|
||||||
"WhenOpened": "2025-03-12T17:31:40.758Z",
|
|
||||||
"EditorCaption": ""
|
|
||||||
},
|
|
||||||
{
|
{
|
||||||
"$type": "Document",
|
"$type": "Document",
|
||||||
"DocumentIndex": 0,
|
"DocumentIndex": 0,
|
||||||
@@ -41,10 +28,23 @@
|
|||||||
"RelativeDocumentMoniker": "Program.cs",
|
"RelativeDocumentMoniker": "Program.cs",
|
||||||
"ToolTip": "E:\\H\u00E1zi\\13.oszt\u00E1ly\\Neumann_Verseny\\fordulo_3\\Program\\Program.cs",
|
"ToolTip": "E:\\H\u00E1zi\\13.oszt\u00E1ly\\Neumann_Verseny\\fordulo_3\\Program\\Program.cs",
|
||||||
"RelativeToolTip": "Program.cs",
|
"RelativeToolTip": "Program.cs",
|
||||||
"ViewState": "AgIAAAMAAAAAAAAAAAAwwBQAAAA6AAAAAAAAAA==",
|
"ViewState": "AgIAAD8AAAAAAAAAAAAcwCcAAAAiAAAAAAAAAA==",
|
||||||
"Icon": "ae27a6b0-e345-4288-96df-5eaf394ee369.000738|",
|
"Icon": "ae27a6b0-e345-4288-96df-5eaf394ee369.000738|",
|
||||||
"WhenOpened": "2025-03-12T12:54:16.847Z",
|
"WhenOpened": "2025-03-12T12:54:16.847Z",
|
||||||
"EditorCaption": ""
|
"EditorCaption": ""
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"$type": "Document",
|
||||||
|
"DocumentIndex": 1,
|
||||||
|
"Title": "Virus.cs",
|
||||||
|
"DocumentMoniker": "E:\\H\u00E1zi\\13.oszt\u00E1ly\\Neumann_Verseny\\fordulo_3\\Program\\Virus.cs",
|
||||||
|
"RelativeDocumentMoniker": "Virus.cs",
|
||||||
|
"ToolTip": "E:\\H\u00E1zi\\13.oszt\u00E1ly\\Neumann_Verseny\\fordulo_3\\Program\\Virus.cs",
|
||||||
|
"RelativeToolTip": "Virus.cs",
|
||||||
|
"ViewState": "AgIAAAMAAAAAAAAAAAAAADIAAAABAAAAAAAAAA==",
|
||||||
|
"Icon": "ae27a6b0-e345-4288-96df-5eaf394ee369.000738|",
|
||||||
|
"WhenOpened": "2025-03-13T16:14:18.948Z",
|
||||||
|
"EditorCaption": ""
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,141 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace Program
|
||||||
|
{
|
||||||
|
class Feladat3
|
||||||
|
{
|
||||||
|
static void Feladat_3()
|
||||||
|
{
|
||||||
|
List<int> primes = new List<int>();
|
||||||
|
|
||||||
|
for (int i = 1000; i < 10000; i++)
|
||||||
|
{
|
||||||
|
if (IsPrime(i))
|
||||||
|
{
|
||||||
|
primes.Add(i);
|
||||||
|
string result = string.Join("", GetSortedDigits(i));
|
||||||
|
Console.WriteLine($"({i},{result}),");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
List<int[]> primesWithDecimalValuesOrdered = new List<int[]>();
|
||||||
|
|
||||||
|
foreach (int i in primes)
|
||||||
|
{
|
||||||
|
primesWithDecimalValuesOrdered.Add(GetSortedDigits(i));
|
||||||
|
}
|
||||||
|
|
||||||
|
var keyValuePairs = primesWithDecimalValuesOrdered
|
||||||
|
.GroupBy(x => x, new IntArrayComparer())
|
||||||
|
.Select(g => new KeyValuePair<int[], int>(g.Key, g.Count()))
|
||||||
|
.Where(kvp => kvp.Value >= 6)
|
||||||
|
.ToList().Count();
|
||||||
|
|
||||||
|
// Print the key-value pairs
|
||||||
|
/*
|
||||||
|
foreach (var kvp in keyValuePairs)
|
||||||
|
{
|
||||||
|
Console.WriteLine($"Key: {string.Join("", kvp.Key)}, Value: {kvp.Value}");
|
||||||
|
}
|
||||||
|
*/
|
||||||
|
|
||||||
|
Console.WriteLine(keyValuePairs);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
int[] digits = { 0, 1, 2, 2, 3, 3, 4, 5, 6, 7, 8, 9 };
|
||||||
|
int length = 4;
|
||||||
|
|
||||||
|
PermutationGenerator generator = new PermutationGenerator();
|
||||||
|
generator.GeneratePermutations(digits, length);
|
||||||
|
//generator.PrintGroupedPermutations();
|
||||||
|
|
||||||
|
// Get groups with at least 6 primes
|
||||||
|
var groupsWithAtLeast6Primes = generator.GroupedPermutations
|
||||||
|
.Where(group => group.Value.Count(permutation => IsPrime(int.Parse(string.Join("", permutation)))) >= 6)
|
||||||
|
.ToList();
|
||||||
|
|
||||||
|
// Print the groups with at least 6 primes
|
||||||
|
foreach (var group in groupsWithAtLeast6Primes)
|
||||||
|
{
|
||||||
|
Console.WriteLine($"Group: {group.Key}");
|
||||||
|
foreach (var permutation in group.Value)
|
||||||
|
{
|
||||||
|
Console.WriteLine(string.Join("", permutation));
|
||||||
|
}
|
||||||
|
Console.WriteLine();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
static int[] GetSortedDigits(int number)
|
||||||
|
{
|
||||||
|
// Convert the number to a string to access each digit
|
||||||
|
string numberString = number.ToString();
|
||||||
|
|
||||||
|
// Convert each character to an integer
|
||||||
|
int[] digits = numberString.Select(c => int.Parse(c.ToString())).ToArray();
|
||||||
|
|
||||||
|
// Sort the array of integers
|
||||||
|
Array.Sort(digits);
|
||||||
|
|
||||||
|
return digits;
|
||||||
|
}
|
||||||
|
|
||||||
|
static bool IsPrime(int number)
|
||||||
|
{
|
||||||
|
if (number <= 1) return false;
|
||||||
|
if (number == 2) return true;
|
||||||
|
if (number % 2 == 0) return false;
|
||||||
|
|
||||||
|
int boundary = (int)Math.Floor(Math.Sqrt(number));
|
||||||
|
|
||||||
|
for (int i = 3; i <= boundary; i += 2)
|
||||||
|
{
|
||||||
|
if (number % i == 0) return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
class IntArrayComparer : IEqualityComparer<int[]>
|
||||||
|
{
|
||||||
|
public bool Equals(int[] x, int[] y)
|
||||||
|
{
|
||||||
|
if (x == null || y == null)
|
||||||
|
return false;
|
||||||
|
|
||||||
|
if (x.Length != y.Length)
|
||||||
|
return false;
|
||||||
|
|
||||||
|
for (int i = 0; i < x.Length; i++)
|
||||||
|
{
|
||||||
|
if (x[i] != y[i])
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int GetHashCode(int[] obj)
|
||||||
|
{
|
||||||
|
if (obj == null)
|
||||||
|
return 0;
|
||||||
|
|
||||||
|
int hash = 17;
|
||||||
|
foreach (int i in obj)
|
||||||
|
{
|
||||||
|
hash = hash * 31 + i;
|
||||||
|
}
|
||||||
|
|
||||||
|
return hash;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
+106
-113
@@ -1,5 +1,6 @@
|
|||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
|
using System.IO;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
@@ -8,135 +9,127 @@ namespace Program
|
|||||||
{
|
{
|
||||||
class Program
|
class Program
|
||||||
{
|
{
|
||||||
|
public static Dictionary<int, List<int>> Contacts = new Dictionary<int, List<int>>();
|
||||||
|
public static HashSet<int> InfectedPeople = new HashSet<int>();
|
||||||
|
|
||||||
static void Main(string[] args)
|
static void Main(string[] args)
|
||||||
{
|
{
|
||||||
List<int> primes = new List<int>();
|
string path = $@"../../../forrasok/elek.txt";
|
||||||
|
|
||||||
for (int i = 1000; i < 10000; i++)
|
var data = File.ReadAllLines(path);
|
||||||
|
|
||||||
|
foreach (var item in data)
|
||||||
{
|
{
|
||||||
if (IsPrime(i))
|
string[] nums = item.Split(' ');
|
||||||
|
int infector = Convert.ToInt32(nums[0]);
|
||||||
|
int infected = Convert.ToInt32(nums[1]);
|
||||||
|
|
||||||
|
if (Contacts.ContainsKey(infector))
|
||||||
{
|
{
|
||||||
primes.Add(i);
|
Contacts[infector].Add(infected);
|
||||||
string result = string.Join("", GetSortedDigits(i));
|
}
|
||||||
Console.WriteLine($"({i},{result}),");
|
else
|
||||||
|
{
|
||||||
|
Contacts[infector] = new List<int> { infected };
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
List<int[]> primesWithDecimalValuesOrdered = new List<int[]>();
|
Virus rootVirus = new Virus(2);
|
||||||
|
InfectedPeople.Clear(); // Clear the set before starting the spread
|
||||||
|
InfectedPeople.Add(2); // Add the root virus to the infected set
|
||||||
|
SpreadBFS(rootVirus, 2);
|
||||||
|
//Spread(rootVirus, 9);
|
||||||
|
|
||||||
foreach (int i in primes)
|
//rootVirus.PrintInfectionTreeWithDepth(2, 0, "->");
|
||||||
{
|
rootVirus.PrintInfectionTree();
|
||||||
primesWithDecimalValuesOrdered.Add(GetSortedDigits(i));
|
|
||||||
|
Console.WriteLine(InfectedPeople.Count);
|
||||||
}
|
}
|
||||||
|
|
||||||
var keyValuePairs = primesWithDecimalValuesOrdered
|
|
||||||
.GroupBy(x => x, new IntArrayComparer())
|
|
||||||
.Select(g => new KeyValuePair<int[], int>(g.Key, g.Count()))
|
|
||||||
.Where(kvp => kvp.Value >= 6)
|
|
||||||
.ToList().Count();
|
|
||||||
|
|
||||||
// Print the key-value pairs
|
public static void SpreadBFS(Virus rootVirus, int maxDepth)
|
||||||
|
{
|
||||||
|
Queue<(Virus virus, int depth)> queue = new Queue<(Virus virus, int depth)>();
|
||||||
|
queue.Enqueue((rootVirus, 0));
|
||||||
|
|
||||||
|
while (queue.Count > 0)
|
||||||
|
{
|
||||||
|
var (currentVirus, currentDepth) = queue.Dequeue();
|
||||||
|
|
||||||
|
if (currentDepth >= maxDepth)
|
||||||
|
{
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (Contacts.ContainsKey(currentVirus.Name))
|
||||||
|
{
|
||||||
|
foreach (var contact in Contacts[currentVirus.Name])
|
||||||
|
{
|
||||||
|
if (!InfectedPeople.Contains(contact))
|
||||||
|
{
|
||||||
|
Virus newInfected = new Virus(contact, currentDepth + 1);
|
||||||
|
currentVirus.Infect(newInfected);
|
||||||
|
InfectedPeople.Add(contact); // Mark as infected
|
||||||
|
queue.Enqueue((newInfected, currentDepth + 1));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Check if the current virus should be healed
|
||||||
|
if (currentDepth - currentVirus.InfectionTurn >= 8)
|
||||||
|
{
|
||||||
|
InfectedPeople.Remove(currentVirus.Name);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void Spread(Virus virus, int maxDepth, int currentDepth = 0)
|
||||||
|
{
|
||||||
|
if (currentDepth >= maxDepth)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (Contacts.ContainsKey(virus.Name))
|
||||||
|
{
|
||||||
|
foreach (var contact in Contacts[virus.Name])
|
||||||
|
{
|
||||||
|
if (!InfectedPeople.Contains(contact))
|
||||||
|
{
|
||||||
|
Virus newInfected = new Virus(contact);
|
||||||
|
virus.Infect(newInfected);
|
||||||
|
InfectedPeople.Add(contact); // Mark as infected
|
||||||
|
Spread(newInfected, maxDepth, currentDepth + 1);
|
||||||
|
} else
|
||||||
|
{
|
||||||
|
Virus newInfected = new Virus(contact);
|
||||||
|
virus.Infect(newInfected);
|
||||||
|
//InfectedPeople.Add(contact); // Mark as infected
|
||||||
|
Spread(newInfected, maxDepth, currentDepth + 1);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
foreach (var kvp in keyValuePairs)
|
public static void Spread(Virus virus)
|
||||||
{
|
{
|
||||||
Console.WriteLine($"Key: {string.Join("", kvp.Key)}, Value: {kvp.Value}");
|
if (Contacts.ContainsKey(virus.Name))
|
||||||
|
{
|
||||||
|
foreach (var contact in Contacts[virus.Name])
|
||||||
|
{
|
||||||
|
if (!InfectedPeople.Contains(contact))
|
||||||
|
{
|
||||||
|
Virus newInfected = new Virus(contact);
|
||||||
|
virus.Infect(newInfected);
|
||||||
|
InfectedPeople.Add(contact); // Mark as infected
|
||||||
|
Spread(newInfected);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
*/
|
*/
|
||||||
|
|
||||||
Console.WriteLine(keyValuePairs);
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
int[] digits = { 0, 1, 2, 2, 3, 3, 4, 5, 6, 7, 8, 9 };
|
|
||||||
int length = 4;
|
|
||||||
|
|
||||||
PermutationGenerator generator = new PermutationGenerator();
|
|
||||||
generator.GeneratePermutations(digits, length);
|
|
||||||
//generator.PrintGroupedPermutations();
|
|
||||||
|
|
||||||
// Get groups with at least 6 primes
|
|
||||||
var groupsWithAtLeast6Primes = generator.GroupedPermutations
|
|
||||||
.Where(group => group.Value.Count(permutation => IsPrime(int.Parse(string.Join("", permutation)))) >= 6)
|
|
||||||
.ToList();
|
|
||||||
|
|
||||||
// Print the groups with at least 6 primes
|
|
||||||
foreach (var group in groupsWithAtLeast6Primes)
|
|
||||||
{
|
|
||||||
Console.WriteLine($"Group: {group.Key}");
|
|
||||||
foreach (var permutation in group.Value)
|
|
||||||
{
|
|
||||||
Console.WriteLine(string.Join("", permutation));
|
|
||||||
}
|
|
||||||
Console.WriteLine();
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
static int[] GetSortedDigits(int number)
|
|
||||||
{
|
|
||||||
// Convert the number to a string to access each digit
|
|
||||||
string numberString = number.ToString();
|
|
||||||
|
|
||||||
// Convert each character to an integer
|
|
||||||
int[] digits = numberString.Select(c => int.Parse(c.ToString())).ToArray();
|
|
||||||
|
|
||||||
// Sort the array of integers
|
|
||||||
Array.Sort(digits);
|
|
||||||
|
|
||||||
return digits;
|
|
||||||
}
|
|
||||||
|
|
||||||
static bool IsPrime(int number)
|
|
||||||
{
|
|
||||||
if (number <= 1) return false;
|
|
||||||
if (number == 2) return true;
|
|
||||||
if (number % 2 == 0) return false;
|
|
||||||
|
|
||||||
int boundary = (int)Math.Floor(Math.Sqrt(number));
|
|
||||||
|
|
||||||
for (int i = 3; i <= boundary; i += 2)
|
|
||||||
{
|
|
||||||
if (number % i == 0) return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
class IntArrayComparer : IEqualityComparer<int[]>
|
|
||||||
{
|
|
||||||
public bool Equals(int[] x, int[] y)
|
|
||||||
{
|
|
||||||
if (x == null || y == null)
|
|
||||||
return false;
|
|
||||||
|
|
||||||
if (x.Length != y.Length)
|
|
||||||
return false;
|
|
||||||
|
|
||||||
for (int i = 0; i < x.Length; i++)
|
|
||||||
{
|
|
||||||
if (x[i] != y[i])
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
public int GetHashCode(int[] obj)
|
|
||||||
{
|
|
||||||
if (obj == null)
|
|
||||||
return 0;
|
|
||||||
|
|
||||||
int hash = 17;
|
|
||||||
foreach (int i in obj)
|
|
||||||
{
|
|
||||||
hash = hash * 31 + i;
|
|
||||||
}
|
|
||||||
|
|
||||||
return hash;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -43,10 +43,12 @@
|
|||||||
<Reference Include="System.Xml" />
|
<Reference Include="System.Xml" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
|
<Compile Include="Feladat3.cs" />
|
||||||
<Compile Include="PermutationGenerator.cs" />
|
<Compile Include="PermutationGenerator.cs" />
|
||||||
<Compile Include="Program.cs" />
|
<Compile Include="Program.cs" />
|
||||||
<Compile Include="Properties\AssemblyInfo.cs" />
|
<Compile Include="Properties\AssemblyInfo.cs" />
|
||||||
<Compile Include="Sorozat.cs" />
|
<Compile Include="Sorozat.cs" />
|
||||||
|
<Compile Include="Virus.cs" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<None Include="App.config" />
|
<None Include="App.config" />
|
||||||
|
|||||||
@@ -0,0 +1,51 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
|
||||||
|
namespace Program
|
||||||
|
{
|
||||||
|
public class Virus
|
||||||
|
{
|
||||||
|
public int Name { get; set; }
|
||||||
|
public Virus Parent { get; set; }
|
||||||
|
public List<Virus> Infected { get; private set; }
|
||||||
|
public int InfectionTurn { get; set; }
|
||||||
|
|
||||||
|
public Virus(int name, int infectionTurn = 0)
|
||||||
|
{
|
||||||
|
Name = name;
|
||||||
|
Infected = new List<Virus>();
|
||||||
|
InfectionTurn = infectionTurn;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Virus(int name, Virus parent, int infectionTurn = 0) : this(name, infectionTurn)
|
||||||
|
{
|
||||||
|
Parent = parent;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void Infect(Virus virus)
|
||||||
|
{
|
||||||
|
virus.Parent = this;
|
||||||
|
Infected.Add(virus);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void PrintInfectionTree(string indent = "")
|
||||||
|
{
|
||||||
|
Console.WriteLine($"{indent}Virus {Name}");
|
||||||
|
foreach (var infected in Infected)
|
||||||
|
{
|
||||||
|
infected.PrintInfectionTree(indent + " ");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void PrintInfectionTreeWithDepth(int maxDepth, int currentDepth = 0, string indent = "")
|
||||||
|
{
|
||||||
|
if (currentDepth > maxDepth) return;
|
||||||
|
|
||||||
|
Console.WriteLine($"{indent}Virus {Name}");
|
||||||
|
foreach (var infected in Infected)
|
||||||
|
{
|
||||||
|
infected.PrintInfectionTreeWithDepth(maxDepth, currentDepth + 1, indent + " ");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
Binary file not shown.
Binary file not shown.
Binary file not shown.
@@ -1 +1 @@
|
|||||||
0f60ae438c65b1815603680249bf9a5d03a307c39118102277870be2ddb77ab4
|
ca659b73ef474311d403419aa47bed331b1360853dc02e88fb5dee915c0be9c6
|
||||||
Binary file not shown.
Binary file not shown.
File diff suppressed because it is too large.
Load diff
+1
-1
@@ -49,7 +49,7 @@
|
|||||||
|
|
||||||
### 3. feladat
|
### 3. feladat
|
||||||
- a: `42`
|
- a: `42`
|
||||||
- b: ``
|
- b: `296962999629`
|
||||||
|
|
||||||
### 4. feladat
|
### 4. feladat
|
||||||
- a: ``
|
- a: ``
|
||||||
|
|||||||
Reference in new issue
Block a user