This file contains 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 org.example.impl; | |
import org.example.api.Greeting; | |
import aQute.bnd.annotation.component.Component; | |
@Component | |
public class BasicGreeting implements Greeting { | |
public String sayHello(String name) { | |
return "Hello " + name; | |
} |
This file contains 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 org.example.api; | |
public interface Greeting { | |
String sayHello(String name); | |
} |
This file contains 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
-- Find the longest shared prefix of two lists | |
-- e.g. findPrefix [1,2,3,4] [1,2,3,5] returns [1,2,3] | |
findPrefix :: (Eq a) => [a] -> [a] -> [a] | |
findPrefix xs = map fst . takeWhile (uncurry (==)) . zip xs |
This file contains 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
countCrossings :: TestCase -> Int | |
countCrossings = length . guardedPairs crosses | |
-- This is the "pairs" function from the first meeting, with the addition of a | |
-- predicate function to filter out unwanted pairs | |
guardedPairs :: (a -> a -> Bool) -> [a] -> [(a,a)] | |
guardedPairs p xs = [(x,y) | (x:ys) <- tails xs, y <- ys, p x y] | |
crosses :: Wire -> Wire -> Bool | |
crosses (Wire s1 e1) (Wire s2 e2) = if s1 < s2 then e1 > e2 else e1 < e2 |
This file contains 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 Main where | |
import Control.Monad | |
import Data.List | |
type Line = [Int] | |
data Wire = Wire { start :: Int | |
, end :: Int } deriving Show |
NewerOlder