Skip to content

Instantly share code, notes, and snippets.

# 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;
}
{-# 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
// 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
:- 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,
{-# LANGUAGE FlexibleInstances, GADTs #-}
import Data.List (intercalate)
import qualified Data.Semigroup as S
import Data.Monoid
----------------------------------------------------------------
-- Semiring
----------------------------------------------------------------
-- 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
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")]
{-# 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
--{-# 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
{-# 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