Skip to content

Instantly share code, notes, and snippets.

@pozorvlak
pozorvlak / gist:9c6fadd6b2afef2a83d51f4368474a8b
Created October 27, 2017 17:41
Closure weirdness in Perl
Updating a single variable in-place: closures get the new value because they fetch it from the lexical scope
$ cat closures.pl
my @closures;
for (my $i = 0; $i < 3; $i++) {
push @closures, sub { print "$i\n"; };
}
for my $fn (@closures) {
$fn->();
}
@pozorvlak
pozorvlak / gist:a5c145fcc9db72190d6163e4596636c7
Created March 12, 2025 10:50
Solutions to "grid of arithmetic operations" puzzle
# Results of solving a "grid of arithmetic operations" problem in MiniZinc,
# using Gecode 6.3.0 at -O5.
# Program listing at https://mathstodon.xyz/@pozorvlak/114148447412533853
v =
[| 2, 34, 4, 9, 30, 15
| 35, 11, 31, 6, 21, 28
| 5, 14, 10, 1, 16, 18
| 13, 20, 29, 23, 19, 7
| 33, 27, 8, 26, 3, 24