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
-- https://myuon.github.io/posts/haskell-atcoder/ を参考にしつつ競プロっぽい書き方にできないか試す | |
{-# LANGUAGE Strict #-} | |
module Main where | |
import qualified Data.ByteString.Char8 as BS | |
import qualified Data.Vector.Unboxed as VU | |
checkMax :: BS.ByteString -> BS.ByteString -> VU.Vector Int -> Int -> Int -> Int -> Int -> 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
This is free and unencumbered software released into the public domain. | |
Anyone is free to copy, modify, publish, use, compile, sell, or | |
distribute this software, either in source code form or as a compiled | |
binary, for any purpose, commercial or non-commercial, and by any | |
means. | |
In jurisdictions that recognize copyright laws, the author or authors | |
of this software dedicate any and all copyright interest in the | |
software to the public domain. We make this dedication for the benefit |
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
eval$s=%q(eval(%w(s=%(eval$s=%q(#{$s}));print(s);sleep(0.5); | |
q=9608.chr("utf-8");print("\e[?25l\e[1G\e[37m\e[23F");24.tim | |
es.each{puts(q*6 0)};w=->{sleep(0 .1)};w[];f=->(n,* as | |
){print(as.map { |a|"\e[#{a}"}* " "+q*n);w[];};pr i nt | |
("\e[2F\e[4 C\e [31m");14.t ime s{f[2,"1A"," 2D" ]; | |
};f[3,"1 F","2C "];f[3," 1F","5 C"];f[3," 1F","8 C" | |
];f[3 ,"1F","11 C"];f [2,"1F"," 14C"]; f[3,"1F", "1 | |
6C "];5.times{f [2 ,"1B","2D"]; }; f[4,"1B","2D" ]; | |
4. times{f[3,"1A "];};f[2,"1A"]; f[3,"1A"];5.time s{ | |
f[ 2,"1B","2D"];};f[4,"1B","2D"];4.times{f[3,"1A"];};f[ 2, |
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
eval$s=%w(s=%(eval$s=%w(#{$s})*"") | |
;f=->*a{m=1 ;puts(a. map{|n|( m | |
==0)?(m= 1; 32.ch r* n):(m =0 ; | |
s.sli ce!(0 ,n ))}.j oi n)};m = | |
1; f[34];f[ 11,2,8,2 ,8,2,m]; f | |
[8 ,2,2,m,5,2,2,m,5,2,2,m,m];f[5 , | |
2, 5,m,2,2,5, m,2 ,2, 5,m,m];f[2 , | |
2, 8,2,8,2,8,m ,m ]; f[2,m,29,m, m | |
]; f[2,m,10,m,3,m,3,m,10,m,m];f[ 2 | |
,m ,11,m,2,m, 2,m,10+ m,m,m];f[2 , |
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
extern crate rusty_machine; | |
extern crate rand; | |
extern crate gnuplot; | |
use rusty_machine::linalg::{Matrix, BaseMatrix}; | |
use rusty_machine::learning::k_means::KMeansClassifier; | |
use rusty_machine::learning::UnSupModel; | |
use rand::thread_rng; | |
use rand::distributions::IndependentSample; |
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
chunk :: (Eq b) => [a] -> (a -> b) -> [(b, [a])] | |
chunk [] _ = [] | |
chunk (x:xs) f = let fx = f x | |
(h, t) = span ((==) fx . f) xs | |
in [(fx,(x:h))] ++ chunk t f | |
data ChunkType = Word | Blank deriving (Show, Eq) |
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
nwSqrt :: Int -> Double | |
nwSqrt n = let s = sqrts $ fromIntegral n in | |
snd $ last $ takeWhile inThreshold $ zip s (tail s) | |
where | |
sqrts :: Double -> [Double] | |
sqrts n = 1.0:[x - (x ^ 2 - n) / (2 * x) | x <- sqrts n] | |
inThreshold :: (Double,Double) -> Bool | |
inThreshold (a,b) = abs (a - b) > 0.00000001 |
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 Text.Parsec | |
data Exp = And Exp Exp | Or Exp Exp | Not Exp | T | F deriving Show | |
expr :: Parsec String st Exp | |
expr = do | |
t <- term | |
Or t <$> (string "or" *> expr) <|> pure t | |
term :: Parsec String st Exp |
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 Control.Monad.Reader | |
data Config = Config { verbose :: Int, debug :: Bool } | |
configToLevel :: Config -> Int | |
configToLevel config | |
| debug config = 10 | |
| otherwise = verbose config |
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 Control.Applicative | |
hoge :: Int -> Int | |
hoge = (*) 2 | |
fuga :: Int -> Int | |
fuga = (+) 1 | |
piyo :: Int -> Int | |
piyo = (+) <$> hoge <*> fuga |
NewerOlder