Last active
August 29, 2015 14:10
-
-
Save m-renaud/0c767f1ca8605d66391c to your computer and use it in GitHub Desktop.
Int parsing and simple operation
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
// Compile with: g++ --std=c++11 -O3 | |
#include <algorithm> | |
#include <iostream> | |
#include <iterator> | |
#include <vector> | |
int main() { | |
std::ios_base::sync_with_stdio(false); | |
std::vector<long int> v ( | |
std::istream_iterator<long int>(std::cin), | |
std::istream_iterator<long int>() | |
); | |
std::cout << v.size() << std::endl; | |
} |
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
{-# LANGUAGE BangPatterns #-} | |
{-# OPTIONS_GHC -Odph #-} | |
import qualified Data.ByteString.Char8 as S | |
import qualified Data.Vector as U | |
-- Read ints from stdin into a vector then print the length. | |
main = S.getContents >>= print . U.length . parse | |
-- Fill a new vector from a file containing a list of numbers. | |
parse = U.unfoldr step | |
where | |
step !s = case S.readInt s of | |
Nothing -> Nothing | |
Just (!k, !t) -> Just (k, S.tail t) |
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 Control.Monad | |
import Data.Functor | |
import System.Random | |
main = do | |
n <- readLn :: IO Int | |
rs <- randomRs (1, maxBound) <$> newStdGen :: IO [Int] | |
forM_ (take n rs) print |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment