Skip to content

Instantly share code, notes, and snippets.

View shintakezou's full-sized avatar

Mauro Panigada shintakezou

View GitHub Profile
@shintakezou
shintakezou / mcalcpp.yy
Last active August 29, 2015 13:59
Bison Calc Test 1 (single file)
/*
bison test 1 (single file),
widely based on examples in the bison manual at
http://www.gnu.org/software/bison/manual/
It should compile with
$ bison mcalcpp.yy
$ g++ mcalcpp.tab.cc
or alike. (bison v>3.0; any C++98 compiler should go)
*/
@shintakezou
shintakezou / amigaos-coroutines.asm
Created May 10, 2014 10:47
Simple coroutines example in m68k (on AmigaOS)
incdir "include:"
include "exec/exec.i"
include "exec/exec_lib.i"
include "dos/dos_lib.i"
opt p=68020
_start
package main
import (
io "bufio"
"fmt"
"os"
"sync"
"unicode"
)
@shintakezou
shintakezou / gist:88188591a1a856def7c4
Created December 23, 2014 11:26
Producer/Consumer with just a single goroutine
package main
import (
io "bufio"
"fmt"
"os"
"unicode"
)
type ControlFlow struct {
@shintakezou
shintakezou / quesito_susi.prolog
Created January 3, 2015 15:44
This shows how to solve a simple problem on an italian quiz magazine.
% gprolog: nth
% swi prolog: nth0
vicino(List, A, B) :-
nth(IndexA, List, A),
nth(IndexB, List, B),
abs(IndexA - IndexB) =:= 1.
chi(Luca, Aldo, Berto) :-
vicino([4, 0, 2, 1, 3], Luca, Aldo),
vicino([1, 2, 3, 0, 4], Berto, Aldo),
@shintakezou
shintakezou / susi923.hs
Last active August 29, 2015 14:17
answer a puzzle (A problem for Susi) on an italian magazine
{-
This code answers to "Un quesito con la Susi n. 923"
(a puzzle on an italian magazine).
Brute force, no optimization (and no Haskell guru here).
-}
import Data.List
checkSol :: [Int] -> Bool
checkSol a =
5*susi == gianni && (sum a) == (susi + gianni + tavolo)
@shintakezou
shintakezou / dudeney_miller.cpp
Last active August 29, 2015 14:26
This code solves Dudeney's "The Miller's puzzle"
/*
this code solves one of the Dudeney's Canterbury Puzzles,
namely The Miller's Puzzle.
My input was an italian blog, i.e.
http://rudimatematici-lescienze.blogautore.espresso.repubblica.it/2015/06/07/lenigma-del-mugnaio/
But you can find all the puzzles (thus even the miller's puzzle)
here:
@shintakezou
shintakezou / susi927.py
Last active September 13, 2015 17:05
Python(3) code to sieve solution(s) for “A quiz with Susi” n. 927
#! /usr/bin/python3
#
# italian magazine "La Settimana Enigmistica",
# quiz "Quesito con la Susi" n. 927
#
# R, B, S: prices of one bottle of red, white and sparkling wine
# a, b, c: number of sparkling (a), white (b) and red (c) wine in a
# box of seven bottles
#
# R = 3B
@shintakezou
shintakezou / susi927bis.py
Last active September 26, 2015 10:43
Solve Susi's puzzle n. 927 using logilab.constraint
#! /usr/bin/python
#
# see https://gist.github.com/shintakezou/666a96e63b0c01be2f78#file-susi927-py
# The problem is the same, but here we use logilab.constraint
# https://www.logilab.org/project/logilab-constraint
# and of course we take into account the fact that prices are integer
# positive numbers.
#
from logilab.constraint import *
@shintakezou
shintakezou / lambdacpp11.cpp
Created March 30, 2012 21:16
lambda in C++11
#include <iostream>
#include <numeric>
#include <vector>
using namespace std;
int main()
{
vector<int> array = {1, 2, 3, 4, 5};