Skip to content

Instantly share code, notes, and snippets.

View lgastako's full-sized avatar

John lgastako

  • Francon & Heyer
  • Milky Way Galaxy, Third Rock from the Sun
View GitHub Profile
{-# LANGUAGE OverloadedStrings #-}
module GetIn where
import Data.Aeson ( Value( Array
, Null
, Object
)
, decode
)
import qualified Data.Set as Set
type Row = Int
type Col = Int
renderSols :: [[(Row, Col)]] -> IO ()
renderSols = mapM_ (putStrLn . renderQs . Set.fromList)
where
renderQs queens = unlines $ map renderRow (range maxRow)
where
{-# LANGUAGE DeriveGeneric #-}
{-# LANGUAGE OverloadedLabels #-}
module SideEffectsExample where
import Control.Lens
import Control.Monad
import Control.Monad.IO.Class
import Control.Monad.Trans.State.Lazy
import Data.Generics.Labels
module Scrabble where
import Data.List ( sortOn )
import Data.Map.Strict ( Map )
import qualified Data.Map.Strict as Map
import System.IO ( hFlush
, stdout
)
main :: IO ()
{-# LANGUAGE InstanceSigs #-}
{-# LANGUAGE LambdaCase #-}
{-# LANGUAGE NoImplicitPrelude #-}
{-# LANGUAGE ScopedTypeVariables #-}
{-# LANGUAGE StandaloneDeriving #-}
{-# LANGUAGE TypeSynonymInstances #-}
module ParsingFromScratch where
import Data.String ( String )
module MonadPoker where
-- https://old.reddit.com/r/haskell/comments/gru0id/haskell_poker_foldm_monadrandom/
import Control.Monad
import Control.Monad.Random
import System.Random.Shuffle
data Rank
= Two
{-# LANGUAGE RankNTypes #-}
{-# LANGUAGE ScopedTypeVariables #-}
module Data.Matrix.Lens
( col
, diag
, elemAt
, inverted
, minor
, row
@lgastako
lgastako / TreeNumbering.hs
Last active May 15, 2020 03:53
Numbering nodes in a tree with and without lenses.
module TreeNumbering where
import Control.Lens
import Control.Monad.State
import Data.Tree
tree_ :: Tree Char
tree_ = Node 'd'
[ Node 'b'
[ Node 'a' []
words'' :: String -> [String]
words'' s
| s == "" = []
| otherwise = takeWhile (/= ' ') s : words'' (dropWhile (== ' ') (dropWhile (/= ' ') s))
words' :: String -> [String]
words' s
| w /= "" = w : words' rest
| otherwise = []
where
{-# LANGUAGE NoImplicitPrelude #-}
{-# LANGUAGE OverloadedStrings #-}
module Fizz where
import Protolude
fizzBuzz :: IO ()
fizzBuzz = run fizzBuzzRules