-
-
Save ear/e299784e57e3e75ac9c8460f0ccbedcc to your computer and use it in GitHub Desktop.
min (unif(0,1),unif(0,1)) ~~ ??
This file contains hidden or 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 Data.List (splitAt, foldl') | |
import Control.Monad (forM_) | |
import System.Random (randomRs, getStdGen) | |
import System.Environment (getArgs) | |
import qualified Data.Map.Strict as M | |
main = do | |
[size, digits, columns] <- map read <$> getArgs :: IO [Int] | |
rs <- take (size*2) <$> (randomRs (0,1) <$> getStdGen) :: IO [Double] | |
let (xs,ys) = splitAt size rs | |
zs = map (truncate . (* (fromIntegral digits))) (zipWith min xs ys) | |
cs = foldl' (\m x -> M.insertWith (const succ) x 1 m) (M.fromList []) zs | |
cols count = round $ (fromIntegral count) / (fromIntegral $ maximum $ M.elems cs) * (fromIntegral columns) | |
forM_ (M.toList cs) $ \(v,count) -> | |
putStrLn $ show v ++ " " ++ replicate (cols count) '*' | |
-------- | |
$ ./A 10000 30 100 | |
0 **************************************************************************************************** | |
1 **************************************************************************************************** | |
2 ********************************************************************************************** | |
3 *************************************************************************************** | |
4 ************************************************************************************ | |
5 ********************************************************************************** | |
6 ********************************************************************************* | |
7 *********************************************************************** | |
8 ************************************************************************* | |
9 ****************************************************************** | |
10 *************************************************************** | |
11 ***************************************************************** | |
12 ***************************************************** | |
13 ***************************************************** | |
14 **************************************************** | |
15 *************************************************** | |
16 ********************************************** | |
17 ****************************************** | |
18 ****************************************** | |
19 ******************************** | |
20 ******************************* | |
21 **************************** | |
22 ************************ | |
23 *********************** | |
24 ******************* | |
25 ***************** | |
26 ********** | |
27 ********* | |
28 **** | |
29 ** |
This file contains hidden or 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
$ time ./A 1000000 30 100 | |
0 **************************************************************************************************** | |
1 ************************************************************************************************* | |
2 ********************************************************************************************** | |
3 ****************************************************************************************** | |
4 *************************************************************************************** | |
5 *********************************************************************************** | |
6 ******************************************************************************** | |
7 ***************************************************************************** | |
8 ************************************************************************* | |
9 ********************************************************************* | |
10 ******************************************************************* | |
11 ************************************************************** | |
12 ************************************************************ | |
13 ******************************************************** | |
14 ***************************************************** | |
15 ************************************************** | |
16 *********************************************** | |
17 ****************************************** | |
18 *************************************** | |
19 ************************************ | |
20 ******************************** | |
21 ***************************** | |
22 ************************* | |
23 ********************** | |
24 ******************* | |
25 *************** | |
26 ************ | |
27 ******** | |
28 ***** | |
29 ** | |
real 0m3.824s | |
user 0m3.280s | |
sys 0m0.227s |
This file contains hidden or 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
$ time ./A 10000000 30 100 | |
0 **************************************************************************************************** | |
1 ************************************************************************************************* | |
2 ********************************************************************************************* | |
3 ****************************************************************************************** | |
4 *************************************************************************************** | |
5 *********************************************************************************** | |
6 ******************************************************************************** | |
7 **************************************************************************** | |
8 ************************************************************************* | |
9 ********************************************************************** | |
10 ****************************************************************** | |
11 *************************************************************** | |
12 *********************************************************** | |
13 ******************************************************** | |
14 ***************************************************** | |
15 ************************************************* | |
16 ********************************************** | |
17 ****************************************** | |
18 *************************************** | |
19 ************************************ | |
20 ******************************** | |
21 ***************************** | |
22 ************************** | |
23 ********************** | |
24 ******************* | |
25 *************** | |
26 ************ | |
27 ******** | |
28 ***** | |
29 ** | |
real 0m39.969s | |
user 0m35.027s | |
sys 0m2.142s |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment