Skip to content

Instantly share code, notes, and snippets.

View shintakezou's full-sized avatar

Mauro Panigada shintakezou

View GitHub Profile
@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 / 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 / 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 / generic.f90
Last active August 7, 2018 18:51
Type-generic functions' example in Fortran90
program generic_example
use my_sum_module
implicit none
print *, my_sum(1.0, 3.0) ! 1 + 1.5
print *, my_sum(1, 5) ! 1 + 2
print *, my_sum(2, 3.0) ! 2 + 1.5
print *, my_sum(1.5, 7) ! 1.5 + 3.5
@shintakezou
shintakezou / generic.c
Last active March 9, 2017 18:27
C11 _Generic basic test
#include <stdio.h>
typedef struct {
double x;
double y;
} vec2d;
#define sum(X, Y) _Generic((X), \
int: sum2l((X), (Y)), \
long: sum2l((X), (Y)), \
@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 / 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 / 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 {
package main
import (
io "bufio"
"fmt"
"os"
"sync"
"unicode"
)
@shintakezou
shintakezou / coroutine-x86.asm
Created May 10, 2014 22:56
Coroutines example in x86
extern printf
extern getchar
extern isalpha
section .data