Skip to content

Instantly share code, notes, and snippets.

View reuk's full-sized avatar
🍹
there's no I in JUCE

reuk reuk

🍹
there's no I in JUCE
View GitHub Profile
void drawFolder(int sides, float rad) {
float ang = (frameCount * 2 * PI * 0.05) / sides;
PVector maxy = new PVector(0, 0);
PVector[] v = new PVector[sides];
for (int i = 0; i != v.length; ++i) {
float angle = ((2 * PI * i) / sides) + ang;
float x = sin(angle) * rad;
@reuk
reuk / fold.pde
Created September 2, 2013 19:28
folding prism walk thing
void setup() {
size(500, 500, P3D);
frameRate(25);
blendMode(ADD);
ortho();
}
void draw() {
background(0);
noFill();
@reuk
reuk / euler144.hs
Last active December 21, 2015 15:29
I'm quite pleased with this one.
import Control.Applicative
data Vec2 a = Vec2 (a, a) deriving (Eq, Show)
instance Functor Vec2 where
fmap f (Vec2 (x, y)) = Vec2 (f x, f y)
instance Applicative Vec2 where
pure x = Vec2 (x, x)
(Vec2 (f, g)) <*> (Vec2 (x, y)) = Vec2 (f x, g y)
@reuk
reuk / Knight.hs
Created August 20, 2013 17:23
Finds solutions to the Knight's Tour problem on arbitrarily-sized boards and from any starting position.
import Control.Applicative
import Data.Maybe
import Debug.Trace
data Board = Board [[Bool]]
deriving (Eq, Show)
newBoard :: Board
newBoard = newBoard' 8 8
where newBoard' x y = Board $ take y $ repeat $ take x $ repeat False
@reuk
reuk / euler102
Created August 19, 2013 19:38
euler 102 solution (well, nearly) using Processing
void line(PVector p, PVector q) {line(p.x, p.y, q.x, q.y);}
class Line {
private PVector i, j;
float a, b, c;
Line(PVector i_, PVector j_) {
i = i_; j = j_;
recalc();
}
@reuk
reuk / euler57
Created August 18, 2013 15:47
More haskelling. This problem's nice - it's very easy to express recursively. It's easy to express iteratively too, of course. Actually, I find the iterative solution a lot clearer, which probably means my Haskell sucks. :(
//
// HASKELL
//
matches i (num, den) | i == 0 = 0
| g (num' + den') > g den' = 1 + f
| otherwise = f
where num' = den
den' = num + (2 * den)
f = matches (i - 1) (num', den')
@reuk
reuk / euler56.hs
Created August 18, 2013 10:08
One-liner solution to Project Euler problem 56.
import Data.Char (digitToInt)
main = print $ maximum [sum $ map digitToInt $ show (a ^ b) | a <- [1..100], b <- [1..100]]
@reuk
reuk / euler55.hs
Created August 18, 2013 09:45
My first Project Euler solution using Haskell. This one (number 55) finds how many Lychrel numbers are smaller than 10000.
solve = isLychrel 0
where isLychrel i x | d == reverse d = False
| i > 50 = True
| otherwise = isLychrel (i + 1) c
where b = reverse $ show x
c = (x + (read b :: Integer))
d = show c
main = print $ length $ filter (== True) $ map solve [1..9999]
@reuk
reuk / Matrix.hs
Created August 16, 2013 23:51
mucking around with applicative functors I have literally no idea what I'm doing function compositions are well shiny though
module Matrix where
import Control.Applicative
import Data.List
data Matrix a = Matrix [[a]]
deriving (Eq, Show)
instance Functor Matrix where
fmap f (Matrix x) = Matrix $ fmap (fmap f) x
@reuk
reuk / headers_and_blah
Created July 12, 2013 20:53
Megasimple raytracing sketch for processing. If I keep it 2D, I want to add support for beziers or splines or curves of some kind. Otherwise, I wanna add support for 3D triangles and have some kind of object loader. The idea is to take the focus of raytracing away from the final product (an image of an object) and instead focus on the rays thems…
class Ray {
private PVector origin = new PVector();
private PVector direction = new PVector();
private float length = MAX_FLOAT;
Ray(PVector o, PVector d) {
setorigin(o);
setdirection(d);
}