Skip to content

Instantly share code, notes, and snippets.

View maxint137's full-sized avatar
💭
back to life?

Max Levy maxint137

💭
back to life?
View GitHub Profile
@maxint137
maxint137 / projecteuler-problem4.cs
Last active February 5, 2017 14:47
Project Euler #4
// A palindromic number reads the same both ways. The largest palindrome made from the product of two 2-digit numbers is 9009 = 91 × 99.
// Find the largest palindrome made from the product of two 3-digit numbers.
// https://projecteuler.net/problem=4
void Main()
{
// xyz * XYZ = abccba
foreach (var p in sixDigitPalindroms())
{
foreach (var prm in permutationsOf(dividersOf(p)).Distinct(new Cmp()))
{
@maxint137
maxint137 / projecteuler-problem5.cs
Last active February 5, 2017 14:48
Project Euler #5
// 2520 is the smallest number that can be divided by each of the numbers from 1 to 10 without any remainder.
// What is the smallest positive number that is evenly divisible by all of the numbers from 1 to 20?
// https://projecteuler.net/problem=5
void Main()
{
var bop = new BagOfPrimes();
Enumerable.Range(1, 20)
.Select(d=>dividersOf(d).GroupBy(_=>_).Aggregate(bop, (c,n) => c.add(n)).value)
.Dump();
@maxint137
maxint137 / problem7.cs
Last active February 5, 2017 15:52
Project Euler #7
// By listing the first six prime numbers: 2, 3, 5, 7, 11, and 13, we can see that the 6th prime is 13
// What is the 10 001st prime number?
// https://projecteuler.net/problem=7
void Main()
{
var knownPrimes = new List<int>(new int[] { 2 });
int N = 3;
while (knownPrimes.Count() < 10001)
{
@maxint137
maxint137 / problem8.cs
Last active February 5, 2017 16:44
Project Euler #8
// https://projecteuler.net/problem=8
var N = @"
73167176531330624919225119674426574742355349194934
96983520312774506326239578318016984801869478851843
85861560789112949495459501737958331952853208805511
12540698747158523863050715693290963295227443043557
66896648950445244523161731856403098711121722383113
62229893423380308135336276614282806444486645238749
30358907296290491560440772390713810515859307960866
70172427121883998797908792274921901699720888093776
@maxint137
maxint137 / problem9.cs
Created February 5, 2017 17:02
Project Euler #9
//https://projecteuler.net/problem=9
void Main()
{
int P = 1000;
var t = Enumerable.Range(1,P)
.Select(a => possibleBC(a, P))
.SelectMany(_ => _)
.Where(_=>_.Item2*_.Item2+_.Item3*_.Item3==_.Item1*_.Item1)
.First();
### Keybase proof
I hereby claim:
* I am maxint137 on github.
* I am maxint (https://keybase.io/maxint) on keybase.
* I have a public key ASCrzuZRguTE-KNFEFGqp0M6RGR8pYeTYmHA2-wNrYd2nAo
To claim this, I am signing this object:
class projecteuler018
{
void parseRawData()
{
istringstream iss{ rawdata };
string row;
int i{};
while(getline(iss, row, '\n'))
{
@maxint137
maxint137 / test.html
Last active June 20, 2017 07:40
learning SVG
<!DOCTYPE html>
<html>
<head>
<title>SVG in HTML</title>
<style>
body {
font-family: cursive;
}
circle {
@maxint137
maxint137 / graphCycles.cs
Last active July 20, 2017 05:52
Find a cycle of a given length in a graph
void Main()
{
var n0 = new Node<string>("n0", null);
var n1 = new Node<string>("n1", null);
var n2 = new Node<string>("n2", null);
var n3 = new Node<string>("n3", null);
var n4 = new Node<string>("n4", null);
var n5 = new Node<string>("n5", null);
var n6 = new Node<string>("n6", null);
var n7 = new Node<string>("n7", null);
@maxint137
maxint137 / Tarjan.cs
Created July 20, 2017 05:06
Tarjan's strongly connected components algorithm
void Main()
{
int N = 8;
var nodes = new List<Node>(N + 1);
foreach (var n in Enumerable.Range(0, N + 1))
{
nodes.Add(new Node($"n{n}", null));
}
nodes[1].setNodes(new Node[] { nodes[2] });