Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@timo
timo / shlomifish_euler_287.nqp
Created June 3, 2018 01:59
nqp and perl6 optimized versions of shlomi fish's (rindolf's) euler 287 solution.
#!/usr/bin/env perl6
# The Expat License
#
# Copyright (c) 2018, Shlomi Fish
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
#!/usr/bin/env perl6
# inspired by https://narimiran.github.io/2018/05/10/python-numpy-nim.html
use nqp;
constant N = 10_000;
constant sigma = 0.1e0;
constant f = (2 / N).Num;
constant mu = 0.001e0;
@timo
timo / result.txt
Created September 8, 2017 11:05 — forked from Skarsnik/result.txt
timo@schmand /tmp> perl6 --profile=heap testshellmem.p6 shell
Before shell call : 101.664 kb
html is 230457 chars
After shell call : 210.332 kb
After forced gc: 249.704 kb
html is 230457 chars
After shell call : 323.016 kb
After forced gc: 354.232 kb
html is 230457 chars
After shell call : 401.640 kb
@timo
timo / trace_spesh_optimize.gdb
Created June 28, 2017 14:55
make a spesh dump after every step of optimization, check 'em all into git, display a log with diffs afterwards
define trace_spesh_optimize
dont-repeat
python
import tempfile
import os
import gdb
spesh_trace_target_folder = tempfile.mkdtemp("", "moar-spesh-trace")
spesh_trace_target_file = os.path.join(spesh_trace_target_folder, "speshdump.txt")
os.system("git init " + spesh_trace_target_folder)
grammar g{
token garble {<[2]>};
token alpha1 {<[2]>};
token beta { <[q]> };
token delta {<+garble +beta>};
token delta1 {<+garble>};
token delta2 {<+alpha1 +beta>}
}
say so "2" ~~ /<g::delta1>/; # OK
say so "2" ~~ /<g::delta2>/; # OK
@timo
timo / cwr.p6
Last active August 18, 2016 23:18 — forked from ahalbert/cwr.p6
use v6;
use Test;
sub combinations_with_replacement(@iterable, $r) {
gather {
cwr(@iterable, [], $r);
}
}
sub cwr(@iterable, @state, $r) {
my $place = @state.elems;
# this is my solution to GRAPH.
# it offers an interactive mode and some test cases
use v6;
class Graph {
has @!nodes;
has %!neighbour;
method connect($a, $b) {
@timo
timo / 01_notable_holes.c
Created March 30, 2016 00:34
partial pahole output for MoarVM's libmoar.so
struct MVMCompUnitBody {
MVMuint8 * data_start; /* 0 8 */
MVMuint32 data_size; /* 8 4 */
/* XXX 4 bytes hole, try to pack */
MVMObject * * coderefs; /* 16 8 */
MVMuint32 num_frames; /* 24 4 */
MVMuint32 orig_frames; /* 28 4 */
MVMStaticFrame * main_frame; /* 32 8 */
#!perl6
use NativeCall;
my $samplerate = 44100;
my $frequency = 440;
sub gen-sin(Int $sample-rate, Int $frequency) {
my num $spf = $sample-rate.Num / $frequency.Num;
my num $twopi = (2 * pi).Num;
@timo
timo / gist:0b64637e8b7bda922bea
Created August 15, 2015 01:40
on the glr branch of rakudo, this "use trace" causes the .say to not happen .. or something.
# remove this to get an output from this again.
use trace;
do {
# putting a "use trace" into this block will
# give a trace as well as the expected results
#use trace;
.say for <hello how are you>;