Skip to content

Commit

Permalink
add worst case scenario paragraph
Browse files Browse the repository at this point in the history
  • Loading branch information
e-silvestri committed Jan 2, 2022
1 parent 13a9607 commit fe656b7
Show file tree
Hide file tree
Showing 5 changed files with 51 additions and 3 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -243,4 +243,5 @@ _Pvt_Extensions

#Solver output file
output.txt
multipleSolutions.txt
multipleSolutions.txt
costs.txt
9 changes: 8 additions & 1 deletion PtVzzlexMasCake.Tests/PuzzleSolverTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,14 @@ namespace PtVzzlexMasCake.Tests
[TestClass]
public class PuzzleSolverTests
{
const int baseTwoExponent = 16;
const int baseTwoExponent = 20;

[TestMethod]
public void PuzzleSolverTest()
{
using var sw = new StreamWriter("../../../multipleSolutions.txt");
using var sw2 = new StreamWriter("../../../costs.txt");

var result = DijkstraSolver.SolveFull(baseTwoExponent);

foreach (var item in result)
Expand Down Expand Up @@ -46,6 +48,11 @@ public void PuzzleSolverTest()
sw.WriteLine();
}
}

if (true)
{
sw2.WriteLine($"{item.Value} {item.Cost}");
}
}
}
}
Expand Down
1 change: 1 addition & 0 deletions PtVzzlexMasCake.sln
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{6E2BA7B5-4B99-466E-983C-CE6EADEA56EB}"
ProjectSection(SolutionItems) = preProject
.gitignore = .gitignore
costs.png = costs.png
dotnet-install.ps1 = dotnet-install.ps1
dotnet-install.sh = dotnet-install.sh
README.md = README.md
Expand Down
41 changes: 40 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -50,4 +50,43 @@ dotnet test
No demonstration that the result is correct is provided,
but the algorithm was tested for numbers up to 2 ^ 20 against a completely different mothodology,
and the two methodologies provide solutions with the same cost
(even if not always the same solutions as multiple optimal exist for a given input).
(even if not always the same solutions as multiple optimal exist for a given input).

## Worst case scenario
![alt text](costs.png)

The worst case is for numbers needing one "AddOne" or "SubtractOne" operation every two "Halve" operations, meaning 1.5 Log2(N) operations (the best case scenarion is obviously log2(N) operations).

for example the number 699051 requires the folloqing sequence to reach one:

```
AddOne
Halve
Halve
AddOne
Halve
Halve
AddOne
Halve
Halve
AddOne
Halve
Halve
AddOne
Halve
Halve
AddOne
Halve
Halve
AddOne
Halve
Halve
AddOne
Halve
Halve
AddOne
Halve
Halve
SubtractOne
Halve
```
Binary file added costs.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit fe656b7

Please sign in to comment.