{{ message }}

Instantly share code, notes, and snippets.

# Mikko Harju mharju

Last active Aug 29, 2015
Solution to the newest Reaktor FastTrack. Mathematically elegant, code-wise maybe not so :)
View outrun.clj
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
 ; A solution to the latest http://reaktor.fi/careers/fast_track/ ; ; Calculates recursively the maximum path function ; S(i,j) = W(i,j) + max { S(i-1, j-1), S(i-1, j) } ; ; Solution to the problem is just finding ; M = max { S(N, i) }, 1 <= i <= N (using 1-based indexing) ; ; then prints out the solution from the given node as an HTML table.
Created Jan 13, 2014
Ecom solution
View ecom.js
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
 function calculate(o){return _.foldl(o,function(a,b){a[b.vat]=b.price+(a[b.vat]||0);return a},{})}
Last active Jan 1, 2016
Reaktor FastTrack morse code DFA solution
View build-dfa.clj
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 test.core (:require [clojure.string :as str])) (def morse (into [] (sort-by key (comparator (fn [x y] (<= (count x) (count y)))) {".-" "A" "-..." "B" "-.-." "C" "-.." "D" "." "E" "..-." "F" "--." "G" "...." "H" ".." "I" ".---" "J" "-.-" "K" ".-.." "L" "--" "M" "-." "N" "---" "O" ".--." "P" "--.-" "Q" ".-." "R" "..." "S" "-" "T" "..-" "U" "...-" "V" ".--" "W" "-..-" "X" "-.--" "Y" "--.." "Z"}))) (defn build-dfa ([codes] (build-dfa codes []))
Created Nov 8, 2013
Reactive Cocoa. Don't you just got to love it?
View gist:7367279
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
 NSArray *items = @[_gainSlider, _frequencySaturation, _driveSlider]; NSArray *signals = [[[items rac_sequence] map:^id(id value) { return [value rac_highlightSignal]; }] array]; __block BOOL triggering = NO; [[RACSignal merge:signals] subscribeNext:^(RACTuple* value) { if(triggering) { return; } triggering = YES;
Last active Dec 22, 2015
Splits the array to parts of equal lengths, len = 3,4,5,...,35 and searches that space for numbers N satisfying N=x(x+1)(x+2)(x+3)(x+4).
View reaktor-max.js
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
 var find_greatest = function(input) { var check = function(n) { if(n==0) { return false; } // n is of form x^5 + O(x^4), so we can pick it by taking the // fifth root and taking the extra crust off var x = Math.floor( Math.pow( n, 0.2 ) ) - 1 return n === x*(x+1)*(x+2)*(x+3)*(x+4); } var slice_n = function(n,x) {
Last active Dec 18, 2015
Encoding and decoding QWERTY-ciphers with constant transposition of one letter.
View qwerty-cipher.py
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
 qwerty = u"qwertyuiopåasdfghjklöä'zxcvbnm," transpose = lambda s,t: ''.join([ (qwerty[qwerty.index(c)+t] if c in qwerty else c) for c in s]) encode = lambda s: transpose(s, 1) decode = lambda s: transpose(s, -1);
Last active Dec 17, 2015
Fixed the glitch.
View trivial-opengl-blit
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
 // Texture: 1024 x 1024 x 4bpp // Contains 1024 x 768 image from (0,0) to (1024, 768) // Use glOrtho like glOrtho2d glOrtho(0, width, height, 0, -1, 1); // This solved it! glClear(GL_COLOR_BUFFER_BIT); glClearColor(0.0, 1.0, 0.0, 1.0); glMatrixMode(GL_MODELVIEW);
Last active Dec 14, 2015
Not so buggy filter code
View filter.c
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
 // Ah. Better. typedef struct { float x1, x2, y1, y2; float c0, c1, c2, c3, c4; } biquad_t; typedef enum { HIGH_SHELF, LOW_SHELF,
Created Mar 5, 2013
Why does this not work?