add csharp examples (#10)

This commit is contained in:
Jim Vaughan
2016-11-07 15:43:30 -06:00
committed by Aditya Bhargava
parent c3396b8b0a
commit 62ed616954
96 changed files with 107024 additions and 0 deletions

View File

@@ -0,0 +1,2 @@
**/bin/*
**/obj/*

View File

@@ -0,0 +1,23 @@
{
"version": "0.2.0",
"configurations": [
{
"name": ".NET Core Launch (console)",
"type": "coreclr",
"request": "launch",
"preLaunchTask": "build",
"program": "${workspaceRoot}/bin/Debug/netcoreapp1.0/01_binary_search.dll",
"args": [],
"cwd": "${workspaceRoot}",
"externalConsole": false,
"stopAtEntry": false,
"internalConsoleOptions": "openOnSessionStart"
},
{
"name": ".NET Core Attach",
"type": "coreclr",
"request": "attach",
"processId": "${command.pickProcess}"
}
]
}

View File

@@ -0,0 +1,16 @@
{
"version": "0.1.0",
"command": "dotnet",
"isShellCommand": true,
"args": [],
"tasks": [
{
"taskName": "build",
"args": [
"${workspaceRoot}/project.json"
],
"isBuildCommand": true,
"problemMatcher": "$msCompile"
}
]
}

View File

@@ -0,0 +1,39 @@
using System;
using System.Collections.Generic;
using System.Linq;
namespace ConsoleApplication
{
public class Program
{
public static void Main(string[] args)
{
var myList = new List<int> { 1, 3, 5, 7, 9 };
Console.WriteLine(BinarySearch(myList, 3)); // => 1
Console.WriteLine(BinarySearch(myList, -1)); // => null gets printed as an empty string
}
private static int? BinarySearch(IList<int> list, int item)
{
var low = 0;
var high = list.Count() - 1;
while (low <= high)
{
var mid = (low + high) / 2;
var guess = list[mid];
if (guess == item) return mid;
if (guess > item)
{
high = mid - 1;
}
else
{
low = mid + 1;
}
}
return null;
}
}
}

View File

@@ -0,0 +1,19 @@
{
"version": "1.0.0-*",
"buildOptions": {
"debugType": "portable",
"emitEntryPoint": true
},
"dependencies": {},
"frameworks": {
"netcoreapp1.0": {
"dependencies": {
"Microsoft.NETCore.App": {
"type": "platform",
"version": "1.0.1"
}
},
"imports": "dnxcore50"
}
}
}

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,2 @@
**/bin/*
**/obj/*

View File

@@ -0,0 +1,23 @@
{
"version": "0.2.0",
"configurations": [
{
"name": ".NET Core Launch (console)",
"type": "coreclr",
"request": "launch",
"preLaunchTask": "build",
"program": "${workspaceRoot}/bin/Debug/netcoreapp1.0/csharp.dll",
"args": [],
"cwd": "${workspaceRoot}",
"externalConsole": false,
"stopAtEntry": false,
"internalConsoleOptions": "openOnSessionStart"
},
{
"name": ".NET Core Attach",
"type": "coreclr",
"request": "attach",
"processId": "${command.pickProcess}"
}
]
}

View File

@@ -0,0 +1,16 @@
{
"version": "0.1.0",
"command": "dotnet",
"isShellCommand": true,
"args": [],
"tasks": [
{
"taskName": "build",
"args": [
"${workspaceRoot}/project.json"
],
"isBuildCommand": true,
"problemMatcher": "$msCompile"
}
]
}

View File

@@ -0,0 +1,41 @@
using System;
using System.Collections.Generic;
namespace ConsoleApplication
{
public class Program
{
public static void Main(string[] args)
{
var arr = new List<int> { 5, 3, 6, 2, 10 };
Console.WriteLine(string.Join(", ", SelectionSort(arr)));
}
private static int[] SelectionSort(List<int> arr)
{
var newArr = new int[arr.Count];
for (int i = 0; i < newArr.Length; i++)
{
var smallest = FindSmallest(arr);
newArr[i] = arr[smallest];
arr.RemoveAt(smallest);
}
return newArr;
}
private static int FindSmallest(List<int> arr)
{
var smallest = arr[0];
var smallestIndex = 0;
for (int i = 0; i < arr.Count; i++)
{
if (arr[i] < smallest)
{
smallest = arr[i];
smallestIndex = i;
}
}
return smallestIndex;
}
}
}

View File

@@ -0,0 +1,19 @@
{
"version": "1.0.0-*",
"buildOptions": {
"debugType": "portable",
"emitEntryPoint": true
},
"dependencies": {},
"frameworks": {
"netcoreapp1.0": {
"dependencies": {
"Microsoft.NETCore.App": {
"type": "platform",
"version": "1.0.1"
}
},
"imports": "dnxcore50"
}
}
}

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,2 @@
**/bin/*
**/obj/*

View File

@@ -0,0 +1,23 @@
{
"version": "0.2.0",
"configurations": [
{
"name": ".NET Core Launch (console)",
"type": "coreclr",
"request": "launch",
"preLaunchTask": "build",
"program": "${workspaceRoot}/bin/Debug/netcoreapp1.0/01_countdown.dll",
"args": [],
"cwd": "${workspaceRoot}",
"externalConsole": false,
"stopAtEntry": false,
"internalConsoleOptions": "openOnSessionStart"
},
{
"name": ".NET Core Attach",
"type": "coreclr",
"request": "attach",
"processId": "${command.pickProcess}"
}
]
}

View File

@@ -0,0 +1,16 @@
{
"version": "0.1.0",
"command": "dotnet",
"isShellCommand": true,
"args": [],
"tasks": [
{
"taskName": "build",
"args": [
"${workspaceRoot}/project.json"
],
"isBuildCommand": true,
"problemMatcher": "$msCompile"
}
]
}

View File

@@ -0,0 +1,23 @@
using System;
namespace ConsoleApplication
{
public class Program
{
public static void Main(string[] args)
{
Countdown(5);
}
private static void Countdown(int i)
{
Console.WriteLine(i);
// base case
if (i <= 0) return;
// recursive case
Countdown(i - 1);
}
}
}

View File

@@ -0,0 +1,19 @@
{
"version": "1.0.0-*",
"buildOptions": {
"debugType": "portable",
"emitEntryPoint": true
},
"dependencies": {},
"frameworks": {
"netcoreapp1.0": {
"dependencies": {
"Microsoft.NETCore.App": {
"type": "platform",
"version": "1.0.1"
}
},
"imports": "dnxcore50"
}
}
}

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,2 @@
**/bin/*
**/obj/*

View File

@@ -0,0 +1,23 @@
{
"version": "0.2.0",
"configurations": [
{
"name": ".NET Core Launch (console)",
"type": "coreclr",
"request": "launch",
"preLaunchTask": "build",
"program": "${workspaceRoot}/bin/Debug/netcoreapp1.0/02_greet.dll",
"args": [],
"cwd": "${workspaceRoot}",
"externalConsole": false,
"stopAtEntry": false,
"internalConsoleOptions": "openOnSessionStart"
},
{
"name": ".NET Core Attach",
"type": "coreclr",
"request": "attach",
"processId": "${command.pickProcess}"
}
]
}

View File

@@ -0,0 +1,16 @@
{
"version": "0.1.0",
"command": "dotnet",
"isShellCommand": true,
"args": [],
"tasks": [
{
"taskName": "build",
"args": [
"${workspaceRoot}/project.json"
],
"isBuildCommand": true,
"problemMatcher": "$msCompile"
}
]
}

View File

@@ -0,0 +1,30 @@
using System;
namespace ConsoleApplication
{
public class Program
{
public static void Main(string[] args)
{
Greet("adit");
}
private static void Greet(string name)
{
Console.WriteLine($"hello, {name}!");
Greet2(name);
Console.WriteLine("getting ready to say bye...");
Bye();
}
private static void Greet2(string name)
{
Console.WriteLine($"how are you, {name}?");
}
private static void Bye()
{
Console.WriteLine("ok bye!");
}
}
}

View File

@@ -0,0 +1,19 @@
{
"version": "1.0.0-*",
"buildOptions": {
"debugType": "portable",
"emitEntryPoint": true
},
"dependencies": {},
"frameworks": {
"netcoreapp1.0": {
"dependencies": {
"Microsoft.NETCore.App": {
"type": "platform",
"version": "1.0.1"
}
},
"imports": "dnxcore50"
}
}
}

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,2 @@
**/bin/*
**/obj/*

View File

@@ -0,0 +1,23 @@
{
"version": "0.2.0",
"configurations": [
{
"name": ".NET Core Launch (console)",
"type": "coreclr",
"request": "launch",
"preLaunchTask": "build",
"program": "${workspaceRoot}/bin/Debug/netcoreapp1.0/03_factorial.dll",
"args": [],
"cwd": "${workspaceRoot}",
"externalConsole": false,
"stopAtEntry": false,
"internalConsoleOptions": "openOnSessionStart"
},
{
"name": ".NET Core Attach",
"type": "coreclr",
"request": "attach",
"processId": "${command.pickProcess}"
}
]
}

View File

@@ -0,0 +1,16 @@
{
"version": "0.1.0",
"command": "dotnet",
"isShellCommand": true,
"args": [],
"tasks": [
{
"taskName": "build",
"args": [
"${workspaceRoot}/project.json"
],
"isBuildCommand": true,
"problemMatcher": "$msCompile"
}
]
}

View File

@@ -0,0 +1,19 @@
using System;
namespace ConsoleApplication
{
public class Program
{
public static void Main(string[] args)
{
Console.WriteLine(Fact(5));
}
private static int Fact(int x)
{
if (x <= 1) return 1;
return x * Fact(x - 1);
}
}
}

View File

@@ -0,0 +1,19 @@
{
"version": "1.0.0-*",
"buildOptions": {
"debugType": "portable",
"emitEntryPoint": true
},
"dependencies": {},
"frameworks": {
"netcoreapp1.0": {
"dependencies": {
"Microsoft.NETCore.App": {
"type": "platform",
"version": "1.0.1"
}
},
"imports": "dnxcore50"
}
}
}

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,2 @@
**/bin/*
**/obj/*

View File

@@ -0,0 +1,23 @@
{
"version": "0.2.0",
"configurations": [
{
"name": ".NET Core Launch (console)",
"type": "coreclr",
"request": "launch",
"preLaunchTask": "build",
"program": "${workspaceRoot}/bin/Debug/netcoreapp1.0/01_loop_sum.dll",
"args": [],
"cwd": "${workspaceRoot}",
"externalConsole": false,
"stopAtEntry": false,
"internalConsoleOptions": "openOnSessionStart"
},
{
"name": ".NET Core Attach",
"type": "coreclr",
"request": "attach",
"processId": "${command.pickProcess}"
}
]
}

View File

@@ -0,0 +1,16 @@
{
"version": "0.1.0",
"command": "dotnet",
"isShellCommand": true,
"args": [],
"tasks": [
{
"taskName": "build",
"args": [
"${workspaceRoot}/project.json"
],
"isBuildCommand": true,
"problemMatcher": "$msCompile"
}
]
}

View File

@@ -0,0 +1,23 @@
using System;
using System.Collections.Generic;
namespace ConsoleApplication
{
public class Program
{
public static void Main(string[] args)
{
Console.WriteLine(Sum(new[] { 1, 2, 3, 4 }));
}
private static int Sum(IEnumerable<int> arr)
{
var total = 0;
foreach (var x in arr)
{
total += x;
}
return total;
}
}
}

View File

@@ -0,0 +1,19 @@
{
"version": "1.0.0-*",
"buildOptions": {
"debugType": "portable",
"emitEntryPoint": true
},
"dependencies": {},
"frameworks": {
"netcoreapp1.0": {
"dependencies": {
"Microsoft.NETCore.App": {
"type": "platform",
"version": "1.0.1"
}
},
"imports": "dnxcore50"
}
}
}

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,2 @@
**/bin/*
**/obj/*

View File

@@ -0,0 +1,23 @@
{
"version": "0.2.0",
"configurations": [
{
"name": ".NET Core Launch (console)",
"type": "coreclr",
"request": "launch",
"preLaunchTask": "build",
"program": "${workspaceRoot}/bin/Debug/netcoreapp1.0/02_recursive_sum.dll",
"args": [],
"cwd": "${workspaceRoot}",
"externalConsole": false,
"stopAtEntry": false,
"internalConsoleOptions": "openOnSessionStart"
},
{
"name": ".NET Core Attach",
"type": "coreclr",
"request": "attach",
"processId": "${command.pickProcess}"
}
]
}

View File

@@ -0,0 +1,16 @@
{
"version": "0.1.0",
"command": "dotnet",
"isShellCommand": true,
"args": [],
"tasks": [
{
"taskName": "build",
"args": [
"${workspaceRoot}/project.json"
],
"isBuildCommand": true,
"problemMatcher": "$msCompile"
}
]
}

View File

@@ -0,0 +1,21 @@
using System;
using System.Collections.Generic;
using System.Linq;
namespace ConsoleApplication
{
public class Program
{
public static void Main(string[] args)
{
Console.WriteLine(Sum(new[] { 1, 2, 3, 4 }));
}
private static int Sum(IEnumerable<int> list)
{
if (!list.Any()) return 0;
return list.Take(1).First() + Sum(list.Skip(1));
}
}
}

View File

@@ -0,0 +1,19 @@
{
"version": "1.0.0-*",
"buildOptions": {
"debugType": "portable",
"emitEntryPoint": true
},
"dependencies": {},
"frameworks": {
"netcoreapp1.0": {
"dependencies": {
"Microsoft.NETCore.App": {
"type": "platform",
"version": "1.0.1"
}
},
"imports": "dnxcore50"
}
}
}

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,2 @@
**/bin/*
**/obj/*

View File

@@ -0,0 +1,23 @@
{
"version": "0.2.0",
"configurations": [
{
"name": ".NET Core Launch (console)",
"type": "coreclr",
"request": "launch",
"preLaunchTask": "build",
"program": "${workspaceRoot}/bin/Debug/netcoreapp1.0/03_recursive_count.dll",
"args": [],
"cwd": "${workspaceRoot}",
"externalConsole": false,
"stopAtEntry": false,
"internalConsoleOptions": "openOnSessionStart"
},
{
"name": ".NET Core Attach",
"type": "coreclr",
"request": "attach",
"processId": "${command.pickProcess}"
}
]
}

View File

@@ -0,0 +1,16 @@
{
"version": "0.1.0",
"command": "dotnet",
"isShellCommand": true,
"args": [],
"tasks": [
{
"taskName": "build",
"args": [
"${workspaceRoot}/project.json"
],
"isBuildCommand": true,
"problemMatcher": "$msCompile"
}
]
}

View File

@@ -0,0 +1,21 @@
using System;
using System.Collections.Generic;
using System.Linq;
namespace ConsoleApplication
{
public class Program
{
public static void Main(string[] args)
{
Console.WriteLine(Count(new[] { 1, 2, 3, 4 }));
}
private static int Count(IEnumerable<int> list)
{
if(!list.Any()) return 0;
return 1 + Count(list.Skip(1));
}
}
}

View File

@@ -0,0 +1,19 @@
{
"version": "1.0.0-*",
"buildOptions": {
"debugType": "portable",
"emitEntryPoint": true
},
"dependencies": {},
"frameworks": {
"netcoreapp1.0": {
"dependencies": {
"Microsoft.NETCore.App": {
"type": "platform",
"version": "1.0.1"
}
},
"imports": "dnxcore50"
}
}
}

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,2 @@
**/bin/*
**/obj/*

View File

@@ -0,0 +1,23 @@
{
"version": "0.2.0",
"configurations": [
{
"name": ".NET Core Launch (console)",
"type": "coreclr",
"request": "launch",
"preLaunchTask": "build",
"program": "${workspaceRoot}/bin/Debug/netcoreapp1.0/04_recursive_max.dll",
"args": [],
"cwd": "${workspaceRoot}",
"externalConsole": false,
"stopAtEntry": false,
"internalConsoleOptions": "openOnSessionStart"
},
{
"name": ".NET Core Attach",
"type": "coreclr",
"request": "attach",
"processId": "${command.pickProcess}"
}
]
}

View File

@@ -0,0 +1,16 @@
{
"version": "0.1.0",
"command": "dotnet",
"isShellCommand": true,
"args": [],
"tasks": [
{
"taskName": "build",
"args": [
"${workspaceRoot}/project.json"
],
"isBuildCommand": true,
"problemMatcher": "$msCompile"
}
]
}

View File

@@ -0,0 +1,23 @@
using System;
using System.Collections.Generic;
using System.Linq;
namespace ConsoleApplication
{
public class Program
{
public static void Main(string[] args)
{
Console.WriteLine(Max(new[] { 1, 3, 2, 5, 9, 8 }));
}
private static int Max(IEnumerable<int> list)
{
if (!list.Any()) throw new ArgumentException(nameof(list));
if (list.Count() == 1) return list.First();
if (list.Count() == 2) return list.First() > list.Skip(1).Take(1).First() ? list.First() : list.Skip(1).Take(1).First();
var sub_max = Max(list.Skip(1));
return list.First() > sub_max ? list.First() : sub_max;
}
}
}

View File

@@ -0,0 +1,19 @@
{
"version": "1.0.0-*",
"buildOptions": {
"debugType": "portable",
"emitEntryPoint": true
},
"dependencies": {},
"frameworks": {
"netcoreapp1.0": {
"dependencies": {
"Microsoft.NETCore.App": {
"type": "platform",
"version": "1.0.1"
}
},
"imports": "dnxcore50"
}
}
}

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,2 @@
**/bin/*
**/obj/*

View File

@@ -0,0 +1,23 @@
{
"version": "0.2.0",
"configurations": [
{
"name": ".NET Core Launch (console)",
"type": "coreclr",
"request": "launch",
"preLaunchTask": "build",
"program": "${workspaceRoot}/bin/Debug/netcoreapp1.0/05_quicksort.dll",
"args": [],
"cwd": "${workspaceRoot}",
"externalConsole": false,
"stopAtEntry": false,
"internalConsoleOptions": "openOnSessionStart"
},
{
"name": ".NET Core Attach",
"type": "coreclr",
"request": "attach",
"processId": "${command.pickProcess}"
}
]
}

View File

@@ -0,0 +1,16 @@
{
"version": "0.1.0",
"command": "dotnet",
"isShellCommand": true,
"args": [],
"tasks": [
{
"taskName": "build",
"args": [
"${workspaceRoot}/project.json"
],
"isBuildCommand": true,
"problemMatcher": "$msCompile"
}
]
}

View File

@@ -0,0 +1,24 @@
using System;
using System.Collections.Generic;
using System.Linq;
namespace ConsoleApplication
{
public class Program
{
public static void Main(string[] args)
{
var arr = new[] { 10, 5, 2, 3 };
Console.WriteLine(string.Join(", ", QuickSort(arr)));
}
private static IEnumerable<int> QuickSort(IEnumerable<int> list)
{
if (list.Count() <= 1) return list;
var pivot = list.First();
var less = list.Skip(1).Where(i => i <= pivot);
var greater = list.Skip(1).Where(i => i > pivot);
return QuickSort(less).Union(new List<int> { pivot }).Union(QuickSort(greater));
}
}
}

View File

@@ -0,0 +1,19 @@
{
"version": "1.0.0-*",
"buildOptions": {
"debugType": "portable",
"emitEntryPoint": true
},
"dependencies": {},
"frameworks": {
"netcoreapp1.0": {
"dependencies": {
"Microsoft.NETCore.App": {
"type": "platform",
"version": "1.0.1"
}
},
"imports": "dnxcore50"
}
}
}

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,2 @@
**/bin/*
**/obj/*

View File

@@ -0,0 +1,23 @@
{
"version": "0.2.0",
"configurations": [
{
"name": ".NET Core Launch (console)",
"type": "coreclr",
"request": "launch",
"preLaunchTask": "build",
"program": "${workspaceRoot}/bin/Debug/netcoreapp1.0/01_price_of_groceries.dll",
"args": [],
"cwd": "${workspaceRoot}",
"externalConsole": false,
"stopAtEntry": false,
"internalConsoleOptions": "openOnSessionStart"
},
{
"name": ".NET Core Attach",
"type": "coreclr",
"request": "attach",
"processId": "${command.pickProcess}"
}
]
}

View File

@@ -0,0 +1,16 @@
{
"version": "0.1.0",
"command": "dotnet",
"isShellCommand": true,
"args": [],
"tasks": [
{
"taskName": "build",
"args": [
"${workspaceRoot}/project.json"
],
"isBuildCommand": true,
"problemMatcher": "$msCompile"
}
]
}

View File

@@ -0,0 +1,20 @@
using System;
using System.Collections.Generic;
namespace ConsoleApplication
{
public class Program
{
public static void Main(string[] args)
{
var book = new Dictionary<string, decimal>();
book.Add("apple", 0.67m);
book.Add("milk", 1.49m);
book.Add("avocado", 1.49m);
foreach (var item in book)
{
Console.WriteLine($"{item.Key}: {item.Value}");
}
}
}
}

View File

@@ -0,0 +1,19 @@
{
"version": "1.0.0-*",
"buildOptions": {
"debugType": "portable",
"emitEntryPoint": true
},
"dependencies": {},
"frameworks": {
"netcoreapp1.0": {
"dependencies": {
"Microsoft.NETCore.App": {
"type": "platform",
"version": "1.0.1"
}
},
"imports": "dnxcore50"
}
}
}

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,2 @@
**/bin/*
**/obj/*

View File

@@ -0,0 +1,23 @@
{
"version": "0.2.0",
"configurations": [
{
"name": ".NET Core Launch (console)",
"type": "coreclr",
"request": "launch",
"preLaunchTask": "build",
"program": "${workspaceRoot}/bin/Debug/netcoreapp1.0/02_check_voter.dll",
"args": [],
"cwd": "${workspaceRoot}",
"externalConsole": false,
"stopAtEntry": false,
"internalConsoleOptions": "openOnSessionStart"
},
{
"name": ".NET Core Attach",
"type": "coreclr",
"request": "attach",
"processId": "${command.pickProcess}"
}
]
}

View File

@@ -0,0 +1,16 @@
{
"version": "0.1.0",
"command": "dotnet",
"isShellCommand": true,
"args": [],
"tasks": [
{
"taskName": "build",
"args": [
"${workspaceRoot}/project.json"
],
"isBuildCommand": true,
"problemMatcher": "$msCompile"
}
]
}

View File

@@ -0,0 +1,29 @@
using System;
using System.Collections.Generic;
namespace ConsoleApplication
{
public class Program
{
private static Dictionary<string, bool> _voted = new Dictionary<string, bool>();
public static void Main(string[] args)
{
CheckVoter("tom");
CheckVoter("mike");
CheckVoter("mike");
}
private static void CheckVoter(string name)
{
if (_voted.ContainsKey(name))
{
Console.WriteLine("kick them out!");
}
else
{
_voted.Add(name, true);
Console.WriteLine("let them vote!");
}
}
}
}

View File

@@ -0,0 +1,19 @@
{
"version": "1.0.0-*",
"buildOptions": {
"debugType": "portable",
"emitEntryPoint": true
},
"dependencies": {},
"frameworks": {
"netcoreapp1.0": {
"dependencies": {
"Microsoft.NETCore.App": {
"type": "platform",
"version": "1.0.1"
}
},
"imports": "dnxcore50"
}
}
}

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,2 @@
**/bin/*
**/obj/*

View File

@@ -0,0 +1,23 @@
{
"version": "0.2.0",
"configurations": [
{
"name": ".NET Core Launch (console)",
"type": "coreclr",
"request": "launch",
"preLaunchTask": "build",
"program": "${workspaceRoot}/bin/Debug/netcoreapp1.0/01_breadth_first_search.dll",
"args": [],
"cwd": "${workspaceRoot}",
"externalConsole": false,
"stopAtEntry": false,
"internalConsoleOptions": "openOnSessionStart"
},
{
"name": ".NET Core Attach",
"type": "coreclr",
"request": "attach",
"processId": "${command.pickProcess}"
}
]
}

View File

@@ -0,0 +1,16 @@
{
"version": "0.1.0",
"command": "dotnet",
"isShellCommand": true,
"args": [],
"tasks": [
{
"taskName": "build",
"args": [
"${workspaceRoot}/project.json"
],
"isBuildCommand": true,
"problemMatcher": "$msCompile"
}
]
}

View File

@@ -0,0 +1,53 @@
using System;
using System.Collections.Generic;
using System.Linq;
namespace ConsoleApplication
{
public class Program
{
private static Dictionary<string, string[]> _graph = new Dictionary<string, string[]>();
public static void Main(string[] args)
{
_graph.Add("you", new[] { "alice", "bob", "claire" });
_graph.Add("bob", new[] { "anuj", "peggy" });
_graph.Add("alice", new[] { "peggy" });
_graph.Add("claire", new[] { "thom", "jonny" });
_graph.Add("anuj", Array.Empty<string>());
_graph.Add("peggy", Array.Empty<string>());
_graph.Add("thom", Array.Empty<string>());
_graph.Add("jonny", Array.Empty<string>());
Search("you");
}
private static bool Search(string name)
{
var searchQueue = new Queue<string>(_graph[name]);
var searched = new List<string>();
while (searchQueue.Any())
{
var person = searchQueue.Dequeue();
if (!searched.Contains(person))
{
if (PersonIsSeller(person))
{
Console.WriteLine($"{person} is a mango seller");
return true;
}
else
{
searchQueue = new Queue<string>(searchQueue.Concat(_graph[person]));
searched.Add(person);
}
}
}
return false;
}
private static bool PersonIsSeller(string name)
{
return name.EndsWith("m");
}
}
}

View File

@@ -0,0 +1,19 @@
{
"version": "1.0.0-*",
"buildOptions": {
"debugType": "portable",
"emitEntryPoint": true
},
"dependencies": {},
"frameworks": {
"netcoreapp1.0": {
"dependencies": {
"Microsoft.NETCore.App": {
"type": "platform",
"version": "1.0.1"
}
},
"imports": "dnxcore50"
}
}
}

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,2 @@
**/bin/*
**/obj/*

View File

@@ -0,0 +1,23 @@
{
"version": "0.2.0",
"configurations": [
{
"name": ".NET Core Launch (console)",
"type": "coreclr",
"request": "launch",
"preLaunchTask": "build",
"program": "${workspaceRoot}/bin/Debug/netcoreapp1.0/01_dijkstras_algorithm.dll",
"args": [],
"cwd": "${workspaceRoot}",
"externalConsole": false,
"stopAtEntry": false,
"internalConsoleOptions": "openOnSessionStart"
},
{
"name": ".NET Core Attach",
"type": "coreclr",
"request": "attach",
"processId": "${command.pickProcess}"
}
]
}

View File

@@ -0,0 +1,16 @@
{
"version": "0.1.0",
"command": "dotnet",
"isShellCommand": true,
"args": [],
"tasks": [
{
"taskName": "build",
"args": [
"${workspaceRoot}/project.json"
],
"isBuildCommand": true,
"problemMatcher": "$msCompile"
}
]
}

View File

@@ -0,0 +1,73 @@
using System;
using System.Collections.Generic;
namespace ConsoleApplication
{
public class Program
{
private const double _infinity = double.PositiveInfinity;
private static Dictionary<string, Dictionary<string, double>> _graph = new Dictionary<string, Dictionary<string, double>>();
private static List<string> _processed = new List<string>();
public static void Main(string[] args)
{
_graph.Add("start", new Dictionary<string, double>());
_graph["start"].Add("a", 6.0);
_graph["start"].Add("b", 2.0);
_graph.Add("a", new Dictionary<string, double>());
_graph["a"].Add("fin", 1.0);
_graph.Add("b", new Dictionary<string, double>());
_graph["b"].Add("a", 3.0);
_graph["b"].Add("fin", 5.0);
_graph.Add("fin", new Dictionary<string, double>());
var costs = new Dictionary<string, double>();
costs.Add("a", 6.0);
costs.Add("b", 2.0);
costs.Add("fin", _infinity);
var parents = new Dictionary<string, string>();
parents.Add("a", "start");
parents.Add("b", "start");
parents.Add("fin", null);
var node = FindLowestCostNode(costs);
while (node != null)
{
var cost = costs[node];
var neighbors = _graph[node];
foreach (var n in neighbors.Keys)
{
var new_cost = cost + neighbors[n];
if (costs[n] > new_cost)
{
costs[n] = new_cost;
parents[n] = node;
}
}
_processed.Add(node);
node = FindLowestCostNode(costs);
}
Console.WriteLine(string.Join(", ", costs));
}
private static string FindLowestCostNode(Dictionary<string, double> costs)
{
var lowestCost = double.PositiveInfinity;
string lowestCostNode = null;
foreach (var node in costs)
{
var cost = node.Value;
if (cost < lowestCost && !_processed.Contains(node.Key))
{
lowestCost = cost;
lowestCostNode = node.Key;
}
}
return lowestCostNode;
}
}
}

View File

@@ -0,0 +1,19 @@
{
"version": "1.0.0-*",
"buildOptions": {
"debugType": "portable",
"emitEntryPoint": true
},
"dependencies": {},
"frameworks": {
"netcoreapp1.0": {
"dependencies": {
"Microsoft.NETCore.App": {
"type": "platform",
"version": "1.0.1"
}
},
"imports": "dnxcore50"
}
}
}

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,2 @@
**/bin/*
**/obj/*

View File

@@ -0,0 +1,23 @@
{
"version": "0.2.0",
"configurations": [
{
"name": ".NET Core Launch (console)",
"type": "coreclr",
"request": "launch",
"preLaunchTask": "build",
"program": "${workspaceRoot}/bin/Debug/netcoreapp1.0/01_set_covering.dll",
"args": [],
"cwd": "${workspaceRoot}",
"externalConsole": false,
"stopAtEntry": false,
"internalConsoleOptions": "openOnSessionStart"
},
{
"name": ".NET Core Attach",
"type": "coreclr",
"request": "attach",
"processId": "${command.pickProcess}"
}
]
}

View File

@@ -0,0 +1,16 @@
{
"version": "0.1.0",
"command": "dotnet",
"isShellCommand": true,
"args": [],
"tasks": [
{
"taskName": "build",
"args": [
"${workspaceRoot}/project.json"
],
"isBuildCommand": true,
"problemMatcher": "$msCompile"
}
]
}

View File

@@ -0,0 +1,37 @@
using System;
using System.Collections.Generic;
using System.Linq;
namespace ConsoleApplication
{
public class Program
{
public static void Main(string[] args)
{
var statesNeeded = new HashSet<string> { "mt", "wa", "or", "id", "nv", "ut", "ca", "az" };
var stations = new Dictionary<string, HashSet<string>>();
stations.Add("kone", new HashSet<string> { "id", "nv", "ut" });
stations.Add("ktwo", new HashSet<string> { "wa", "id", "mt" });
stations.Add("kthree", new HashSet<string> { "or", "nv", "ca" });
stations.Add("kfour", new HashSet<string> { "nv", "ut" });
stations.Add("kfive", new HashSet<string> { "ca", "az" });
var finalStations = new HashSet<string>();
while (statesNeeded.Any())
{
string bestStation = null;
var statesCovered = new HashSet<string>();
foreach (var station in stations)
{
var covered = new HashSet<string>(statesNeeded.Intersect(station.Value));
if (covered.Count > statesCovered.Count){
bestStation = station.Key;
statesCovered = covered;
}
}
statesNeeded.RemoveWhere(s => statesCovered.Contains(s));
finalStations.Add(bestStation);
}
Console.WriteLine(string.Join(", ", finalStations));
}
}
}

View File

@@ -0,0 +1,19 @@
{
"version": "1.0.0-*",
"buildOptions": {
"debugType": "portable",
"emitEntryPoint": true
},
"dependencies": {},
"frameworks": {
"netcoreapp1.0": {
"dependencies": {
"Microsoft.NETCore.App": {
"type": "platform",
"version": "1.0.1"
}
},
"imports": "dnxcore50"
}
}
}

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,2 @@
**/bin/*
**/obj/*

View File

@@ -0,0 +1,23 @@
{
"version": "0.2.0",
"configurations": [
{
"name": ".NET Core Launch (console)",
"type": "coreclr",
"request": "launch",
"preLaunchTask": "build",
"program": "${workspaceRoot}/bin/Debug/netcoreapp1.0/01_longest_common_subsequence.dll",
"args": [],
"cwd": "${workspaceRoot}",
"externalConsole": false,
"stopAtEntry": false,
"internalConsoleOptions": "openOnSessionStart"
},
{
"name": ".NET Core Attach",
"type": "coreclr",
"request": "attach",
"processId": "${command.pickProcess}"
}
]
}

View File

@@ -0,0 +1,16 @@
{
"version": "0.1.0",
"command": "dotnet",
"isShellCommand": true,
"args": [],
"tasks": [
{
"taskName": "build",
"args": [
"${workspaceRoot}/project.json"
],
"isBuildCommand": true,
"problemMatcher": "$msCompile"
}
]
}

View File

@@ -0,0 +1,20 @@
using System;
namespace ConsoleApplication
{
public class Program
{
public static void Main(string[] args)
{
if (word_a[i] == word_b[1])
{
cell[i][j] = cell[i - 1][j - 1] + 1;
}
else
{
cell[i][j] = Math.Max(cell[i - 1][j], cell[i][j - 1]);
}
}
}
}

View File

@@ -0,0 +1,19 @@
{
"version": "1.0.0-*",
"buildOptions": {
"debugType": "portable",
"emitEntryPoint": true
},
"dependencies": {},
"frameworks": {
"netcoreapp1.0": {
"dependencies": {
"Microsoft.NETCore.App": {
"type": "platform",
"version": "1.0.1"
}
},
"imports": "dnxcore50"
}
}
}

File diff suppressed because it is too large Load Diff