This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| from itertools import groupby | |
| from collections import defaultdict | |
| def divides(k,n): | |
| """ | |
| Determines if number n is divisible by n | |
| """ | |
| return n % k == 0 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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. | |
| """ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| (* 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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| using System; | |
| using System.Collections.Generic; | |
| using System.Linq; | |
| using System.Text; | |
| namespace CodeMasters | |
| { | |
| class Program | |
| { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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; |