Skip to content

Instantly share code, notes, and snippets.

View shoooe's full-sized avatar
🏓

Thomas Pigarelli shoooe

🏓
View GitHub Profile
@shoooe
shoooe / a8.cpp
Created April 30, 2015 06:54
Some random corrector which, given a dictionary file with "<word> <frequency>" space separated pairs and fed with a word, returns the closest word of distance 1 with the highest frequency.
#include <iostream>
#include <fstream>
#include <map>
#include <stdexcept>
#include <vector>
namespace a8 {
// aliases
using word = std::string;
@shoooe
shoooe / ngrams.hs
Created April 16, 2015 23:02
N-grams!
groupEvery :: Int -> [a] -> [[a]]
groupEvery n lst
| length lst < n = []
| otherwise = take n lst : groupEvery n (tail lst)
ngrams :: Int -> String -> [String]
ngrams n = concatMap (groupEvery n . fillWord '_') . words
where fillWord f w = f : (w ++ replicate (n - 1) f)
main :: IO ()
@shoooe
shoooe / PuzzleGenerator.hs
Last active August 29, 2015 14:10
A generator for a puzzle exercise given by the teacher in my Uni, created to generate test data to check your solution.
module Main where
import Prelude hiding (id)
import Data.List (intersperse)
import System.Random
import Control.Applicative
type PieceId = String
type PieceContent = Char
@shoooe
shoooe / ExampleInput.txt
Last active August 29, 2015 14:10
Exercise that I should have done in Java, but I decided to do in 100 lines of Haskell.
0 A VUOTO 1 2 VUOTO
1 B VUOTO VUOTO 3 0
2 C 0 3 VUOTO VUOTO
3 D 1 VUOTO VUOTO 2
@shoooe
shoooe / perms.hs
Last active August 29, 2015 14:09
Some exercise with Haskell
-- Original question can be found here:
-- http://www.reddit.com/r/haskell/comments/2lq8dt/produce_infinite_list_with_a_string/
permWithRep :: Int -> [a] -> [[a]]
permWithRep = replicateM
allSets :: String -> [[String]]
allSets str = map (flip permWithRep $ str) [0..]
main :: IO ()
import Data.Char (toLower)
isPangram :: String -> Bool
isPangram s =
let ls = map (toLower) s
in null . filter (not . (`elem` ls)) $ ['a'..'z']
main :: IO ()
main = do
s <- getLine
@shoooe
shoooe / at_least_two_equal_digits.hs
Created June 29, 2014 14:24
Simple program that calculates the number of possible phone numbers of length 4 that have 2 or more equal digits, and displays them.
import Data.Map (Map)
import qualified Data.Map as Map
countDistinct :: Ord a => [a] -> Int
countDistinct = Map.size . foldr fn Map.empty
where fn e = Map.insertWith (+) e 1
validStrings :: [String]
validStrings =
filter ((`elem` [1..3]) . countDistinct) $ do
@shoooe
shoooe / matrix_fun.hs
Last active August 29, 2015 14:03
Some fun with matrices.
data Matrix a
= Matrix (Int, Int) [[a]]
deriving (Eq, Show)
rowIndexes :: Matrix a -> [Int]
rowIndexes (Matrix (_, y) _) = [0..y - 1]
colIndexes :: Matrix a -> [Int]
colIndexes (Matrix (x, _) _) = [0..x - 1]

####Recurrent Standard C++ quotes

This is a list of quotes from the C++ standard that are often useful while answering questions on StackOverflow. Feel free to suggest quotes that should be added.

The following quotes refer to the N3936 draft (~C++14).


§1.9/15 Program execution [intro.execution]

Except where noted, evaluations of operands of individual operators and of subexpressions of individual expressions are unsequenced. [ Note: In an expression that is evaluated more than once during the execution of a program, unsequenced and indeterminately sequenced evaluations of its subexpressions need not be performed consistently in different evaluations. — end note ] The value computations of the operands of an operator are sequenced before the value computation of the result of the operator. If a side effect on a scalar object is unsequenced relative to either another side effect on the same scalar object or a value computatio