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
(ns primes.core | |
(:use clojure.test) | |
(:require [clojure.math.numeric-tower :as math])) | |
;; Problem statement: | |
;; You are given a function ‘secret()’ that accepts a single integer parameter | |
;; and returns an integer. In your favorite programming language, write a | |
;; program that determines if this function is an additive function | |
;; [ secret(x+y) = secret(x) + secret(y) ] for all prime numbers under 100. |
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
/// @file segmented_sieve.cpp | |
/// @author Kim Walisch, <[email protected]> | |
/// @brief This is a simple implementation of the segmented sieve of | |
/// Eratosthenes with a few optimizations. It generates the | |
/// primes below 10^9 in 0.9 seconds (single-threaded) on an | |
/// Intel Core i7-4770 CPU (3.4 GHz) from 2013. | |
/// @license Public domain. | |
#include <iostream> | |
#include <algorithm> |
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
# This code is part of a presentation on streaming analytics in Julia | |
# It was inspired by a number of individuals and makes use of some of their ideas | |
# 1. FastML.com got me thinking about inline processing after | |
# reading his great Vowpal Wabbit posts | |
# 2. John Lanford and his fantastic Vowpal Wabbit library. | |
# Check out his NYU video course to learn more (see below) | |
# 3. John Myles White's presentation on online SDG and his StreamStats.jl library | |
# Thank you all! | |
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
# Requested gist of code to produce: | |
# https://www.scribd.com/doc/271871142/Julia-Type-Hierarchy | |
# | |
# I just redirected the output to a dot file, then executed: | |
# dot -Tpdf julia.dot -o julia.pdf | |
function print_type_tree(t, parent=Any, seen=Set{DataType}()) | |
# Avoid redundant edges. | |
t ∈ seen && return | |
push!(seen, t) | |
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
# Installation: | |
# - Put this in your .bash_profile | |
# - Replace my directory with your exobrain directory on line 10 | |
# | |
# What you get: | |
# A Jupyter notebook open on a well-defined port that is always | |
# on for exobrain-ing your ideas... | |
exec 6<>/dev/tcp/localhost/10000 || ( | |
source activate py27 && |
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
# Fortran-like array with arbitrary starting indices | |
# | |
# usage: | |
# | |
# julia> include("FArray.jl") | |
# size (generic function with 51 methods) | |
# | |
# julia> y = FArray(Float64, -1:1, -7:7, -128:512, -5:5, -1:1, -3:3, -2:2, -1:1); | |
# | |
# julia> y[-1,-7,-128,-5,-1,-3,-2,-1] = 14 |
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 is fully unicode aware and if you use your variable and function | |
# names just right, you can express your anger like no other language. | |
⋰┛ಠДಠ┛⋱彡┻━┻(n) = n < 2 ? n : ⋰┛ಠДಠ┛⋱彡┻━┻(n - 1) + ⋰┛ಠДಠ┛⋱彡┻━┻(n - 2) | |
@elapsed ⋰┛ಠДಠ┛⋱彡┻━┻(25) # 0.00266 |
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
if VERSION > v"0.4.0-dev+4268" | |
const marcoexpandkeys = Dict{Any,Any}("^I" => function (s,o...) | |
if !isempty(s) | |
line = parse(Base.LineEdit.input_string(s)) | |
s.kill_buffer=Base.LineEdit.input_string(s) | |
Base.LineEdit.edit_clear(s) | |
Base.LineEdit.edit_insert(s,string(macroexpand(line))) | |
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
#upper triangular indices - iterates over upper triangular indices in a list of | |
#indices. | |
type uppertriangular; iterable; end | |
Base.start(x::uppertriangular) = (1, 1) | |
function Base.next(x::uppertriangular, state) | |
(idx1, idx2) = state | |
next1 = idx1 | |
next2 = idx2 + 1 | |
if next2 > length(x.iterable) |
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 Plots;glvisualize() | |
using GLVisualize, FileIO, Colors, Images | |
using GeometryTypes, GLAbstraction | |
x = ["(。◕‿◕。)", "◔ ⌣ ◔","(づ。◕‿‿◕。)づ", "┬──┬ ノ( ゜-゜ノ)", "(╯°□°)╯︵ ┻━┻", "¯\\_(ツ)_/¯"] | |
y = [-4, -3, -2, -1, 6, 0] | |
scatter(x, y) | |
t = bounce(linspace(-1.0f0,1f0, 20)) | |
translation = map(t) do t | |
rotationmatrix_y(1f0)*rotationmatrix_z(deg2rad(90f0)) * translationmatrix(Vec3f0(3,3,t)) |