Skip to content

Instantly share code, notes, and snippets.

View syntacticsugar's full-sized avatar
🎯
Focusing

RomyRomy syntacticsugar

🎯
Focusing
View GitHub Profile
console.log("hello");
function LazySeq(head, tail) {
this.head = head; // value
this.tail = tail; // thunk || null
}
function ints(n) {
return new LazySeq(n, function() { return ints(n+1); });
}
@syntacticsugar
syntacticsugar / magic_maths.html
Last active December 16, 2015 07:29
magic mathz...
<!DOCTYPE html>
<html lang="en">
<head>
<title>-=( magic maths )=-</title>
<link rel="stylesheet" href="" />
</head>
<body bgcolor="#040404">
<canvas id="canvas" width=960 height=700>
</canvas>
<script src="magic_maths.js"></script>
@syntacticsugar
syntacticsugar / around_the_world.js
Created April 14, 2013 04:32
learning about the unit circle. trigonometry exercises for javascript canvas stuffs.
var canvas = document.getElementById("exercises"),
context = canvas.getContext("2d"),
width = canvas.width,
height = canvas.height;
// midpoints
var midX = canvas.width/2, midY = canvas.height/2;
// trigonometry
var TAU = Math.PI * 2,
<!DOCTYPE html>
<head>
<meta http-equiv="Content-Type" content="text/html;charset=utf-8">
<meta http-equiv="encoding" content="utf-8">
</head>
<canvas id="canvas" width="1490" height="512" style="border:1px dashed">
CA canvas
</canvas>
<script type="text/javascript">
var canvas = document.getElementById("canvas");
@syntacticsugar
syntacticsugar / church_encoding.rb
Created April 8, 2013 17:58
In mathematics, Church encoding is a means of embedding data and operators into the lambda calculus, the most familiar form being the Church numerals, a representation of the natural numbers using lambda notation. The method is named for Alonzo Church, who first encoded data in the lambda calculus this way. Terms that are usually considered prim…
# proccc
def one proccc, x
proccc.(x)
end
def two proccc, x
proccc.(proccc.(x))
end
@syntacticsugar
syntacticsugar / euler11.rb
Created March 28, 2013 19:19
What is the greatest product of four adjacent numbers in the same direction (up, down, left, right, or diagonally) in the 20x20 grid?
class Celery
def initialize(grid)
@grid = grid
@height = grid.length
@width = grid[0].length
end
def self.mini
[[ 0, 1, 2, 3, 4],
[10,11,12,13,14],
[20,21,22,23,24],
@syntacticsugar
syntacticsugar / euler8.rb
Created March 27, 2013 00:27
Find the greatest product of five consecutive digits in the 1000-digit number.
# Find the greatest product of five consecutive digits in the 1000-digit number.
madness=7316717653133062491922511967442657474235534919493496983520312774506326239578318016984801869478851843858615607891129494954595017379583319528532088055111254069874715852386305071569329096329522744304355766896648950445244523161731856403098711121722383113622298934233803081353362766142828064444866452387493035890729629049156044077239071381051585930796086670172427121883998797908792274921901699720888093776657273330010533678812202354218097512545405947522435258490771167055601360483958644670632441572215539753697817977846174064955149290862569321978468622482839722413756570560574902614079729686524145351004748216637048440319989000889524345065854122758866688116427171479924442928230863465674813919123162824586178664583591245665294765456828489128831426076900422421902267105562632111110937054421750694165896040807198403850962455444362981230987879927244284909188845801561660979191338754992005240636899125607176060588611646710940507754100225698315
def modulo_3?(number)
# (number % 3).zero?
number.modulo(3).zero? # i guess this is more idiomatic Ruby, though I like the previous better
end
def commify(number)
reversed = number.to_s.reverse
number_size = number.to_s.size
result = ""
@syntacticsugar
syntacticsugar / commify_numbers.rb
Created March 20, 2013 04:09
# goal: get a number like 25164150 # and transform it to: 25,164,150
# goal: get a number like 25164150
# and transform it to: 25,164,150
# =begin
# 1) number.to_s.split("").length
# 2) start from end, count multiples of 3
# 3) insert comma
# 4) turn array back into a string
# .join(",")
# x.unshift(",")unless (x % 3 != 0)
# Euclid's formula yields Pythagorean triples for integers m and n with m < n:
# a = m**2 - n**2 ; b = 2*m*n ; c = m**2 + n**2
x = 1000
def euclids upto
result = []
(2..upto).each do |m| # Start at 2 as 1 results nothing anyway
(1...m).each do |n| # Euclid's formula only works for m > n
result << [m**2 - n**2, 2*m*n, m**2 + n**2]