Skip to content

Instantly share code, notes, and snippets.

(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.
/// @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 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!
# 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)
@Ismael-VC
Ismael-VC / always_on_jupyter.sh
Last active September 11, 2015 16:57 — forked from jbn/always_on_jupyter.sh
Always On Jupyter
# 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 &&
@Ismael-VC
Ismael-VC / FArray.jl
Created September 25, 2015 16:04 — forked from alsam/FArray.jl
Julia implementation Fortran-like array with arbitrary starting indices, negative or zero. Incurs a reasonable overhead vs. Base.Array, expected performance degradation should be strictly less than 2x.
# 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
@Ismael-VC
Ismael-VC / factorial-table.jl
Created February 10, 2016 03:09 — forked from rknuu/factorial-table.jl
Julia is awesome...
# 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
@Ismael-VC
Ismael-VC / .juliarc.jl
Created August 10, 2016 00:47 — forked from meggart/.juliarc.jl
Macroexpand shortcut in the REPL
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
@Ismael-VC
Ismael-VC / uppertriangular.jl
Created September 28, 2016 04:59 — forked from ityonemo/uppertriangular.jl
Iterates over upper triangular indices.
#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)
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))