Question15 solved (time exceeded 25 minutes)
This commit is contained in:
commit
9796ca03af
|
@ -0,0 +1,6 @@
|
|||
// See https://aka.ms/new-console-template for more information
|
||||
using projectEuler;
|
||||
|
||||
Console.WriteLine("Hello, World!");
|
||||
var question = question15.Solve(21,21);
|
||||
Console.WriteLine(question);
|
|
@ -0,0 +1,10 @@
|
|||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<OutputType>Exe</OutputType>
|
||||
<TargetFramework>net8.0</TargetFramework>
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
<Nullable>enable</Nullable>
|
||||
</PropertyGroup>
|
||||
|
||||
</Project>
|
|
@ -0,0 +1,25 @@
|
|||
|
||||
Microsoft Visual Studio Solution File, Format Version 12.00
|
||||
# Visual Studio Version 17
|
||||
VisualStudioVersion = 17.5.002.0
|
||||
MinimumVisualStudioVersion = 10.0.40219.1
|
||||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "ProjectEuler", "ProjectEuler.csproj", "{FE2E32A1-5E96-45B8-AE16-71BEC7A0DDA7}"
|
||||
EndProject
|
||||
Global
|
||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||
Debug|Any CPU = Debug|Any CPU
|
||||
Release|Any CPU = Release|Any CPU
|
||||
EndGlobalSection
|
||||
GlobalSection(ProjectConfigurationPlatforms) = postSolution
|
||||
{FE2E32A1-5E96-45B8-AE16-71BEC7A0DDA7}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{FE2E32A1-5E96-45B8-AE16-71BEC7A0DDA7}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{FE2E32A1-5E96-45B8-AE16-71BEC7A0DDA7}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{FE2E32A1-5E96-45B8-AE16-71BEC7A0DDA7}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
EndGlobalSection
|
||||
GlobalSection(SolutionProperties) = preSolution
|
||||
HideSolutionNode = FALSE
|
||||
EndGlobalSection
|
||||
GlobalSection(ExtensibilityGlobals) = postSolution
|
||||
SolutionGuid = {FF2A347A-C997-4486-9BA2-2D8CC4DD0122}
|
||||
EndGlobalSection
|
||||
EndGlobal
|
|
@ -0,0 +1,23 @@
|
|||
{
|
||||
"runtimeTarget": {
|
||||
"name": ".NETCoreApp,Version=v8.0",
|
||||
"signature": ""
|
||||
},
|
||||
"compilationOptions": {},
|
||||
"targets": {
|
||||
".NETCoreApp,Version=v8.0": {
|
||||
"ProjectEuler/1.0.0": {
|
||||
"runtime": {
|
||||
"ProjectEuler.dll": {}
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"libraries": {
|
||||
"ProjectEuler/1.0.0": {
|
||||
"type": "project",
|
||||
"serviceable": false,
|
||||
"sha512": ""
|
||||
}
|
||||
}
|
||||
}
|
Binary file not shown.
Binary file not shown.
Binary file not shown.
|
@ -0,0 +1,12 @@
|
|||
{
|
||||
"runtimeOptions": {
|
||||
"tfm": "net8.0",
|
||||
"framework": {
|
||||
"name": "Microsoft.NETCore.App",
|
||||
"version": "8.0.0"
|
||||
},
|
||||
"configProperties": {
|
||||
"System.Runtime.Serialization.EnableUnsafeBinaryFormatterSerialization": false
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,2 @@
|
|||
A lot of times I run into stack overflow issues.
|
||||
Use BigInteger and you will not run into stack overflow issues.
|
|
@ -0,0 +1,4 @@
|
|||
// <autogenerated />
|
||||
using System;
|
||||
using System.Reflection;
|
||||
[assembly: global::System.Runtime.Versioning.TargetFrameworkAttribute(".NETCoreApp,Version=v8.0", FrameworkDisplayName = ".NET 8.0")]
|
|
@ -0,0 +1,22 @@
|
|||
//------------------------------------------------------------------------------
|
||||
// <auto-generated>
|
||||
// This code was generated by a tool.
|
||||
//
|
||||
// Changes to this file may cause incorrect behavior and will be lost if
|
||||
// the code is regenerated.
|
||||
// </auto-generated>
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
using System;
|
||||
using System.Reflection;
|
||||
|
||||
[assembly: System.Reflection.AssemblyCompanyAttribute("ProjectEuler")]
|
||||
[assembly: System.Reflection.AssemblyConfigurationAttribute("Debug")]
|
||||
[assembly: System.Reflection.AssemblyFileVersionAttribute("1.0.0.0")]
|
||||
[assembly: System.Reflection.AssemblyInformationalVersionAttribute("1.0.0")]
|
||||
[assembly: System.Reflection.AssemblyProductAttribute("ProjectEuler")]
|
||||
[assembly: System.Reflection.AssemblyTitleAttribute("ProjectEuler")]
|
||||
[assembly: System.Reflection.AssemblyVersionAttribute("1.0.0.0")]
|
||||
|
||||
// Generated by the MSBuild WriteCodeFragment class.
|
||||
|
|
@ -0,0 +1 @@
|
|||
ffcde6f75b6a2a29b7675ed917cd743ebe587f04c450947801882186d33ad68a
|
|
@ -0,0 +1,13 @@
|
|||
is_global = true
|
||||
build_property.TargetFramework = net8.0
|
||||
build_property.TargetPlatformMinVersion =
|
||||
build_property.UsingMicrosoftNETSdkWeb =
|
||||
build_property.ProjectTypeGuids =
|
||||
build_property.InvariantGlobalization =
|
||||
build_property.PlatformNeutralAssembly =
|
||||
build_property.EnforceExtendedAnalyzerRules =
|
||||
build_property._SupportedPlatformList = Linux,macOS,Windows
|
||||
build_property.RootNamespace = ProjectEuler
|
||||
build_property.ProjectDir = C:\Users\Travis\Desktop\projects\ProjectEuler\
|
||||
build_property.EnableComHosting =
|
||||
build_property.EnableGeneratedComInterfaceComImportInterop =
|
|
@ -0,0 +1,8 @@
|
|||
// <auto-generated/>
|
||||
global using global::System;
|
||||
global using global::System.Collections.Generic;
|
||||
global using global::System.IO;
|
||||
global using global::System.Linq;
|
||||
global using global::System.Net.Http;
|
||||
global using global::System.Threading;
|
||||
global using global::System.Threading.Tasks;
|
Binary file not shown.
|
@ -0,0 +1 @@
|
|||
cf16980a0ba4091f5ea3e0558bd5272f285814d26eeff00d425e377e20bb1870
|
|
@ -0,0 +1,14 @@
|
|||
C:\Users\Travis\Desktop\projects\ProjectEuler\bin\Debug\net8.0\ProjectEuler.exe
|
||||
C:\Users\Travis\Desktop\projects\ProjectEuler\bin\Debug\net8.0\ProjectEuler.deps.json
|
||||
C:\Users\Travis\Desktop\projects\ProjectEuler\bin\Debug\net8.0\ProjectEuler.runtimeconfig.json
|
||||
C:\Users\Travis\Desktop\projects\ProjectEuler\bin\Debug\net8.0\ProjectEuler.dll
|
||||
C:\Users\Travis\Desktop\projects\ProjectEuler\bin\Debug\net8.0\ProjectEuler.pdb
|
||||
C:\Users\Travis\Desktop\projects\ProjectEuler\obj\Debug\net8.0\ProjectEuler.GeneratedMSBuildEditorConfig.editorconfig
|
||||
C:\Users\Travis\Desktop\projects\ProjectEuler\obj\Debug\net8.0\ProjectEuler.AssemblyInfoInputs.cache
|
||||
C:\Users\Travis\Desktop\projects\ProjectEuler\obj\Debug\net8.0\ProjectEuler.AssemblyInfo.cs
|
||||
C:\Users\Travis\Desktop\projects\ProjectEuler\obj\Debug\net8.0\ProjectEuler.csproj.CoreCompileInputs.cache
|
||||
C:\Users\Travis\Desktop\projects\ProjectEuler\obj\Debug\net8.0\ProjectEuler.dll
|
||||
C:\Users\Travis\Desktop\projects\ProjectEuler\obj\Debug\net8.0\refint\ProjectEuler.dll
|
||||
C:\Users\Travis\Desktop\projects\ProjectEuler\obj\Debug\net8.0\ProjectEuler.pdb
|
||||
C:\Users\Travis\Desktop\projects\ProjectEuler\obj\Debug\net8.0\ProjectEuler.genruntimeconfig.cache
|
||||
C:\Users\Travis\Desktop\projects\ProjectEuler\obj\Debug\net8.0\ref\ProjectEuler.dll
|
Binary file not shown.
|
@ -0,0 +1 @@
|
|||
10b4be1bdd189e5f97095d6e9334221900ee43b067b33755c1ab85c5d26a5277
|
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
|
@ -0,0 +1,72 @@
|
|||
{
|
||||
"format": 1,
|
||||
"restore": {
|
||||
"C:\\Users\\Travis\\Desktop\\projects\\ProjectEuler\\ProjectEuler.csproj": {}
|
||||
},
|
||||
"projects": {
|
||||
"C:\\Users\\Travis\\Desktop\\projects\\ProjectEuler\\ProjectEuler.csproj": {
|
||||
"version": "1.0.0",
|
||||
"restore": {
|
||||
"projectUniqueName": "C:\\Users\\Travis\\Desktop\\projects\\ProjectEuler\\ProjectEuler.csproj",
|
||||
"projectName": "ProjectEuler",
|
||||
"projectPath": "C:\\Users\\Travis\\Desktop\\projects\\ProjectEuler\\ProjectEuler.csproj",
|
||||
"packagesPath": "C:\\Users\\Travis\\.nuget\\packages\\",
|
||||
"outputPath": "C:\\Users\\Travis\\Desktop\\projects\\ProjectEuler\\obj\\",
|
||||
"projectStyle": "PackageReference",
|
||||
"fallbackFolders": [
|
||||
"C:\\Program Files (x86)\\Microsoft Visual Studio\\Shared\\NuGetPackages"
|
||||
],
|
||||
"configFilePaths": [
|
||||
"C:\\Users\\Travis\\AppData\\Roaming\\NuGet\\NuGet.Config",
|
||||
"C:\\Program Files (x86)\\NuGet\\Config\\Microsoft.VisualStudio.FallbackLocation.config",
|
||||
"C:\\Program Files (x86)\\NuGet\\Config\\Microsoft.VisualStudio.Offline.config"
|
||||
],
|
||||
"originalTargetFrameworks": [
|
||||
"net8.0"
|
||||
],
|
||||
"sources": {
|
||||
"C:\\Program Files (x86)\\Microsoft SDKs\\NuGetPackages\\": {},
|
||||
"https://api.nuget.org/v3/index.json": {}
|
||||
},
|
||||
"frameworks": {
|
||||
"net8.0": {
|
||||
"targetAlias": "net8.0",
|
||||
"projectReferences": {}
|
||||
}
|
||||
},
|
||||
"warningProperties": {
|
||||
"warnAsError": [
|
||||
"NU1605"
|
||||
]
|
||||
},
|
||||
"restoreAuditProperties": {
|
||||
"enableAudit": "true",
|
||||
"auditLevel": "low",
|
||||
"auditMode": "direct"
|
||||
}
|
||||
},
|
||||
"frameworks": {
|
||||
"net8.0": {
|
||||
"targetAlias": "net8.0",
|
||||
"imports": [
|
||||
"net461",
|
||||
"net462",
|
||||
"net47",
|
||||
"net471",
|
||||
"net472",
|
||||
"net48",
|
||||
"net481"
|
||||
],
|
||||
"assetTargetFallback": true,
|
||||
"warn": true,
|
||||
"frameworkReferences": {
|
||||
"Microsoft.NETCore.App": {
|
||||
"privateAssets": "all"
|
||||
}
|
||||
},
|
||||
"runtimeIdentifierGraphPath": "C:\\Program Files\\dotnet\\sdk\\8.0.202/PortableRuntimeIdentifierGraph.json"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,16 @@
|
|||
<?xml version="1.0" encoding="utf-8" standalone="no"?>
|
||||
<Project ToolsVersion="14.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||
<PropertyGroup Condition=" '$(ExcludeRestorePackageImports)' != 'true' ">
|
||||
<RestoreSuccess Condition=" '$(RestoreSuccess)' == '' ">True</RestoreSuccess>
|
||||
<RestoreTool Condition=" '$(RestoreTool)' == '' ">NuGet</RestoreTool>
|
||||
<ProjectAssetsFile Condition=" '$(ProjectAssetsFile)' == '' ">$(MSBuildThisFileDirectory)project.assets.json</ProjectAssetsFile>
|
||||
<NuGetPackageRoot Condition=" '$(NuGetPackageRoot)' == '' ">$(UserProfile)\.nuget\packages\</NuGetPackageRoot>
|
||||
<NuGetPackageFolders Condition=" '$(NuGetPackageFolders)' == '' ">C:\Users\Travis\.nuget\packages\;C:\Program Files (x86)\Microsoft Visual Studio\Shared\NuGetPackages</NuGetPackageFolders>
|
||||
<NuGetProjectStyle Condition=" '$(NuGetProjectStyle)' == '' ">PackageReference</NuGetProjectStyle>
|
||||
<NuGetToolVersion Condition=" '$(NuGetToolVersion)' == '' ">6.9.1</NuGetToolVersion>
|
||||
</PropertyGroup>
|
||||
<ItemGroup Condition=" '$(ExcludeRestorePackageImports)' != 'true' ">
|
||||
<SourceRoot Include="C:\Users\Travis\.nuget\packages\" />
|
||||
<SourceRoot Include="C:\Program Files (x86)\Microsoft Visual Studio\Shared\NuGetPackages\" />
|
||||
</ItemGroup>
|
||||
</Project>
|
|
@ -0,0 +1,2 @@
|
|||
<?xml version="1.0" encoding="utf-8" standalone="no"?>
|
||||
<Project ToolsVersion="14.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003" />
|
|
@ -0,0 +1,78 @@
|
|||
{
|
||||
"version": 3,
|
||||
"targets": {
|
||||
"net8.0": {}
|
||||
},
|
||||
"libraries": {},
|
||||
"projectFileDependencyGroups": {
|
||||
"net8.0": []
|
||||
},
|
||||
"packageFolders": {
|
||||
"C:\\Users\\Travis\\.nuget\\packages\\": {},
|
||||
"C:\\Program Files (x86)\\Microsoft Visual Studio\\Shared\\NuGetPackages": {}
|
||||
},
|
||||
"project": {
|
||||
"version": "1.0.0",
|
||||
"restore": {
|
||||
"projectUniqueName": "C:\\Users\\Travis\\Desktop\\projects\\ProjectEuler\\ProjectEuler.csproj",
|
||||
"projectName": "ProjectEuler",
|
||||
"projectPath": "C:\\Users\\Travis\\Desktop\\projects\\ProjectEuler\\ProjectEuler.csproj",
|
||||
"packagesPath": "C:\\Users\\Travis\\.nuget\\packages\\",
|
||||
"outputPath": "C:\\Users\\Travis\\Desktop\\projects\\ProjectEuler\\obj\\",
|
||||
"projectStyle": "PackageReference",
|
||||
"fallbackFolders": [
|
||||
"C:\\Program Files (x86)\\Microsoft Visual Studio\\Shared\\NuGetPackages"
|
||||
],
|
||||
"configFilePaths": [
|
||||
"C:\\Users\\Travis\\AppData\\Roaming\\NuGet\\NuGet.Config",
|
||||
"C:\\Program Files (x86)\\NuGet\\Config\\Microsoft.VisualStudio.FallbackLocation.config",
|
||||
"C:\\Program Files (x86)\\NuGet\\Config\\Microsoft.VisualStudio.Offline.config"
|
||||
],
|
||||
"originalTargetFrameworks": [
|
||||
"net8.0"
|
||||
],
|
||||
"sources": {
|
||||
"C:\\Program Files (x86)\\Microsoft SDKs\\NuGetPackages\\": {},
|
||||
"https://api.nuget.org/v3/index.json": {}
|
||||
},
|
||||
"frameworks": {
|
||||
"net8.0": {
|
||||
"targetAlias": "net8.0",
|
||||
"projectReferences": {}
|
||||
}
|
||||
},
|
||||
"warningProperties": {
|
||||
"warnAsError": [
|
||||
"NU1605"
|
||||
]
|
||||
},
|
||||
"restoreAuditProperties": {
|
||||
"enableAudit": "true",
|
||||
"auditLevel": "low",
|
||||
"auditMode": "direct"
|
||||
}
|
||||
},
|
||||
"frameworks": {
|
||||
"net8.0": {
|
||||
"targetAlias": "net8.0",
|
||||
"imports": [
|
||||
"net461",
|
||||
"net462",
|
||||
"net47",
|
||||
"net471",
|
||||
"net472",
|
||||
"net48",
|
||||
"net481"
|
||||
],
|
||||
"assetTargetFallback": true,
|
||||
"warn": true,
|
||||
"frameworkReferences": {
|
||||
"Microsoft.NETCore.App": {
|
||||
"privateAssets": "all"
|
||||
}
|
||||
},
|
||||
"runtimeIdentifierGraphPath": "C:\\Program Files\\dotnet\\sdk\\8.0.202/PortableRuntimeIdentifierGraph.json"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,8 @@
|
|||
{
|
||||
"version": 2,
|
||||
"dgSpecHash": "T2aVq83MosNF2xLxjuIWNKqV1uHTuuxtWh0Vh8q9MVfPQFacYZtfkYDCLotTw89XtMMGho9no9eVN189TrvxfQ==",
|
||||
"success": true,
|
||||
"projectFilePath": "C:\\Users\\Travis\\Desktop\\projects\\ProjectEuler\\ProjectEuler.csproj",
|
||||
"expectedPackageFiles": [],
|
||||
"logs": []
|
||||
}
|
|
@ -0,0 +1,59 @@
|
|||
using System.CodeDom.Compiler;
|
||||
using System.Numerics;
|
||||
using System.Security.Cryptography.X509Certificates;
|
||||
|
||||
namespace projectEuler {
|
||||
//
|
||||
class question15 {
|
||||
question15(){
|
||||
|
||||
}
|
||||
|
||||
public static BigInteger Solve(int x, int y){
|
||||
List<List<BigInteger>> grid = new List<List<BigInteger>>();
|
||||
//initialize grid
|
||||
for(int width = 0; width < x; width++){
|
||||
grid.Add(new List<BigInteger>());
|
||||
string row = "";
|
||||
for(int height = 0; height < y; height++){
|
||||
grid[width].Add(0);
|
||||
row += " 0";
|
||||
}
|
||||
Console.WriteLine(row);
|
||||
}
|
||||
|
||||
|
||||
grid[0][0] = 1;
|
||||
for(int width = 0; width < x; width++) {
|
||||
string row = "";
|
||||
for(int height = 0; height < x ; height++){
|
||||
if(grid[width][height] == 1){
|
||||
continue;
|
||||
}
|
||||
BigInteger top = 0;
|
||||
BigInteger left = 0;
|
||||
if(width - 1 >= 0)
|
||||
{
|
||||
left = grid[width-1][height];
|
||||
}
|
||||
if(height - 1 >= 0){
|
||||
top = grid[width][height-1];
|
||||
}
|
||||
if(top == 0 || left == 0) {
|
||||
row += " 1";
|
||||
grid[width][height] = 1;
|
||||
} else {
|
||||
row += " " + (top + left).ToString();
|
||||
grid[width][height] = top + left;
|
||||
}
|
||||
|
||||
}
|
||||
Console.WriteLine(row);
|
||||
}
|
||||
return grid[x-1][y-1];
|
||||
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue