Skip to content

Instantly share code, notes, and snippets.

View m-khooryani's full-sized avatar

Mojtaba Khooryani m-khooryani

  • Polestar
  • Gothenburg, Sweden
View GitHub Profile
@m-khooryani
m-khooryani / Program.cs
Created March 9, 2021 21:48
without middleware function app
[FunctionName(nameof(SomeCommandFunction))]
public static async Task<Guid> Run([HttpTrigger(AuthorizationLevel.Anonymous, "post")]
HttpRequestData req, FunctionExecutionContext executionContext,
ILogger logger,
IUnitOfWork unitOfWork)
{
logger.LogInformation("Function started");
// some Logic (skipped for simplicity)
var addedId = Guid.NewGuid();
@m-khooryani
m-khooryani / Program.cs
Created July 2, 2020 09:30
Count Paths in n*m Matrix (DP)
static void Main(string[] args)
{
int n = 5, m = 5;
Console.WriteLine(CountPaths(n, m)); // 70
}
static int CountPaths(int n, int m)
{
int[,] dp = new int[n, m];
dp[n - 1, m - 1] = 1;
@m-khooryani
m-khooryani / Program.cs
Last active July 1, 2020 15:05
Partition Problem (DP)
class Program
{
static void Main(string[] args)
{
int[] a = new int[] { 15, 5, 20, 10, 35, 15, 10 };
Console.WriteLine(Partition(a, a.Sum() / 2)); // true
}
private static bool Partition(int[] a, int S)
@m-khooryani
m-khooryani / Program.cs
Created June 24, 2020 15:00
Subset Sum (DP)
class Program
{
static int[] s;
static int k;
static Point[,] points;
static void Main(string[] args)
{
k = 24;
s = new int[] { 12, 1, 61, 5, 9, 2 };
@m-khooryani
m-khooryani / Program.cs
Last active June 23, 2020 15:22
Subset Sum (Bitmask)
class Program
{
static void Main(string[] args)
{
int k = 24;
int[] s = new int[] { 12, 1, 61, 5, 9, 2 };
s = s.Where(x => x <= k).ToArray();
int n = s.Length;
List<int> indices = new List<int>();
@m-khooryani
m-khooryani / Program.cs
Created June 13, 2020 15:25
Pattern Matching
class Program
{
static void Main(string[] args)
{
Console.WriteLine(PatternMatching("cheat", "c.*t")); // true
Console.WriteLine(PatternMatching("bcd", "abcd")); // false
Console.WriteLine(PatternMatching("cheat", "c.*te")); // false
Console.WriteLine(PatternMatching("abcdef", ".***************************.")); // true
Console.WriteLine(PatternMatching("abcdef", ".***************************")); // true
}
@m-khooryani
m-khooryani / Program.cs
Created June 12, 2020 17:01
Shortest Path in binary matrix
class Program
{
static void Main(string[] args)
{
bool[][] matrix = new bool[][]
{
new bool[] {false, false, false, false },
new bool[] {true, true, false, true },
new bool[] {false, false, false, false },
new bool[] {false, false, false, false },
@m-khooryani
m-khooryani / Program.cs
Last active June 10, 2020 06:57
calculate Pi using Monte Carlo
class Program
{
static void Main(string[] args)
{
Tuple<long, double> tuple = CalculatePI(new Random(0));
var points = tuple.Item1;
var pi = tuple.Item2;
Console.WriteLine($"PI: {pi} using Monte Carlo method with {points} points.");
}
@m-khooryani
m-khooryani / Program.cs
Created June 9, 2020 16:10
Longest substring with K unique characters
class Program
{
static void Main(string[] args)
{
Console.WriteLine(LongestSubstringWithKUniqueChars("abcba", 2));
}
private static string LongestSubstringWithKUniqueChars(string s, int k)
{
if (k == 0)
@m-khooryani
m-khooryani / Program.cs
Created June 5, 2020 11:59
Auto-complete using Trie
class Program
{
static void Main(string[] args)
{
Trie trie = new Trie();
trie.Insert("dog");
trie.Insert("deer");
trie.Insert("deal");
var foundWords = trie.Search("de");