Skip to content

Instantly share code, notes, and snippets.

View salva's full-sized avatar

Salvador Fandiño salva

View GitHub Profile
@salva
salva / t4.pl
Created March 28, 2012 17:27
t4
#!/usr/bin/perl
use strict;
use warnings;
# my $tab = <<EOT;
# ------
# ------
# ------
# ------
@salva
salva / gist:b402c9ed3936b43c82fc
Last active August 29, 2015 14:10
Mi solution to Ovid puzzle...
use strict;
use warnings;
my @a = ( [ 'b', 'c', 'f' ],
[ 'a', 'd' ],
[ 'c', 'd', 'e' ] );
my $last_ix = -1;
my %ixs;
@salva
salva / interactive-session.prolog
Last active May 5, 2016 20:37
Michał Wojciechowski's puzzle (blogs.perl.org/users/michal_wojciechowski/2016/05/brutally-solving-a-logic-puzzle-with-perl-6.html)
$ swipl
?- ["puzzle.prolog"].
true.
?- S = [_, 3, 17, 5, _, _, 13, _, 7], puzzle(S, O).
S = [41, 3, 17, 5, 23, 19, 13, 11, 7],
O = [61, 47, 31, 59, 37, 43, 71, 53, 541] ;
S = [11, 3, 17, 5, 41, 37, 13, 23, 7],
O = [31, 83, 43, 29, 67, 61, 59, 71, 601] ;
#!/usr/bin/perl
use strict;
use warnings;
my $n = shift;
my $start = int($n / 2 + 1);
my @play = (($start..$n), (1..($start - 1)));
while ($n > 1) {
#!/usr/bin/perl
use strict;
use warnings;
my $n = shift;
my @offsets;
my $offset = 2 - ($n & 1);
my $size = $n;
#include <stdio.h>
#include <stdlib.h>
int main(int argc, char **argv) {
int n = atoi(argv[1]);
int half = n / 2;
int i, j;
int *a = malloc(n * sizeof(int));
for (j = 0, i = half; i < n ; i++, j++) a[j] = i;