This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env perl | |
for (my $N=<>; $N; $N--){ | |
$_ = ""; | |
for (my $L=<>; $L; $L--) { | |
$_ .= <>; | |
} | |
for (my $L=<>; $L; $L--) { | |
my ($n, $r) = split(' ', <>); | |
s/($r( |$){$n}/\1/gm; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env perl | |
<>; | |
foreach(<>){ | |
s/(ij|[aeiou]+)p\1/\1/ig; | |
print; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env julia | |
using CRC | |
# crc computing function | |
const handler = crc(CRC_32) | |
# offsets of IDAT chunks (points to 'I' byte) | |
const offsets = [114,131197,262278,393361,524445,655526,786609,917691,1048775,1179858,1188429] | |
# correct crcs. No 0x0a in those so we can assume they're correct ;) | |
const crcs = [0xf55a745d, 0x06e15ebf, 0xa0bdc18a, 0xadefb326, 0x09c557f7, |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env julia | |
# Adapted from https://github.com/pablocelayes/rsa-wiener-attack | |
using ContinuedFractions # Note: this needs my fork of ContinuedFractions.jl | |
# fast perfect square test (from project euler tools) | |
# returns -1 if n is not a perfect square | |
function perfect_square(n::Integer) | |
h = n & 0xF # last four bits |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env julia | |
const ENTROPY_MAP_2D = open("entropy.csv") do f | |
readdlm(f, ',') | |
end | |
# Returns index 1:26 for a-z, 27 for space | |
function get_index_for(ch) | |
if 'a' <= ch <= 'z' | |
return int(ch - 96) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env julia | |
# Peano arithmetic (https://en.wikipedia.org/wiki/Peano_axioms) | |
abstract Natural <: Integer | |
immutable Zero <: Natural end | |
immutable Successor{P<:Natural} <: Natural end | |
# Define a total order relation | |
<(::Type{Zero}, ::Type{Zero}) = false | |
<{P<:Natural}(::Type{Zero}, ::Type{Successor{P}}) = true |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
julia> code_llvm(g, (Int,)) | |
define i64 @julia_g_20191(i64) { | |
top: | |
%1 = icmp sgt i64 %0, 0, !dbg !8 | |
br i1 %1, label %L.preheader, label %L3, !dbg !8 | |
L.preheader: ; preds = %top | |
%2 = add i64 %0, -1, !dbg !8 | |
%3 = zext i64 %2 to i65 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
# encoding: utf-8 | |
""" | |
Usage: | |
rlwrap ./srs_test.py | |
""" | |
import os |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
chunks(l::AbstractVector, n::Int) = let part_l = length(l) / n | |
[let start = floor(Int, (i-1)*part_l + 1), stop = floor(Int, i*part_l); | |
l[start:stop] end for i in 1:n] | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
fn isqrt(n: usize) -> usize { | |
n == 0 && return n; | |
let mut s = (n as f64).sqrt() as usize; | |
s = (s + n / s) >> 1; | |
if s * s > n { s - 1 } else { s } | |
} | |
fn perfect_sqrt(n: usize) -> isize { | |
match n & 0xf { | |
0 | 1 | 4 | 9 => { |
OlderNewer