Skip to content

Instantly share code, notes, and snippets.

View ilpropheta's full-sized avatar

Marco Arena ilpropheta

View GitHub Profile
Verifying that "marena.id" is my Blockstack ID. https://onename.com/marena
@ilpropheta
ilpropheta / Grade Compact Calculation.cpp
Last active February 15, 2016 08:14
Replacing if-cascade on numerical ranges with 3-LOC (using vector + upper_bound)
#include <algorithm>
#include <iostream>
#include <vector>
using namespace std;
/*
Just for fun: equivalent to:
if (score < 40)
// my solution for: http://www.geeksforgeeks.org/check-if-a-given-number-is-fancy/
// Precondition: i only contains digit chars
bool is_fancy(const string& i)
{
static const map<char, char> toFancy{
{'0', '0'}, {'1', '1'},
{'6', '9'}, {'8', '8'}, {'9', '6'},
{'2', 0}, {'3', 0}, {'4', 0}, {'5', 0}, {'7', 0},
};
// canonical way
template<typename MapType>
auto map_vals(const MapType& m)
{
vector<typename MapType::mapped_type> res;
res.reserve(m.size());
transform(begin(m), end(m), back_inserter(res), [](const auto& p) {
return p.second;
});
return res;
#include <iostream>
#include <type_traits>
#include <string>
using namespace std;
// PACK UTILS (TAG VERSION) =============================
/* find type T in a pack (recursive)
This is used to find a TAG
#include <random>
#include <iostream>
namespace boost
{
namespace mario
{
enum class Mano
{
Piuma=0, Fero=1