Skip to content

Instantly share code, notes, and snippets.

View edalorzo's full-sized avatar

Edwin Dalorzo edalorzo

View GitHub Profile
@edalorzo
edalorzo / PythonEuler9.py
Created November 25, 2012 03:19
Project Euler-Problem #9
def calc_triple(m, n):
a = n ** 2 - m ** 2
b = 2 * m * n
c = n ** 2 + m ** 2
return (a,b,c)
def find_triplet():
j = 1
sum = 0
@edalorzo
edalorzo / PythonEuler12.py
Created November 25, 2012 17:06
Project Euler-Problem #12
from itertools import groupby
from collections import defaultdict
def divides(k,n):
"""
Determines if number n is divisible by n
"""
return n % k == 0
@edalorzo
edalorzo / PythonEuler37.py
Created November 25, 2012 17:45
Project Euler-Problem #37
def divides(k,n):
"""
Determines if number n is divisible by n
"""
return n % k == 0
def ldf(n, k):
"""
Obtains the least divisor of n starting from k.
"""
@edalorzo
edalorzo / basic-list-functions.sml
Last active July 15, 2021 17:04
Learning SML - Basic List Functions
(* Returns the head of a list. *)
fun head(xs) =
case xs of
[] => raise List.Empty
| (x::_) => x
(* Returns the tail of a list. *)
fun tail(xs) =
case xs of
[] => raise List.Empty
@edalorzo
edalorzo / Example.java
Created February 17, 2013 15:01
Java Infinite Streams
package codemasters.lambda.learn.streams;
import java.util.List;
import java.util.Iterator;
import java.util.ArrayList;
import java.util.NoSuchElementException;
import java.util.function.Supplier;
import java.util.function.Consumer;
import java.util.function.Predicate;
@edalorzo
edalorzo / Example.cs
Last active December 14, 2015 02:39
C# Infinite Streams
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace CodeMasters
{
class Program
{
@edalorzo
edalorzo / Euler21.hs
Last active December 14, 2015 04:18
Problem Euler 21 - Haskell Solution
module Euler.Problem21 where
import qualified Data.Map as Map
import qualified Data.Set as Set
problem1::Int->Int->Int->Int
problem1 a b n = sum [x | x <- [1..n-1], x `mod` a == 0 || x `mod` b == 0]
sumOfProperDivisors::Int->Int
sumOfProperDivisors n = sum [x | x <- [1..n `div` 2], n `mod` x == 0]
@edalorzo
edalorzo / Cons.java
Created March 11, 2013 16:48
Java Infinite Streams
import java.util.function.Supplier;
public class Cons<T> implements Stream<T>{
private final T head;
//stream thunk
private final Supplier<Stream<T>> tail;
public Cons(T head, Supplier<Stream<T>> tail) {
this.head = head;
package codemasters.lambda.linq;
import java.util.List;
import java.util.Map;
import java.util.LinkedHashMap;
import java.util.Map.Entry;
import java.util.AbstractMap.SimpleEntry;
import java.util.function.ToIntFunction;
import java.util.function.ToDoubleFunction;
import java.util.function.BiFunction;
import codemasters.lambda.domain.Car;
import codemasters.lambda.domain.Person;
import codemasters.lambda.domain.Sale;
import java.util.*;
import java.util.Map.Entry;
import java.util.function.ToIntFunction;
import java.util.function.ToDoubleFunction;
import java.util.function.Function;
import java.util.function.Supplier;