This file contains hidden or 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
# if you know what Blue Prince is but don't know what numerical cores are, don't worry about it | |
# not particularly optimized, but certainly fast enough | |
# please comment with a test case if there are bugs | |
using Combinatorics | |
const OPERATOR_OPTIONS = map(Tuple, permutations((-,*,/))) |
This file contains hidden or 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 tally(n=100) | |
snake_eyes = 0 | |
any_ones = 0 | |
for i in 1:n | |
rolls = (dice_roll(), dice_roll()) | |
if 1 in rolls # tests at least one of them is a one | |
any_ones += 1 | |
if rolls[1] == rolls[2] # tests both are one |
This file contains hidden or 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 --startup-file=no --history-file=no -e 'import REPL; print( | |
let SYMBOLS = REPL.REPLCompletions.latex_symbols | |
get(SYMBOLS, "\\\$(ARGS[1])") do | |
SYMBOLS["\\text$(ARGS[1])"] | |
end | |
end | |
)' Sigma |
This file contains hidden or 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
# Originally written to work with InlineString in WeakRefStrings, this should work for any primitive type | |
# In most cases, the built-in defaults provided by Julia work fine, using `read` and `write`. | |
# However, if your `read` and `write` methods are not round-trippable, or they convert your data into a | |
# less-efficient representation before writing, then you might want to additionally define a custom | |
# serialization method, using this code. | |
# It should only be necessary to substitute your type for `Primitive`. | |
using Serialization |
This file contains hidden or 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 Pkg | |
function imports(pkg_dir::AbstractString) | |
imported = Set{String}() | |
for (root, dirs, files) in walkdir(pkg_dir) | |
for file in files | |
if endswith(file, ".jl") | |
union!(imported, open(imports, joinpath(root, file))) | |
end | |
end |
This file contains hidden or 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> @benchmark collect(groupby2(first, ["face", "foo", "bar", "book", "baz"])) | |
BenchmarkTools.Trial: | |
memory estimate: 1.98 KiB | |
allocs estimate: 60 | |
-------------- | |
minimum time: 14.258 μs (0.00% GC) | |
median time: 15.473 μs (0.00% GC) | |
mean time: 16.915 μs (0.00% GC) | |
maximum time: 207.366 μs (0.00% GC) | |
-------------- |
This file contains hidden or 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
Benchmarking Take1 ... | |
Take1 with cfg = 4096: nruns = 28955, elapsed = 1.516598519 secs | |
Take1 with cfg = 16384: nruns = 6217, elapsed = 1.307575089 secs | |
Take1 with cfg = 65536: nruns = 1252, elapsed = 1.152236431 secs | |
Take1 with cfg = 262144: nruns = 266, elapsed = 0.905467819 secs | |
Take1 with cfg = 1048576: nruns = 91, elapsed = 1.172819189 secs | |
Benchmarking Take2 ... | |
Take2 with cfg = 4096: nruns = 24779, elapsed = 1.368126555 secs | |
Take2 with cfg = 16384: nruns = 6403, elapsed = 1.47713414 secs | |
Take2 with cfg = 65536: nruns = 926, elapsed = 0.909415618 secs |
This file contains hidden or 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
module Sukano | |
using JuMP | |
function sudoku_setup() | |
m = Model() | |
@defVar(m, 0 <= board[1:9,1:9,1:9] <=1, Int) | |
# each square can only have one value | |
@addConstraint(m, squareconst[i=1:9,j=1:9], sum(board[i,j,:]) == 1) |
This file contains hidden or 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 partition(f::Function, collection) | |
u = similar(collection) | |
v = similar(collection) | |
for el in collection | |
if f(el) | |
push!(u, el) | |
else | |
push!(v, el) | |
end |
This file contains hidden or 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
data { | |
int<lower=1> N_ages; | |
vector[N_ages] ages; | |
int K[N_ages]; | |
int N[N_ages]; | |
} | |
transformed data { | |
vector[N_ages] mu; | |
mu <- rep_vector(0, N_ages); |
NewerOlder