Skip to content

Instantly share code, notes, and snippets.

View ygrenzinger's full-sized avatar

Yannick Grenzinger ygrenzinger

View GitHub Profile
@ygrenzinger
ygrenzinger / Phone.hs
Created December 27, 2016 20:56
Phone.hs
module Phone where
import Data.Char (isUpper, toLower)
import Control.Arrow
import Data.List (maximumBy)
type Digit = Char
type Presses = Int
type Key = (Digit, String)
@ygrenzinger
ygrenzinger / quickCheckAndMonoid.hs
Created January 8, 2017 10:23
QuickCheck and Monoid experimentation
import Test.QuickCheck
import Data.List
import Data.Monoid
prop_revapp :: [Int] -> [Int] -> Bool
prop_revapp xs ys = reverse (ys++xs) == reverse xs ++ reverse ys
quotVsRem :: Integral a => a -> a -> Bool
quotVsRem x y = quot x y * y + rem x y == x
import Test.QuickCheck
import Test.QuickCheck.Function
prop_revapp :: [Int] -> [Int] -> Bool
prop_revapp xs ys = reverse (ys++xs) == reverse xs ++ reverse ys
data Two a b = Two a b deriving (Eq, Show)
data Or a b = First a | Second b deriving (Eq, Show)
instance Functor (Two a) where
@ygrenzinger
ygrenzinger / ConstantApplicative.hs
Last active January 10, 2017 15:08
Constant Applicative
newtype Constant a b = Constant { getConstant :: a } deriving (Eq, Ord, Show)
instance Functor (Constant a) where
fmap _ (Constant a) = Constant a
instance Monoid a => Applicative (Constant a) where
pure x = Constant mempty
(<*>) (Constant a) (Constant b) = Constant (a <> b)
@ygrenzinger
ygrenzinger / IsTestable.java
Created February 5, 2017 14:40
Java code snippet for test's part of interview
package interview;
/**
* Created by yannickgrenzinger on 02/12/2016.
*/
public class Executor {
private final Printer3D printer = new Printer3D();
private final XMLFileReader reader = new XMLFileReader();
@ygrenzinger
ygrenzinger / erlang-week1.erl
Last active February 26, 2017 13:49
Future Learn Erlang Mooc - Week 1
-module(week1).
-export([perimeter/1,area/1,enclose/1, bitsD/1, bitsT/1]).
% I don't use Erlang Unit test http://erlang.org/doc/apps/eunit/chapter.html
% Because I don't know how to setup a project with dependancies at this point
% Each shape is defined by it's name, some general info and some points
perimeter({circle,R, _CenterPoint}) ->
2 * math:pi() * R;
perimeter({rectangle,W,H, _Points}) ->
package interview;
import com.google.common.collect.Sets;
import org.junit.Test;
import java.util.*;
import static org.assertj.core.api.Assertions.assertThat;
@ygrenzinger
ygrenzinger / erlang-week2.erl
Created March 5, 2017 16:24
Future Learn Erlang Week 2 exercise
-module(week2).
-export([get_file_contents/1,show_file_contents/1, processText/1]).
-include_lib("eunit/include/eunit.hrl").
isAlphabetical(X) ->
($A =< X andalso X =< $Z) or ($a =< X andalso X =< $z).
isAlphabetical_test() ->
?assertEqual(true, isAlphabetical($G)),
?assertEqual(true, isAlphabetical($g)),
@ygrenzinger
ygrenzinger / erlang-week2.erl
Created March 5, 2017 16:24
Future Learn Erlang Week 2 exercise
-module(week2).
-export([get_file_contents/1,show_file_contents/1, processText/1]).
-include_lib("eunit/include/eunit.hrl").
isAlphabetical(X) ->
($A =< X andalso X =< $Z) or ($a =< X andalso X =< $z).
isAlphabetical_test() ->
?assertEqual(true, isAlphabetical($G)),
?assertEqual(true, isAlphabetical($g)),
@ygrenzinger
ygrenzinger / invert-tree.clj
Created March 18, 2017 13:57
Clojure best language to win Google Interview :)
;; https://leetcode.com/problems/invert-binary-tree/?tab=Description#/description
;; exemple of a graph [[[1] 2 [3]] 4 [[6] 7 [9]]]
(defn invert [tree]
(if (< (count tree) 2)
tree
[(invert (nth tree 2)) (nth tree 1) (invert (nth tree 0))]))