Skip to content

Instantly share code, notes, and snippets.

View shintakezou's full-sized avatar

Mauro Panigada shintakezou

View GitHub Profile
@shintakezou
shintakezou / transform.cpp
Created April 24, 2012 16:40
"Array map" in C++11
#include <iostream>
#include <algorithm>
#include <vector>
using namespace std;
int main() {
vector<string> vet {"hello", "world", "take", "the", "moon"};
vector<string>::iterator it;
@shintakezou
shintakezou / check01.c
Created January 15, 2014 18:20
Check if a 32bit number decimal representation is made of 0 or 1 digits only.
/*
See StackOverflow
http://stackoverflow.com/questions/21137812/check-to-see-if-integer-is-one-in-which-each-digit-is-either-a-zero-or-a-one
to know why this exists. Do not take it seriously: the other answers show the way!
*/
#include <stdio.h>
#include <stdbool.h>
#include <inttypes.h>
#include <limits.h>
@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
@shintakezou
shintakezou / coroutine-x86.asm
Created May 10, 2014 22:56
Coroutines example in x86
extern printf
extern getchar
extern isalpha
section .data
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 / 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)), \