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 LinearAlgebra | |
########################################### | |
# Types and basis | |
abstract type AbstractCrystalGroup end | |
struct CrystalGroup{K} <: AbstractCrystalGroup | |
R::Array{K, 2} | |
T::Array{K, 1} | |
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
## Part 1 | |
struct Planet | |
pos::Vector{Int} | |
vel::Vector{Int} | |
end | |
Planet(s::String) = Planet(parse.(Int, match(r"x=([\-0-9]+).*y=([\-0-9]+).*z=([\-0-9]+)", s).captures), zeros(Int, 3)) | |
veldiff!(p1::Planet, p2::Planet) = (p1.vel .+= sign.(p2.pos .- p1.pos)) | |
shift!(p::Planet) = (p.pos .+= p.vel) | |
energy(p::Planet) = sum(abs.(p.pos))*sum(abs.(p.vel)) |
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
mutable struct Prog | |
code::Vector{Int} | |
cur::Int | |
input::Vector{Int} | |
output::Vector{Int} | |
relative_base::Int | |
eop::Bool | |
end | |
str2prog(s) = parse.(Int, split(s, ",")) |
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
struct PermIter{T} | |
v::Vector{T} | |
infinite::Bool | |
end | |
function Base.iterate(iter::PermIter{T}, state = ones(Int, length(iter.v))) where T | |
if state[end] == 2 return nothing end | |
v = iter.v | |
elem = Vector{T}(undef, length(iter.v)) |
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
## Part 1 | |
function conv2graph(data) | |
graph = Dict{String, Vector{String}}() # x is being orbited by [y, z] | |
for orbit in data | |
m = match(r"^([^\)]+)\)(.*)$", orbit) | |
if m[1] in keys(graph) | |
push!(graph[m[1]], m[2]) | |
else | |
graph[m[1]] = [m[2]] | |
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
mutable struct Code | |
code::Vector{Int} | |
cur::Int | |
input::Int | |
output::Int | |
eop::Bool | |
end | |
str2prog(s) = parse.(Int, split(s, ",")) |
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
# | |
# This is a Shiny web application. You can run the application by clicking | |
# the 'Run App' button above. | |
# | |
# Find out more about building applications with Shiny here: | |
# | |
# http://shiny.rstudio.com/ | |
# | |
library(shiny) |
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
# https://github.com/dmlc/MXNet.jl/issues/167 | |
using MXNet | |
# Custom eval metric | |
import MXNet.mx: get, reset!, _update_single_output | |
type CustomMetric <: mx.AbstractEvalMetric | |
loss::Float64 | |
n::Int |
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 BenchmarkTools | |
# Prepare random dictionary | |
d = Dict{Symbol, Real}() | |
for _ in 1:1000 | |
d[Symbol(randstring())] = rand() | |
end | |
function test_dict() | |
Dict(k => v for (k, v) in d) |
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
# There is no default parse(Float16), this one is taken from | |
# https://github.com/JuliaLang/julia/issues/16411#issuecomment-256835385 | |
import Base: parse | |
function parse(::Type{Float16}, str::String) | |
fp = 0.0 | |
try | |
fp = parse(Float64, str) | |
catch | |
throw(ArgumentError(string("invalid number format \"",str,"\" for Float16"))) |