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
using BenchmarkTools | |
macro fast_instance_iteration(_instance::Symbol) | |
local outer_instance = getfield(@__MODULE__, _instance) | |
local dispatch_on_instance = Val{outer_instance} | |
local base_type = typeof(outer_instance) | |
local field_values = [getfield(outer_instance, field) for field in fieldnames(base_type)] | |
local num_fields = length(field_values) | |
local id = rand() |
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> function dg()::Int | |
N = 200000 | |
nheads::Int = @distributed (+) for i = 1:N | |
Int(rand(Bool)) | |
end | |
return nheads | |
end | |
dg (generic function with 1 method) | |
julia> @code_warntype dg() |
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
using BenchmarkTools | |
NUCLEOTIDES = collect("ACGT") | |
function build_countnuc(nucleotides) | |
prog = "vec -> (freqtable = fill(0, $(length(nucleotides)));\n" | |
prog *= "for n in vec\n" | |
prog *= "if n == '$(nucleotides[1])'\n freqtable[1] += 1\n" | |
for (i, nuc) in enumerate(nucleotides[2: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
julia> io = IOBuffer("JuliaLang"); | |
julia> string(io.data) | |
"UInt8[0x4a, 0x75, 0x6c, 0x69, 0x61, 0x4c, 0x61, 0x6e, 0x67]" | |
julia> string(io.data) | |
"UInt8[0x4a, 0x75, 0x6c, 0x69, 0x61, 0x4c, 0x61, 0x6e, 0x67]" | |
julia> String(io.data) | |
"JuliaLang" |
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
bo9bo6bo19bo12bo27bo9bo8bo13bo9bobobo6bo7bo3bo4bo8bo29bo7bo2bo9bobo14bo3bob2o6bo15bo3bo3bo13bo13bo5bo35bo20bo4b2o9bo14bo14bo9bobo44bo6bo9b2o10bo30bo7bo49bo$8bo19bo9b2obo3bo31bo45bo3bo6bo33bo3bo5bo6b2o6bobo14bo3bo10bo10bo4bo16bo26bobo13bo7bobo18bo13bo21bo86bo14bo15bo4bo5bobo3bo17bo7bo5bo21bo5b2o6bo10bo8bo5bo$4bo5bo8bo20bo3bobo2bo5bo3bo4bobo18bo2bo5bo18bo7bo4bo2bo14bo5bo25bo3bo3bo12bob2o8b2obo5bo4bobo2bo26bo2bo17bobo9bo15bo11b3o22bo23b2o10bo11bo29bo2bobo4bobo4bo3bo14bo2bo58bo2bo16bo6bo6bo8bo22bo5bo$3bo21b2o4bo10bobo13bob2o14bo6bo14bo2bo3bo13bo3bo12b2o2bo3bo12bo19bo2bo17b2obo4bo16bo2bobobo14bo20bo6bo4bo11bo4bo20bo4bobo3bo16bo34bo9bo6bo20bo5bobo20bo10bob2o17bo5bo39bo7bo4bo5bo25bo27bo$8bo2bo25bo10bo10bo2bo10bo5bo8bo3bo4bo11bo42bo19bobo19bo13bo6bobo14bo5bo5bo2bo4bo11bo18bo2b2o5bo10bo19bo6bo3bo7bo5b2o33bo5bo19bo20bo9bo15bo7bo24bo4bo11bob3o2b2o10bo2b2o8bobo5bo7bo18bo9bo2bo$20bo3bo4bo27bo16bo41bo16bo17bo19bo2bo9bo6bo5bo5bo11b2ob2o13bo4bo2bo7bo20bo2bobo11b2o8bo4bo4bo4bo2bo4bo8bo8b2o4bo5bo11bo11bo8bo7bo2b2o40bo35bo23bo2 |
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> using PyCall | |
julia> py""" | |
def pysum(lx, ly): | |
return sum(x*y for x in range(1,lx+1) for y in range(1,ly+1,3)) | |
""" | |
julia> jlsum(lx, ly) = sum(x*y for x in 1:lx for y in 1:3:ly) | |
jlsum (generic function with 2 methods) |
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
from collections import Counter | |
def stonesForCrown(stones): | |
c = Counter(stones) | |
num = 0 | |
val = 0 | |
l = sorted(c.items(), key = lambda x:(x[1], x[0]), reverse=True) | |
for x in l: | |
if num != x[1]: | |
num = x[1] |
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
import sys | |
import random | |
def parse_input(): | |
lines = [line for line in sys.stdin] | |
ly, lx = int(lines[0]), int(lines[1]) | |
board = [] | |
for y in range(ly): | |
line = "".join(l for l in lines[y+2] if l in ["p", "P", " "]) |
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
def P(X): | |
""" | |
X is P, if it auto-satisfate itself | |
""" | |
return X(X) | |
def V(X): | |
""" | |
X is V, if X is a property | |
""" |
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
function factorial(num) { | |
var fact = 1; | |
for(var i=2; i<=num; i++) { | |
fact *= i; | |
} | |
return fact; | |
} | |
function getReps(str) { | |
var sortedLetters = str.split("").sort(); |
NewerOlder