solution found for feladat 2
This commit is contained in:
parent
c83b7eacbd
commit
490efd2fcc
fordulo_3/Program
.vs/Program
CopilotIndices/17.13.431.34963
FileContentIndex
628ed0ad-8049-492c-95bc-a594579de0f6.vsidx709cd04e-3822-46cd-877c-58cf2aa34676.vsidxc5e1a060-b5a3-4a37-83b6-4d15ff12fdfb.vsidxfeb9953c-1d6a-4dd8-b9aa-8c2bba9ba3d5.vsidx
copilot-chat/f9c248b7/sessions
v17
bin/Debug
obj/Debug
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
|
@ -2,13 +2,13 @@
|
|||
"Version": 1,
|
||||
"WorkspaceRootPath": "E:\\H\u00E1zi\\13.oszt\u00E1ly\\Neumann_Verseny\\fordulo_3\\Program\\",
|
||||
"Documents": [
|
||||
{
|
||||
"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}"
|
||||
},
|
||||
{
|
||||
"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}",
|
||||
"RelativeMoniker": "D:0:0:{6A74A9DE-500D-46FF-859A-18F4A752D2A5}|Program.csproj|solutionrelative:program.cs||{A6C744A8-0E4A-4FC6-886A-064283054674}"
|
||||
}
|
||||
],
|
||||
"DocumentGroupContainers": [
|
||||
|
@ -18,33 +18,32 @@
|
|||
"DocumentGroups": [
|
||||
{
|
||||
"DockedWidth": 200,
|
||||
"SelectedChildIndex": 1,
|
||||
"SelectedChildIndex": 0,
|
||||
"Children": [
|
||||
{
|
||||
"$type": "Document",
|
||||
"DocumentIndex": 1,
|
||||
"DocumentIndex": 0,
|
||||
"Title": "Sorozat.cs",
|
||||
"DocumentMoniker": "E:\\H\u00E1zi\\13.oszt\u00E1ly\\Neumann_Verseny\\fordulo_3\\Program\\Sorozat.cs",
|
||||
"RelativeDocumentMoniker": "Sorozat.cs",
|
||||
"ToolTip": "E:\\H\u00E1zi\\13.oszt\u00E1ly\\Neumann_Verseny\\fordulo_3\\Program\\Sorozat.cs",
|
||||
"RelativeToolTip": "Sorozat.cs",
|
||||
"ViewState": "AgIAAAgAAAAAAAAAAAAxwBkAAAAcAAAAAAAAAA==",
|
||||
"ViewState": "AgIAABwAAAAAAAAAAAAYwCMAAAAaAAAAAAAAAA==",
|
||||
"Icon": "ae27a6b0-e345-4288-96df-5eaf394ee369.000738|",
|
||||
"WhenOpened": "2025-03-12T12:59:58.311Z",
|
||||
"EditorCaption": ""
|
||||
},
|
||||
{
|
||||
"$type": "Document",
|
||||
"DocumentIndex": 0,
|
||||
"DocumentIndex": 1,
|
||||
"Title": "Program.cs",
|
||||
"DocumentMoniker": "E:\\H\u00E1zi\\13.oszt\u00E1ly\\Neumann_Verseny\\fordulo_3\\Program\\Program.cs",
|
||||
"RelativeDocumentMoniker": "Program.cs",
|
||||
"ToolTip": "E:\\H\u00E1zi\\13.oszt\u00E1ly\\Neumann_Verseny\\fordulo_3\\Program\\Program.cs",
|
||||
"RelativeToolTip": "Program.cs",
|
||||
"ViewState": "AgIAAAQAAAAAAAAAAAAUwCEAAABqAAAAAAAAAA==",
|
||||
"ViewState": "AgIAAAAAAAAAAAAAAAAAAA4AAAAzAAAAAAAAAA==",
|
||||
"Icon": "ae27a6b0-e345-4288-96df-5eaf394ee369.000738|",
|
||||
"WhenOpened": "2025-03-12T12:54:16.847Z",
|
||||
"EditorCaption": ""
|
||||
"WhenOpened": "2025-03-12T12:54:16.847Z"
|
||||
}
|
||||
]
|
||||
}
|
||||
|
|
|
@ -2,13 +2,13 @@
|
|||
"Version": 1,
|
||||
"WorkspaceRootPath": "E:\\H\u00E1zi\\13.oszt\u00E1ly\\Neumann_Verseny\\fordulo_3\\Program\\",
|
||||
"Documents": [
|
||||
{
|
||||
"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}"
|
||||
},
|
||||
{
|
||||
"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}",
|
||||
"RelativeMoniker": "D:0:0:{6A74A9DE-500D-46FF-859A-18F4A752D2A5}|Program.csproj|solutionrelative:program.cs||{A6C744A8-0E4A-4FC6-886A-064283054674}"
|
||||
}
|
||||
],
|
||||
"DocumentGroupContainers": [
|
||||
|
@ -18,33 +18,32 @@
|
|||
"DocumentGroups": [
|
||||
{
|
||||
"DockedWidth": 200,
|
||||
"SelectedChildIndex": 1,
|
||||
"SelectedChildIndex": 0,
|
||||
"Children": [
|
||||
{
|
||||
"$type": "Document",
|
||||
"DocumentIndex": 1,
|
||||
"DocumentIndex": 0,
|
||||
"Title": "Sorozat.cs",
|
||||
"DocumentMoniker": "E:\\H\u00E1zi\\13.oszt\u00E1ly\\Neumann_Verseny\\fordulo_3\\Program\\Sorozat.cs",
|
||||
"RelativeDocumentMoniker": "Sorozat.cs",
|
||||
"ToolTip": "E:\\H\u00E1zi\\13.oszt\u00E1ly\\Neumann_Verseny\\fordulo_3\\Program\\Sorozat.cs",
|
||||
"RelativeToolTip": "Sorozat.cs",
|
||||
"ViewState": "AgIAAAgAAAAAAAAAAAAxwBkAAAAcAAAAAAAAAA==",
|
||||
"ViewState": "AgIAABwAAAAAAAAAAAAYwCMAAAAaAAAAAAAAAA==",
|
||||
"Icon": "ae27a6b0-e345-4288-96df-5eaf394ee369.000738|",
|
||||
"WhenOpened": "2025-03-12T12:59:58.311Z",
|
||||
"EditorCaption": ""
|
||||
},
|
||||
{
|
||||
"$type": "Document",
|
||||
"DocumentIndex": 0,
|
||||
"DocumentIndex": 1,
|
||||
"Title": "Program.cs",
|
||||
"DocumentMoniker": "E:\\H\u00E1zi\\13.oszt\u00E1ly\\Neumann_Verseny\\fordulo_3\\Program\\Program.cs",
|
||||
"RelativeDocumentMoniker": "Program.cs",
|
||||
"ToolTip": "E:\\H\u00E1zi\\13.oszt\u00E1ly\\Neumann_Verseny\\fordulo_3\\Program\\Program.cs",
|
||||
"RelativeToolTip": "Program.cs",
|
||||
"ViewState": "AgIAAAQAAAAAAAAAAAAUwCEAAABqAAAAAAAAAA==",
|
||||
"ViewState": "AgIAAAAAAAAAAAAAAAAAAA4AAAAzAAAAAAAAAA==",
|
||||
"Icon": "ae27a6b0-e345-4288-96df-5eaf394ee369.000738|",
|
||||
"WhenOpened": "2025-03-12T12:54:16.847Z",
|
||||
"EditorCaption": ""
|
||||
"WhenOpened": "2025-03-12T12:54:16.847Z"
|
||||
}
|
||||
]
|
||||
}
|
||||
|
|
|
@ -10,28 +10,9 @@ namespace Program
|
|||
{
|
||||
static void Main(string[] args)
|
||||
{
|
||||
Sorozat leghosszabb = new Sorozat(77031);
|
||||
leghosszabb.TagokKiszamitasa(leghosszabb.KezdoErtek);
|
||||
Sorozat.ComputeCollatz(1000000);
|
||||
|
||||
int max = 110000;
|
||||
int min = 100000;
|
||||
|
||||
|
||||
for (int i = min; i < max; i++)
|
||||
{
|
||||
Sorozat sorozat = new Sorozat(i);
|
||||
sorozat.TagokKiszamitasa(sorozat.KezdoErtek);
|
||||
if (sorozat.Tagok.Count > leghosszabb.Tagok.Count)
|
||||
{
|
||||
leghosszabb = new Sorozat(sorozat);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// mivel 1.000.000 számot kell megvizsgálin ezért ez a fajta megoldás nem jó
|
||||
//Sorozat leghosszabb = sorozatok.OrderByDescending(x => x.Tagok.Count).First();
|
||||
|
||||
Console.WriteLine($"2. feladat megoldás: {leghosszabb.KezdoErtek}|{leghosszabb.Tagok.Count}");
|
||||
Sorozat.CollatzLengthWithPrint(837799);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -8,64 +8,71 @@ namespace Program
|
|||
{
|
||||
class Sorozat
|
||||
{
|
||||
public int KezdoErtek;
|
||||
static Dictionary<long, int> memo = new Dictionary<long, int>();
|
||||
|
||||
public List<int> Tagok = new List<int>();
|
||||
static int CollatzLength(long n) {
|
||||
|
||||
int[] kettoHatvanyok = new int[] { 1, 2, 4, 8, 16, 32, 64, 128, 256, 512, 1024, 2048, 4096, 8192, 16384, 32768, 65536, 131072, 262144, 524288, 1048576, 2097152, 4194304, 8388608 };
|
||||
long original = n;
|
||||
int count = 0;
|
||||
|
||||
public int TagokKiszamitasa(int ertek)
|
||||
{
|
||||
int ujertek;
|
||||
|
||||
if (kettoHatvanyok.Contains(ertek))
|
||||
while (n != 1 && !memo.ContainsKey(n))
|
||||
{
|
||||
int index = 0;
|
||||
while (kettoHatvanyok[index] != ertek)
|
||||
if (n % 2 == 0)
|
||||
{
|
||||
index++;
|
||||
n /= 2;
|
||||
} else
|
||||
{
|
||||
n = n * 3 + 1;
|
||||
}
|
||||
|
||||
KettoHatvanyokTagokHozzaAdasa(index);
|
||||
|
||||
return 1;
|
||||
count++;
|
||||
}
|
||||
|
||||
if (ertek == 1) {
|
||||
Tagok.Add(ertek);
|
||||
return 1;
|
||||
}
|
||||
|
||||
if (ertek % 2 == 0)
|
||||
if (memo.ContainsKey(n))
|
||||
{
|
||||
ujertek = ertek / 2;
|
||||
|
||||
} else
|
||||
{
|
||||
ujertek = ertek * 3 + 1;
|
||||
count += memo[n];
|
||||
}
|
||||
|
||||
Tagok.Add(ertek);
|
||||
return TagokKiszamitasa(ujertek);
|
||||
memo[original] = count;
|
||||
return count;
|
||||
}
|
||||
|
||||
public void KettoHatvanyokTagokHozzaAdasa(int index)
|
||||
public static void CollatzLengthWithPrint(long n)
|
||||
{
|
||||
for (int i = index; i >= 0; i--)
|
||||
|
||||
long original = n;
|
||||
int count = 0;
|
||||
|
||||
while (n != 1)
|
||||
{
|
||||
Tagok.Add(kettoHatvanyok[i]);
|
||||
if (n % 2 == 0)
|
||||
{
|
||||
n /= 2;
|
||||
}
|
||||
else
|
||||
{
|
||||
n = n * 3 + 1;
|
||||
}
|
||||
count++;
|
||||
Console.WriteLine(n);
|
||||
}
|
||||
}
|
||||
|
||||
public Sorozat(Sorozat sorozat)
|
||||
public static void ComputeCollatz(int limit)
|
||||
{
|
||||
KezdoErtek = sorozat.KezdoErtek;
|
||||
Tagok = sorozat.Tagok;
|
||||
}
|
||||
int maxLenght = 0;
|
||||
int maxNumber = 0;
|
||||
|
||||
public Sorozat(int kezdoErtek)
|
||||
{
|
||||
this.KezdoErtek = kezdoErtek;
|
||||
for (int i = 1; i < limit; i++)
|
||||
{
|
||||
int length = Sorozat.CollatzLength(i);
|
||||
if (length > maxLenght)
|
||||
{
|
||||
maxLenght = length;
|
||||
maxNumber = i;
|
||||
}
|
||||
}
|
||||
|
||||
Console.WriteLine($"2. feladat megoldás: {maxNumber}|{maxLenght}");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
|
@ -36,3 +36,21 @@
|
|||
- a: `213`
|
||||
- b: `KULDJPENZT`
|
||||
- c: `APU FUTYUL ORRUK MIATT APU SIET SIET HAZA ORRUK LETOR TOVIG BIZONY LETOR`
|
||||
|
||||
## 3. Forduló
|
||||
|
||||
### 1. feladat
|
||||
- a: ``
|
||||
- b: ``
|
||||
- c: ``
|
||||
|
||||
### 2. feladat
|
||||
- `837799|524`
|
||||
|
||||
### 3. feladat
|
||||
- a: ``
|
||||
- b: ``
|
||||
|
||||
### 4. feladat
|
||||
- a: ``
|
||||
- b: ``
|
||||
|
|
Loading…
Reference in New Issue
Block a user