This commit is contained in:
Digi 2025-03-12 21:04:26 +01:00
parent 490efd2fcc
commit f92b3d93ef
20 changed files with 1300 additions and 36 deletions

View File

@ -2,13 +2,13 @@
"Version": 1, "Version": 1,
"WorkspaceRootPath": "E:\\H\u00E1zi\\13.oszt\u00E1ly\\Neumann_Verseny\\fordulo_3\\Program\\", "WorkspaceRootPath": "E:\\H\u00E1zi\\13.oszt\u00E1ly\\Neumann_Verseny\\fordulo_3\\Program\\",
"Documents": [ "Documents": [
{
"AbsoluteMoniker": "D:0:0:{6A74A9DE-500D-46FF-859A-18F4A752D2A5}|Program.csproj|e:\\h\u00E1zi\\13.oszt\u00E1ly\\neumann_verseny\\fordulo_3\\program\\sorozat.cs||{A6C744A8-0E4A-4FC6-886A-064283054674}",
"RelativeMoniker": "D:0:0:{6A74A9DE-500D-46FF-859A-18F4A752D2A5}|Program.csproj|solutionrelative:sorozat.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\\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\\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}" "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}",
"RelativeMoniker": "D:0:0:{6A74A9DE-500D-46FF-859A-18F4A752D2A5}|Program.csproj|solutionrelative:permutationgenerator.cs||{A6C744A8-0E4A-4FC6-886A-064283054674}"
} }
], ],
"DocumentGroupContainers": [ "DocumentGroupContainers": [
@ -18,32 +18,33 @@
"DocumentGroups": [ "DocumentGroups": [
{ {
"DockedWidth": 200, "DockedWidth": 200,
"SelectedChildIndex": 0, "SelectedChildIndex": 2,
"Children": [ "Children": [
{ {
"$type": "Document", "$type": "Document",
"DocumentIndex": 0, "DocumentIndex": 1,
"Title": "Sorozat.cs", "Title": "PermutationGenerator.cs",
"DocumentMoniker": "E:\\H\u00E1zi\\13.oszt\u00E1ly\\Neumann_Verseny\\fordulo_3\\Program\\Sorozat.cs", "DocumentMoniker": "E:\\H\u00E1zi\\13.oszt\u00E1ly\\Neumann_Verseny\\fordulo_3\\Program\\PermutationGenerator.cs",
"RelativeDocumentMoniker": "Sorozat.cs", "RelativeDocumentMoniker": "PermutationGenerator.cs",
"ToolTip": "E:\\H\u00E1zi\\13.oszt\u00E1ly\\Neumann_Verseny\\fordulo_3\\Program\\Sorozat.cs", "ToolTip": "E:\\H\u00E1zi\\13.oszt\u00E1ly\\Neumann_Verseny\\fordulo_3\\Program\\PermutationGenerator.cs",
"RelativeToolTip": "Sorozat.cs", "RelativeToolTip": "PermutationGenerator.cs",
"ViewState": "AgIAABwAAAAAAAAAAAAYwCMAAAAaAAAAAAAAAA==", "ViewState": "AgIAAAAAAAAAAAAAAAAAABMAAAA8AAAAAAAAAA==",
"Icon": "ae27a6b0-e345-4288-96df-5eaf394ee369.000738|", "Icon": "ae27a6b0-e345-4288-96df-5eaf394ee369.000738|",
"WhenOpened": "2025-03-12T12:59:58.311Z", "WhenOpened": "2025-03-12T17:31:40.758Z",
"EditorCaption": "" "EditorCaption": ""
}, },
{ {
"$type": "Document", "$type": "Document",
"DocumentIndex": 1, "DocumentIndex": 0,
"Title": "Program.cs", "Title": "Program.cs",
"DocumentMoniker": "E:\\H\u00E1zi\\13.oszt\u00E1ly\\Neumann_Verseny\\fordulo_3\\Program\\Program.cs", "DocumentMoniker": "E:\\H\u00E1zi\\13.oszt\u00E1ly\\Neumann_Verseny\\fordulo_3\\Program\\Program.cs",
"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": "AgIAAAAAAAAAAAAAAAAAAA4AAAAzAAAAAAAAAA==", "ViewState": "AgIAAAMAAAAAAAAAAAAwwBQAAAA6AAAAAAAAAA==",
"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": ""
} }
] ]
} }

View File

@ -2,13 +2,13 @@
"Version": 1, "Version": 1,
"WorkspaceRootPath": "E:\\H\u00E1zi\\13.oszt\u00E1ly\\Neumann_Verseny\\fordulo_3\\Program\\", "WorkspaceRootPath": "E:\\H\u00E1zi\\13.oszt\u00E1ly\\Neumann_Verseny\\fordulo_3\\Program\\",
"Documents": [ "Documents": [
{
"AbsoluteMoniker": "D:0:0:{6A74A9DE-500D-46FF-859A-18F4A752D2A5}|Program.csproj|e:\\h\u00E1zi\\13.oszt\u00E1ly\\neumann_verseny\\fordulo_3\\program\\sorozat.cs||{A6C744A8-0E4A-4FC6-886A-064283054674}",
"RelativeMoniker": "D:0:0:{6A74A9DE-500D-46FF-859A-18F4A752D2A5}|Program.csproj|solutionrelative:sorozat.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\\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\\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}" "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}",
"RelativeMoniker": "D:0:0:{6A74A9DE-500D-46FF-859A-18F4A752D2A5}|Program.csproj|solutionrelative:permutationgenerator.cs||{A6C744A8-0E4A-4FC6-886A-064283054674}"
} }
], ],
"DocumentGroupContainers": [ "DocumentGroupContainers": [
@ -18,32 +18,33 @@
"DocumentGroups": [ "DocumentGroups": [
{ {
"DockedWidth": 200, "DockedWidth": 200,
"SelectedChildIndex": 0, "SelectedChildIndex": 2,
"Children": [ "Children": [
{ {
"$type": "Document", "$type": "Document",
"DocumentIndex": 0, "DocumentIndex": 1,
"Title": "Sorozat.cs", "Title": "PermutationGenerator.cs",
"DocumentMoniker": "E:\\H\u00E1zi\\13.oszt\u00E1ly\\Neumann_Verseny\\fordulo_3\\Program\\Sorozat.cs", "DocumentMoniker": "E:\\H\u00E1zi\\13.oszt\u00E1ly\\Neumann_Verseny\\fordulo_3\\Program\\PermutationGenerator.cs",
"RelativeDocumentMoniker": "Sorozat.cs", "RelativeDocumentMoniker": "PermutationGenerator.cs",
"ToolTip": "E:\\H\u00E1zi\\13.oszt\u00E1ly\\Neumann_Verseny\\fordulo_3\\Program\\Sorozat.cs", "ToolTip": "E:\\H\u00E1zi\\13.oszt\u00E1ly\\Neumann_Verseny\\fordulo_3\\Program\\PermutationGenerator.cs",
"RelativeToolTip": "Sorozat.cs", "RelativeToolTip": "PermutationGenerator.cs",
"ViewState": "AgIAABwAAAAAAAAAAAAYwCMAAAAaAAAAAAAAAA==", "ViewState": "AgIAAAAAAAAAAAAAAAAAABMAAAA8AAAAAAAAAA==",
"Icon": "ae27a6b0-e345-4288-96df-5eaf394ee369.000738|", "Icon": "ae27a6b0-e345-4288-96df-5eaf394ee369.000738|",
"WhenOpened": "2025-03-12T12:59:58.311Z", "WhenOpened": "2025-03-12T17:31:40.758Z",
"EditorCaption": "" "EditorCaption": ""
}, },
{ {
"$type": "Document", "$type": "Document",
"DocumentIndex": 1, "DocumentIndex": 0,
"Title": "Program.cs", "Title": "Program.cs",
"DocumentMoniker": "E:\\H\u00E1zi\\13.oszt\u00E1ly\\Neumann_Verseny\\fordulo_3\\Program\\Program.cs", "DocumentMoniker": "E:\\H\u00E1zi\\13.oszt\u00E1ly\\Neumann_Verseny\\fordulo_3\\Program\\Program.cs",
"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": "AgIAAAAAAAAAAAAAAAAAAA4AAAAzAAAAAAAAAA==", "ViewState": "AgIAAAMAAAAAAAAAAAAwwBQAAAA6AAAAAAAAAA==",
"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": ""
} }
] ]
} }

View File

@ -0,0 +1,73 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Program
{
class PermutationGenerator
{
public Dictionary<string, List<int[]>> GroupedPermutations { get; private set; }
private HashSet<string> uniquePermutations;
public PermutationGenerator()
{
GroupedPermutations = new Dictionary<string, List<int[]>>();
uniquePermutations = new HashSet<string>();
}
public void GeneratePermutations(int[] digits, int length)
{
GeneratePermutations(digits, new int[length], 0);
}
private void GeneratePermutations(int[] digits, int[] current, int index)
{
if (index == current.Length)
{
if (current[0] != 0) // Avoid permutations starting with 0
{
AddPermutation(current);
}
return;
}
for (int i = 0; i < digits.Length; i++)
{
current[index] = digits[i];
GeneratePermutations(digits, current, index + 1);
}
}
private void AddPermutation(int[] permutation)
{
var key = string.Concat(permutation.OrderBy(x => x));
var permutationString = string.Join("", permutation);
if (!uniquePermutations.Contains(permutationString))
{
uniquePermutations.Add(permutationString);
if (!GroupedPermutations.ContainsKey(key))
{
GroupedPermutations[key] = new List<int[]>();
}
GroupedPermutations[key].Add((int[])permutation.Clone());
}
}
public void PrintGroupedPermutations()
{
foreach (var group in GroupedPermutations)
{
Console.WriteLine($"Group: {group.Key}");
foreach (var permutation in group.Value)
{
Console.WriteLine(string.Join("", permutation));
}
Console.WriteLine();
}
}
}
}

View File

@ -10,9 +10,133 @@ namespace Program
{ {
static void Main(string[] args) static void Main(string[] args)
{ {
Sorozat.ComputeCollatz(1000000); List<int> primes = new List<int>();
Sorozat.CollatzLengthWithPrint(837799); 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;
} }
} }
} }

View File

@ -43,6 +43,7 @@
<Reference Include="System.Xml" /> <Reference Include="System.Xml" />
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<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" />

View File

@ -1 +1 @@
52261ac204714890afe2467c25b9765789d39c141c743f2c478f13be997c8941 0f60ae438c65b1815603680249bf9a5d03a307c39118102277870be2ddb77ab4

1064
fordulo_3/primek.sql Normal file

File diff suppressed because it is too large Load Diff

View File

@ -48,7 +48,7 @@
- `837799|524` - `837799|524`
### 3. feladat ### 3. feladat
- a: `` - a: `42`
- b: `` - b: ``
### 4. feladat ### 4. feladat