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
# https://www.facebook.com/codingcompetitions/hacker-cup/2021/qualification-round/problems/A1 | |
$vowels = "AEIOU" | |
function convert-letter($inputCh, $targetCh) | |
{ | |
if ($inputCh -eq $targetCh) | |
{ | |
return 0; | |
} |
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
{-# LANGUAGE FlexibleInstances, UndecidableInstances, InstanceSigs, NoImplicitPrelude #-} | |
import Prelude(id, ($), (.), putStrLn, undefined) | |
-- The standard(?) haskell monad definition | |
class StdMonad m where | |
(>>=) :: m a -> (a -> m b) -> m b | |
return :: a -> m a | |
-- The more mathematical monad defintion |
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
// Ref: https://codingdojo.org/kata/BankOCR/ | |
// Disable warning for incomplete pattern matching, https://github.com/fsharp/fslang-suggestions/issues/278 would be nice | |
#nowarn "25" | |
open System | |
type Bit = Zero | One | |
with | |
static member fromBool b = if b then One else Zero |
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
:- use_module(library(clpfd)). | |
amountRule(AMOUNT) :- AMOUNT #>= 5000, AMOUNT #=< 100000. | |
durationRule(AMOUNT,DURATION) :- | |
MINDURATION #= 6, | |
DURATION #>= MINDURATION, | |
AMOUNT #>= 25000 #<==> D1, | |
AMOUNT #>= 50000 #<==> D2, | |
AMOUNT #>= 75000 #<==> D3, | |
MAXDURATION #= 12 + D1 * 12 + D2 * 12 + D3 * 12, |
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
{-# LANGUAGE FlexibleInstances, GADTs #-} | |
import Data.List (intercalate) | |
import qualified Data.Semigroup as S | |
import Data.Monoid | |
---------------------------------------------------------------- | |
-- Semiring | |
---------------------------------------------------------------- |
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
-- formalize lifting : (some kind of done) | |
-- obs (lift rs) ctxm == fold1 (<>) (map (\ctxs -> obs rs ctxs) ctxm) | |
-- | |
-- unify reval and rreduce? | |
-- quick check of laws | |
-- better test rules | |
-- a high level eval function that incrementally extends contexts and redecues the rule until trival is reached | |
-- parse from show | |
-- context dependent show | |
-- cleanup / generalize semiring instances |
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
using System; | |
using System.Text.RegularExpressions; | |
using NUnit.Framework; | |
namespace FormatChallenge | |
{ | |
public class FormattableTests | |
{ | |
[TestCase("ccccnnnnnnnn", "330012345678")] | |
[TestCase("nnnnnnnn", "12345678")] | |
[TestCase("cccc-nnnnnnnn", "3300-12345678")] |
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
{-# LANGUAGE InstanceSigs, MultiParamTypeClasses #-} | |
import Control.Applicative | |
import qualified Data.Map as Map | |
import Data.Map (Map) | |
import qualified Data.Monoid as Monoid | |
import Data.Monoid (Monoid, Last(..), getLast) | |
import Data.Maybe (fromJust, isNothing, isJust) | |
--import Data.Map.Append -- map with "correct" monoid implementation... module not found though |
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
--{-# LANGUAGE StandaloneDeriving, DeriveFunctor, GeneralizedNewtypeDeriving #-} | |
import Data.Map (Map) | |
import qualified Data.Map as Map | |
import qualified Data.Maybe | |
type Amount = Int | |
type ApplicantId = String | |
--data Value = IntValue Int -- | StringValue String | |
type Value = Int |
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
{-# LANGUAGE MultiParamTypeClasses, FlexibleInstances, FunctionalDependencies #-} | |
import Data.Set (Set) | |
import qualified Data.Set as Set | |
import Data.List | |
import Data.Function (on) | |
type Var = String | |
type VarSet = Set Var |