Skip to content

Instantly share code, notes, and snippets.

View shintakezou's full-sized avatar

Mauro Panigada shintakezou

View GitHub Profile
@shintakezou
shintakezou / susi946.cpp
Last active November 25, 2017 14:45
Solving "Quesito con la Susi n. 946"
/* This trivially solves a quiz on the Italian magazine
"La Settimana Enigmistica", namely
"Quesito con la Susi n. 946".
It uses, without any special reason, >C++11
features.
Problem:
There are four friends (Giovanni, Marco, Simone, Elisa)
sat down behind a desk; Susi must say who's the shortest
@shintakezou
shintakezou / susi946b.cpp
Created November 25, 2017 14:46
This is like another gist (https://gist.github.com/shintakezou/aab5d6c3a76689a6370ab6477f8cff2e) but it uses more lambdas...
/* This trivially solves a quiz on the Italian magazine
"La Settimana Enigmistica", namely
"Quesito con la Susi n. 946".
It uses, without any special reason, >C++11
features.
Problem:
There are four friends (Giovanni, Marco, Simone, Elisa)
sat down behind a desk; Susi must say who's the shortest
@shintakezou
shintakezou / susi948.f03
Last active February 11, 2018 12:36
Bruteforcing towards the solution for "Quesito con la Susi n. 948" from an Italian magazine.
! Find the solution for the problem
! "Quesito con la Susi n. 948"
! from Italian magazine "La Settimana Enigmistica".
! Brute force, as usual.
!
! Find
! n = 3*y0 + y1 + y2 + y3 + y4 + y5 + y6
! so that
! y(i) is between 4 and 10 included
! (hence n is between 36 and 90 included)
@shintakezou
shintakezou / test-json-p6-grammar.p6
Last active November 7, 2018 17:39
My first attempt to write and use Perl6 grammars; it seems to work (but it isn't tested extensively)
use v6.c;
# based on my original attempt, enhanced with protos
# and ideas from https://github.com/moritz/json
grammar JSON-Grammar
{
token TOP { \s* <json-value> \s* }
proto token json-value { * }
@shintakezou
shintakezou / dynamic_dispatch.cpp
Created January 12, 2019 21:46
Dynamic overloading simple poc test (dynamic dispatching)
#include <iostream>
// likely you'd like to use this someway; instead, this code
// simply ignores and accepts memory leaks.
//#include <memory>
#include <string>
#include <stack>
#include <sstream>
@shintakezou
shintakezou / dyndis.hs
Created January 13, 2019 21:35
tests of "dynamic overloading" (or alike) in several languages
-- interpreter of + and .
data StackEl = Onum Integer | Ostr String
instance Show StackEl where
show (Onum a) = show a
show (Ostr s) = "\"" ++ s ++ "\""
plus (Onum a) (Onum b) = Onum $ a+b
plus (Onum a) (Ostr b) = Ostr $ (show a) ++ b
@shintakezou
shintakezou / elements.c
Created April 14, 2019 15:51
Couting unique elements, with a peculiar definition of equality.
#include "elements.h"
#include <stddef.h>
#include <stdbool.h>
static int compare(const element *a, const element *b)
{
if (a->e2 == b->e2)
return 0;
else if (a->e1 != b->e1)
@shintakezou
shintakezou / Element.cpp
Created April 14, 2019 16:22
Lambda used as nested functions.
#include "Element.hpp"
#include <vector>
#include <string>
size_t count_uniques(const std::vector<SElement> v)
{
size_t c = 0;
bool found;
@shintakezou
shintakezou / counter2.f03
Created April 14, 2019 16:50
Nested functions in Fortran (2003, 2008…)
module counter2
implicit none
type element
character(len=16) :: s
integer :: e1, e2
end type element
contains
function count_unique(s) result(c)
module Counter
(Element(..),
countUnique,
countUnique2) where
data Element = Element { s :: String,
e1 :: Int,
e2 :: Int } deriving (Show, Eq)