Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

View shoooe's full-sized avatar
🏓

Thomas Pigarelli shoooe

🏓
View GitHub Profile

Keybase proof

I hereby claim:

  • I am shoooe on github.
  • I am tpigarelli (https://keybase.io/tpigarelli) on keybase.
  • I have a public key ASCbdD34wOQtajdGmowxTw6Vce6Ce5CKBsPf926SpZ0tMwo

To claim this, I am signing this object:

#include <iostream>
#include <memory>
#include <cassert>
enum class node_color {
red,
black
};
template<typename DataType>

Why is the codomain useful?

In set theory we have that a domain is the set of all inputs for which a function is defined and the image is the set of possible outputs given those inputs. You would think this would be enough, but no: we also have the concept of codomain, which is the set of all possible outputs and some.

This also leads to the distinction between "surjective" functions and non-"surjective" functions (functions that have the image being equal to the codomain and those that don't, respectively). This distinction seems to provide no useful information about the function itself.

Now, let's make an example, we have:

ƒ : {a, b, c, d} -> {1, 2, 3, 4}

ƒ a = 1

namespace detail {
template<typename It>
It partition(It begin, It end) {
if (begin == end) return end;
auto pivot = *(end - 1);
auto left = begin; // left partion past the end
for (auto right = begin; right != end; ++right) {
if (*right <= pivot) {
std::iter_swap(left, right);
@shoooe
shoooe / filetoobig.md
Last active May 9, 2021 12:34
The asymmetries of C++

The asymmetries of C++

This is lighthearted collection of asymmetries of the C++ language. This is not, in any way, intended as a critic.


Partial specialization is allowed for class templates but not for function templates

§14.5.5 [temp.class.spec] describes the semantic and syntax for class template partial specialization such as, given:

@shoooe
shoooe / equal100.hs
Last active August 29, 2015 14:20
Solution to the fifth problem found here: https://goo.gl/eEyf9x, because it took longer than it should have.
-- Write a program that outputs all possibilities to put + or - or nothing
-- between the numbers 1, 2, ..., 9 (in this order) such that the result is
-- always 100. For example: 1 + 2 + 34 – 5 + 67 – 8 + 9 = 100.
import Control.Monad (replicateM)
ints :: [String]
ints = map (\i -> [i]) ['1'..'9']
inbetweens :: [[String]]
type alias Unit = Float
type Vec2 = Vec2 Unit Unit
(|+|) : Vec2 -> Vec2 -> Vec2
(Vec2 ax ay) |+| (Vec2 bx by) = Vec2 (ax + bx) (ay + by)
negate : Vec2 -> Vec2
negate (Vec2 x y) = Vec2 (-x) (-y)
(|-|) : Vec2 -> Vec2 -> Vec2
@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