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
-- Specification follows corresponding cata on codewars | |
{- | |
To run online I recommend to follow https://paiza.io/en/projects/new?language=haskell | |
, paste the code instead of the template, run and click on output tab. | |
This is a demo for the specific task, so it bypasses problem with negative logarithm argument optimistically. | |
Hence it yields arbitrary numbers if called on a value out of domain. | |
-} | |
module Main where |
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 Strict #-} | |
module Main where | |
{- | |
ghc -O2 weigth-basis.hs # Was not tested with default level. | |
./weight-basis.hs | |
-} | |
import Control.DeepSeq |
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
-- To prevent overflows | |
{-# LANGUAGE Strict #-} | |
module Main where | |
{- | |
ghc -O2 weigth.hs # Was not tested with default level. | |
./weight.hs 2> progress-bar.txt | |
-} | |
import Control.DeepSeq |
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 BangPatterns #-} | |
import Data.List ((\\), union, sort) | |
import Data.Foldable | |
import Debug.Trace | |
type N = Int | |
type Mono = Int | |
type IndexCode = Int | |
multMonomials :: Mono -> Mono -> Mono |
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
import Data.List ((\\), union, sort) | |
type Mono = Int | |
multMonomials :: Mono -> Mono -> Mono | |
multMonomials = (+) | |
divMonomial :: Mono -> Mono -> Mono | |
divMonomial a b = if a > b | |
then a - b |
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
import Data.List (sort, nub) | |
type Power = Int | |
type IndexCode = Int | |
type Flag = Int | |
type Orbit = [Power] | |
type Roots = [Power] | |
type P = Int | |
type N = 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
type Order = Integer | |
type Element = Integer | |
order :: Order -> Element -> Order | |
order p elem = order' p elem elem 1 | |
where | |
order' _ 1 _ ord = ord | |
order' p power elem ord = order' p (power*elem `mod` p) elem (ord+1) | |
elemsOfOrder :: Order -> Order -> [Element] |
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
import Data.List (sort, nub) | |
type Power = Int | |
type IndexCode = Int | |
type Flag = Int | |
type Orbit = [Power] | |
type Roots = [Power] | |
type P = Int | |
type N = 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
type Order = Integer | |
type Element = Integer | |
order :: Order -> Element -> Order | |
order p elem = order' p elem elem 1 | |
where | |
order' _ 1 _ ord = ord | |
order' p power elem ord = order' p (power*elem `mod` p) elem (ord+1) | |
-- Searching any generator of cyclic subgroup of order d. |
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
module Main where | |
import Control.Monad | |
-- Directly composing morphisms as if we were not in End_{Hask}. | |
regular :: (->) Int Int | |
regular = (+) 1 . (+) 1 . (+) 1 . (+) 1 | |
-- Actually the same, but explicitly using action of Hom-functor on arrows. | |
functorial :: (->) Int Int |
NewerOlder