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,
|
"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\\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}",
|
"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}"
|
"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": [
|
"DocumentGroupContainers": [
|
||||||
|
@ -18,33 +18,32 @@
|
||||||
"DocumentGroups": [
|
"DocumentGroups": [
|
||||||
{
|
{
|
||||||
"DockedWidth": 200,
|
"DockedWidth": 200,
|
||||||
"SelectedChildIndex": 1,
|
"SelectedChildIndex": 0,
|
||||||
"Children": [
|
"Children": [
|
||||||
{
|
{
|
||||||
"$type": "Document",
|
"$type": "Document",
|
||||||
"DocumentIndex": 1,
|
"DocumentIndex": 0,
|
||||||
"Title": "Sorozat.cs",
|
"Title": "Sorozat.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\\Sorozat.cs",
|
||||||
"RelativeDocumentMoniker": "Sorozat.cs",
|
"RelativeDocumentMoniker": "Sorozat.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\\Sorozat.cs",
|
||||||
"RelativeToolTip": "Sorozat.cs",
|
"RelativeToolTip": "Sorozat.cs",
|
||||||
"ViewState": "AgIAAAgAAAAAAAAAAAAxwBkAAAAcAAAAAAAAAA==",
|
"ViewState": "AgIAABwAAAAAAAAAAAAYwCMAAAAaAAAAAAAAAA==",
|
||||||
"Icon": "ae27a6b0-e345-4288-96df-5eaf394ee369.000738|",
|
"Icon": "ae27a6b0-e345-4288-96df-5eaf394ee369.000738|",
|
||||||
"WhenOpened": "2025-03-12T12:59:58.311Z",
|
"WhenOpened": "2025-03-12T12:59:58.311Z",
|
||||||
"EditorCaption": ""
|
"EditorCaption": ""
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"$type": "Document",
|
"$type": "Document",
|
||||||
"DocumentIndex": 0,
|
"DocumentIndex": 1,
|
||||||
"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": "AgIAAAQAAAAAAAAAAAAUwCEAAABqAAAAAAAAAA==",
|
"ViewState": "AgIAAAAAAAAAAAAAAAAAAA4AAAAzAAAAAAAAAA==",
|
||||||
"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": ""
|
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
|
|
@ -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\\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}",
|
"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}"
|
"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": [
|
"DocumentGroupContainers": [
|
||||||
|
@ -18,33 +18,32 @@
|
||||||
"DocumentGroups": [
|
"DocumentGroups": [
|
||||||
{
|
{
|
||||||
"DockedWidth": 200,
|
"DockedWidth": 200,
|
||||||
"SelectedChildIndex": 1,
|
"SelectedChildIndex": 0,
|
||||||
"Children": [
|
"Children": [
|
||||||
{
|
{
|
||||||
"$type": "Document",
|
"$type": "Document",
|
||||||
"DocumentIndex": 1,
|
"DocumentIndex": 0,
|
||||||
"Title": "Sorozat.cs",
|
"Title": "Sorozat.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\\Sorozat.cs",
|
||||||
"RelativeDocumentMoniker": "Sorozat.cs",
|
"RelativeDocumentMoniker": "Sorozat.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\\Sorozat.cs",
|
||||||
"RelativeToolTip": "Sorozat.cs",
|
"RelativeToolTip": "Sorozat.cs",
|
||||||
"ViewState": "AgIAAAgAAAAAAAAAAAAxwBkAAAAcAAAAAAAAAA==",
|
"ViewState": "AgIAABwAAAAAAAAAAAAYwCMAAAAaAAAAAAAAAA==",
|
||||||
"Icon": "ae27a6b0-e345-4288-96df-5eaf394ee369.000738|",
|
"Icon": "ae27a6b0-e345-4288-96df-5eaf394ee369.000738|",
|
||||||
"WhenOpened": "2025-03-12T12:59:58.311Z",
|
"WhenOpened": "2025-03-12T12:59:58.311Z",
|
||||||
"EditorCaption": ""
|
"EditorCaption": ""
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"$type": "Document",
|
"$type": "Document",
|
||||||
"DocumentIndex": 0,
|
"DocumentIndex": 1,
|
||||||
"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": "AgIAAAQAAAAAAAAAAAAUwCEAAABqAAAAAAAAAA==",
|
"ViewState": "AgIAAAAAAAAAAAAAAAAAAA4AAAAzAAAAAAAAAA==",
|
||||||
"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": ""
|
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
|
|
@ -10,28 +10,9 @@ namespace Program
|
||||||
{
|
{
|
||||||
static void Main(string[] args)
|
static void Main(string[] args)
|
||||||
{
|
{
|
||||||
Sorozat leghosszabb = new Sorozat(77031);
|
Sorozat.ComputeCollatz(1000000);
|
||||||
leghosszabb.TagokKiszamitasa(leghosszabb.KezdoErtek);
|
|
||||||
|
|
||||||
int max = 110000;
|
Sorozat.CollatzLengthWithPrint(837799);
|
||||||
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}");
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -8,64 +8,71 @@ namespace Program
|
||||||
{
|
{
|
||||||
class Sorozat
|
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)
|
while (n != 1 && !memo.ContainsKey(n))
|
||||||
{
|
{
|
||||||
int ujertek;
|
if (n % 2 == 0)
|
||||||
|
|
||||||
if (kettoHatvanyok.Contains(ertek))
|
|
||||||
{
|
{
|
||||||
int index = 0;
|
n /= 2;
|
||||||
while (kettoHatvanyok[index] != ertek)
|
|
||||||
{
|
|
||||||
index++;
|
|
||||||
}
|
|
||||||
|
|
||||||
KettoHatvanyokTagokHozzaAdasa(index);
|
|
||||||
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (ertek == 1) {
|
|
||||||
Tagok.Add(ertek);
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (ertek % 2 == 0)
|
|
||||||
{
|
|
||||||
ujertek = ertek / 2;
|
|
||||||
|
|
||||||
} else
|
} else
|
||||||
{
|
{
|
||||||
ujertek = ertek * 3 + 1;
|
n = n * 3 + 1;
|
||||||
|
}
|
||||||
|
count++;
|
||||||
}
|
}
|
||||||
|
|
||||||
Tagok.Add(ertek);
|
if (memo.ContainsKey(n))
|
||||||
return TagokKiszamitasa(ujertek);
|
{
|
||||||
|
count += memo[n];
|
||||||
}
|
}
|
||||||
|
|
||||||
public void KettoHatvanyokTagokHozzaAdasa(int index)
|
memo[original] = count;
|
||||||
|
return count;
|
||||||
|
}
|
||||||
|
|
||||||
|
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;
|
int maxLenght = 0;
|
||||||
Tagok = sorozat.Tagok;
|
int maxNumber = 0;
|
||||||
|
|
||||||
|
for (int i = 1; i < limit; i++)
|
||||||
|
{
|
||||||
|
int length = Sorozat.CollatzLength(i);
|
||||||
|
if (length > maxLenght)
|
||||||
|
{
|
||||||
|
maxLenght = length;
|
||||||
|
maxNumber = i;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public Sorozat(int kezdoErtek)
|
Console.WriteLine($"2. feladat megoldás: {maxNumber}|{maxLenght}");
|
||||||
{
|
|
||||||
this.KezdoErtek = kezdoErtek;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
|
@ -36,3 +36,21 @@
|
||||||
- a: `213`
|
- a: `213`
|
||||||
- b: `KULDJPENZT`
|
- b: `KULDJPENZT`
|
||||||
- c: `APU FUTYUL ORRUK MIATT APU SIET SIET HAZA ORRUK LETOR TOVIG BIZONY LETOR`
|
- 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