Skip to content

Instantly share code, notes, and snippets.

{-
binomial-distribution-1: https://www.hackerrank.com/challenges/binomial-distribution-1/
Author: Evgeniy Malov <[email protected]>
Date: Jan 4, 2025
join me : https://www.youtube.com/@EvgeniyMalov
https://ru.linkedin.com/in/deepwalk
-}
import Text.Printf (printf)
-- 4 shots
@evgenii-malov
evgenii-malov / gist:ad57a00c7fbb86a9825b1ab30315a011
Created January 2, 2025 17:26
hackerrank random-number-generator (with desmos visualisation)
{-
random-number-generator: https://www.hackerrank.com/challenges/random-number-generator
Author: Evgeniy Malov <[email protected]>
Date: Jan 1, 2025
join me : https://www.youtube.com/@EvgeniyMalov
https://ru.linkedin.com/in/deepwalk
-}
{-# LANGUAGE DuplicateRecordFields, FlexibleInstances, UndecidableInstances #-}
module Main where
for haskell repl:
:set prompt "\ESC[34mλ> \ESC[m"
for python repl:
sys.ps1 = '\x01\x1b[1;49;31m\x02λ>\x01\x1b[0m\x02'
sys.ps2 = '\x01\x1b[1;49;31m\x02λ>\x01\x1b[0m\x02'
@evgenii-malov
evgenii-malov / fif.sh
Created December 17, 2022 16:14
fzf search in files with open is visual studio code (ctrl-o)
fif() {
rg \
--column \
--no-heading \
--fixed-strings \
--ignore-case \
--hidden \
--follow \
--glob '!.git/*' \
--glob '!.vscode-server/*' \
@evgenii-malov
evgenii-malov / marrays.hs
Last active September 6, 2022 15:57
Work with mutable arrays in haskell examples
-- video https://youtu.be/uj2N5fBZnCA
import Data.Array.MArray
import Data.Array.IO.Internals (IOArray(IOArray))
import Control.Monad.ST
import Data.Array.ST
workio = do
a <- newArray (0,3) 'a' :: IO ( IOArray Int Char)
writeArray a 3 'x'
a_ <- getAssocs a
@evgenii-malov
evgenii-malov / iarray.hs
Last active September 6, 2022 15:57
work with Immutable array in Haskell
-- video https://youtu.be/RPEtIZ44RSc
import Data.Array.IArray
import Data.Char (toUpper)
-- elements that is associated with some kind of numerical index
-- truly constant time (O(1)) access.
-- store their data more efficiently in memory.
-- modification function must create an entirely new array (partially can be fixed with Monad context)
-- math look:
@evgenii-malov
evgenii-malov / bsort_st.hs
Last active September 5, 2022 09:00
Haskell bubble sort with ST monad and STref
-- video https://www.youtube.com/watch?v=9JDPGvc6UmI
import Control.Monad.ST
import Data.IntMap.Strict
import Data.STRef (newSTRef, readSTRef, writeSTRef, modifySTRef)
import Control.Monad
until_ :: Monad m => m a -> m Bool -> m ()
until_ a p = do
a
b <- p
@evgenii-malov
evgenii-malov / linked_list.hs
Created September 5, 2022 05:53
Haskell linked list with ST monad
-- see video https://www.youtube.com/watch?v=MJscn-m4KIo&t=3943s
import Data.STRef
import Control.Monad.ST
import Data.Maybe
import Control.Monad
import Data.Either (fromRight, isLeft, fromLeft)
import Debug.Trace
data Llist s a = Llist {llen:: STRef s Int, lhead:: STRef s (Maybe (Node s a)) }
@evgenii-malov
evgenii-malov / cartesiant_ik.hs
Last active April 22, 2022 13:17
Cartesian tree with implcit key in Haskell
-- explain video https://youtu.be/Ln_tVErialQ
-- GHCi, version 8.8.4
{-# LANGUAGE RankNTypes #-}
{-# LANGUAGE TypeOperators #-}
{-# OPTIONS_GHC -Wno-incomplete-patterns #-}
import PrettyT -- https://www.youtube.com/watch?v=Ud-1Z0hBlB8&t=379s
-- data Btree a = Empty | Node a (Btree a) (Btree a) deriving Show
import Data.Ord
import Data.List
@evgenii-malov
evgenii-malov / cartesian_tree.hs
Last active May 23, 2024 02:31
Build cartesian tree in Haskell in 3 ways (O(N^2), O(N*LogN) and O(N))
-- video https://youtu.be/E8Fxtpr24Zg
-- GHCi, version 8.8.4
{-# LANGUAGE RankNTypes #-}
{-# LANGUAGE TypeOperators #-}
{-# OPTIONS_GHC -Wno-incomplete-patterns #-}
import PrettyT -- https://www.youtube.com/watch?v=Ud-1Z0hBlB8&t=379s
-- data Btree a = Empty | Node a (Btree a) (Btree a) deriving Show
import Data.Ord
import Data.List