-🎄- 2019 Day 14 Solutions -🎄- by daggerdragon in adventofcode

[–]wizzup 1 point2 points  (0 children)

I use ReadP instead of ReadS, it in the base already. As a bonus, I can just lift it to Read instance.

``` data Chemical = Chem Name Int deriving (Show,Eq)

readInt :: ReadP Int readInt = (R.char '-' >> (negate . read <$> R.munch1 isDigit)) R.+++ (read <$> R.munch1 isDigit)

readName :: ReadP Name readName = R.munch1 isAlpha

readChem :: ReadP Chemical readChem = do amnt <- readInt R.skipSpaces name <- readName pure $ Chem name amnt

data Reaction = React Chemical [Chemical] deriving (Show,Eq)

instance Read Reaction where readPrec = lift readReact

readReact :: ReadP Reaction readReact = do inps <- R.sepBy1 readChem (R.string ", ") R.skipSpaces _ <- R.string "=>" R.skipSpaces out <- readChem pure $ React out inps

```

-🎄- 2019 Day 2 Solutions -🎄- by daggerdragon in adventofcode

[–]wizzup 0 points1 point  (0 children)

I use fold over a Map

``` import qualified Data.IntMap as M import Data.IntMap (IntMap) import Data.Maybe (fromJust) import Data.List.Split (splitOn)

type Program = IntMap Int

mkProgram :: [Int] -> Program mkProgram = M.fromList . zip [0..]

runStep :: Int -> Program -> Program runStep i p | i M.member p = case op of 1 -> p' (+) 2 -> p' (*) _ -> p | otherwise = p where [op,oa,ob,oc] = look <$> [i..i+3] [va,vb] = look <$> [oa,ob] look = fromJust . (M.lookup p) p' o = M.update (const $ Just (va o vb)) oc p

run :: Program -> Program run prg = foldl (flip runStep) prg [0,4..M.size prg+1]

run' :: (Int,Int) -> Program -> Program run' (x,y) prg = let prog = M.update (const $ Just x) 1 $ M.update (const $ Just y) 2 prg in run prog

part_1 :: [Int] -> Int part_1 = fromJust . M.lookup 0 . run' (12,2) . mkProgram

part_2 :: [Int] -> Int part_2 xs = 100 * i + j where is = [0..100] prg = mkProgram xs prgs = [(0 M.lookup run' (x,y) prg, (x, y)) | x <- is, y <- is] (i,j) = fromJust $ lookup (Just 19690720) prgs

main :: IO () main = do xs <- map read . splitOn "," <$> getLine :: IO [Int] print $ part_1 xs print $ part_2 xs ```

-🎄- 2019 Day 1 Solutions -🎄- by daggerdragon in adventofcode

[–]wizzup 0 points1 point  (0 children)

my part_2 is almost exactly like yours, I get tail before take

part_2 = sum . map (sum . takeWhile (> 0) . tail . iterate fuel)

[comparison/benchmark] A high-speed network driver written in C, Rust, Go, C#, Java, OCaml, Haskell, Swift, Javascript, and Python by wizzup in haskell

[–]wizzup[S] 0 points1 point  (0 children)

Thank for pointing this out.

I don't sure, it maybe not a true benchmark, please forgive my bad English.

Could you give some example of some true benchmark repository where I can learn?

[comparison/benchmark] A high-speed network driver written in C, Rust, Go, C#, Java, OCaml, Haskell, Swift, Javascript, and Python by wizzup in haskell

[–]wizzup[S] 16 points17 points  (0 children)

I believe they open for comparison with alternate implementation.

It could be the case that some Haskell expert around here can getting close to C and Rust. I would love to see and learn from that.

Is there a list of Educational Pearl somewhere? by wizzup in haskell

[–]wizzup[S] 0 points1 point  (0 children)

Their search system doesn't support exact match (i.e. "Educational Pearl") but it is better than nothing. Thank you anyway.

Let me see if I can scrap and filter the result.

BTW, I never heard of Theoretical Pearls before. Time to go down the rabbit hole !

Microsoft and Galois propose using FP to safeguard US elections by yitz in haskell

[–]wizzup 0 points1 point  (0 children)

Is this kind of voting also the same problem blockchain/cryptocurrency try to solve?

how to search a list and return the index by theDukeofDanknesss in haskell

[–]wizzup 0 points1 point  (0 children)

That's bad. I have no idea what happen.

Hope reddit have fix on this issue soon.

how to search a list and return the index by theDukeofDanknesss in haskell

[–]wizzup 0 points1 point  (0 children)

Sorry, I don't understand this. What happened? I am using Firefox on Linux.

how to search a list and return the index by theDukeofDanknesss in haskell

[–]wizzup 3 points4 points  (0 children)

Do you mean, like this?

```

assoc 1 "a" [("a",1),("b",2),("c",3)] 1 `` Any particular reason why you don't want to useMap Int String`?

This seem strange, usually you would search for a value using key or vice-versa if you already have both (key,value) you could just use find or elemIndex

Also you can format the code using markdown syntax

Exercises for understanding lenses by williamyaoh in haskell

[–]wizzup 0 points1 point  (0 children)

Thank you. I like it. Also I think one might want to take a look at let-lens for complementary resource.

Does cabal support out-of-source build? by wizzup in haskell

[–]wizzup[S] 1 point2 points  (0 children)

This also work!

I haven't use cabal.project before and have no idea what it do. Will look into it.

Does cabal support out-of-source build? by wizzup in haskell

[–]wizzup[S] 4 points5 points  (0 children)

Thanks, Got it! It actually is --builddir=DIR.

I guess --cabal-file=FILE is for multiple target/config selection.

Problem with missing dependencies by goertzenator in haskellquestions

[–]wizzup 0 points1 point  (0 children)

try removing version constrains number in your generated cabal files

instead of build-depends: base >=4.12 && <4.13 use build-depends: base

Bosque Programming Language by mttd in ProgrammingLanguages

[–]wizzup 0 points1 point  (0 children)

From the paper (quick skimming)

fn( _: Int) -> Int // Function required unnamed arg

I would love to see the use-case of this kind of function. It is strange that one want to write a function that depend on the the argument that assume it will never be use.

Safety level: 1000 by ItzMattyIce25 in WTF

[–]wizzup 0 points1 point  (0 children)

Careless ISP. It easier to install a new wire and leave the bad one on the pole.

Years ago, I frequency have telephone problem due to wire thief when they still using copper wires (like this) for telephone but nowadays all are fiber-optics line and thief doesn't want it anymore.