Skip to content

Instantly share code, notes, and snippets.

@m-renaud
Last active August 29, 2015 14:10
Show Gist options
  • Save m-renaud/0c767f1ca8605d66391c to your computer and use it in GitHub Desktop.
Save m-renaud/0c767f1ca8605d66391c to your computer and use it in GitHub Desktop.
Int parsing and simple operation
// 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;
}
{-# 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)
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