Skip to content

Instantly share code, notes, and snippets.

/* Zoek een 9-letterige string van die enkel volgende letters mag bevatten: "acdegilmnoprstuw" zodat de hash(de_string) hetvolgende is "910897038977002".
* if hash is defined by the following pseudo-code:
* Int64 hash (String s) { Int64 h = 7 String letters = "acdegilmnoprstuw" for(Int32 i = 0; i < s.length; i++) { h = (h * 37 + letters.indexOf(s[i])) } return h }
* For example, if we were trying to find the 7 letter string where hash(the_string) was 680131659347, the answer would be "leepadg".)
*/
void Main()
{
new []
{
680131659347, // leepadg
@kboga
kboga / gist:2890446
Created June 7, 2012 17:58
speed comparison
NQP (master)
real 3m18.296s
user 2m52.579s
sys 0m6.636s
real 3m4.194s
user 2m51.095s
sys 0m6.856s
RAKUDO
@kboga
kboga / gist:2890186
Created June 7, 2012 17:24
slurpy subrules?
my grammar G {
method s_m(*%n) { say(%n<a b c>) }
token TOP { <s_m(|{:a<1>, :c<3>}, :b<2>)> }
}
G.s_m(|{:a<1>, :c<3>}, :b<2>);
G.parse('');
@kboga
kboga / altnfa test run
Created June 6, 2012 23:07
altnfa (nqp test & rakudo spectest)with ICU
t/qregex/01-qregex.t .. Failed 3/706 subtests
Test Summary Report
-------------------
t/qregex/01-qregex.t (Wstat: 0 Tests: 706 Failed: 3)
Failed tests: 18-19, 290
Files=1, Tests=706, 18 wallclock secs ( 0.26 usr 0.01 sys + 17.02 cusr 0.40 csys = 17.69 CPU)
Result: FAIL
not ok 18 - alt subpattern in group
@kboga
kboga / gist:1129444
Created August 6, 2011 15:42
Patch to match for Numification of Match objects
diff --git a/src/core/Match.pm b/src/core/Match.pm
index ffb0ae3..eb7a800 100644
--- a/src/core/Match.pm
+++ b/src/core/Match.pm
@@ -7,6 +7,9 @@ my class Match is Capture {
multi method Str(Match:D:) {
$!to > $!from ?? $!orig.substr($!from, $!to-$!from) !! '';
}
+ method Numeric(Match:D:) {
+ self.Str.Numeric;