Skip to content

Instantly share code, notes, and snippets.

View syntacticsugar's full-sized avatar
🎯
Focusing

RomyRomy syntacticsugar

🎯
Focusing
View GitHub Profile
@syntacticsugar
syntacticsugar / 44a_pentagonal_numbers.rb
Last active August 29, 2015 14:01
project euler #44 Pentagonal Numbers in Ruby. This is probably the most inefficient, naive way to solve it, but it solved the problem. blehhhhh
=begin
Pentagonal numbers are generated by the formula, Pn=n(3n−1)/2. The first ten pentagonal numbers are:
1, 5, 12, 22, 35, 51, 70, 92, 117, 145, ...
It can be seen that P^4 + P^7 = 22 + 70 = 92 = P^8.
However, their difference, 70 − 22 = 48, is not pentagonal.
Find a pair of pentagonal numbers P^j and P^k,

How to Use

Open up Terminal.app in your /Applications/Utilities directory, then type in these commands, one after each other:

  1. Create a temporary directory for cycript:

    mkdir cycript && cd cycript
    
  2. Pull the latest cycript from cycript.org:

import Either
--main = asText (filterrr (\x -> x > 2) [1, 2, 3, 4])
main = asText (map squirtWithError [-2, -1, 0, 16, 36])
-- types
data Option a = None | Some a
@syntacticsugar
syntacticsugar / project_euler_17.rb
Last active January 2, 2016 23:59
project euler 17. took me foarever!!!!! and I had to get help from Nicky Bicky!
=begin
If the numbers 1 to 5 are written out in words: one, two, three, four, five, then there are 3 + 3 + 5 + 4 + 4 = 19 letters used in total.
If all the numbers from 1 to 1000 (one thousand) inclusive were written out in words, how many letters would be used?
NOTE: Do not count spaces or hyphens. For example, 342 (three hundred and forty-two) contains 23 letters and 115 (one hundred and fifteen) contains 20 letters. The use of "and" when writing out numbers is in compliance with British usage.
=end
# "and" COUNTS!
@syntacticsugar
syntacticsugar / project_euler_36.rb
Created December 29, 2013 01:52
project euler #36, first pass.
class String
def palindrome?
self == self.reverse
end
end
class Integer
def palindrome?(b=10)
self.to_s(b).palindrome?
end
@syntacticsugar
syntacticsugar / church_encoding.rb
Created November 22, 2013 00:28
"Let there be light." Thus spoke Alonzothrustra.
# proccc
def one proccc, x
proccc.(x)
end
def two proccc, x
proccc.(proccc.(x))
end
class Fixnum
def ordinal
%w[first second third fourth fifth sixth seventh eighth ninth tenth eleventh twelfth][self - 1]
end
# Use #to_word rather than #to_s, so it doesn't break any other printing of numbers.
def to_word
%w[one two three four five six seven eight nine ten eleven twelve][self - 1]
end
end
$array = []
module Collatz
def self.how_many n
if n == 1
($array.push n).length
elsif n.even?
$array.push n
n = n / 2
how_many n
(define menu
(lambda (x y)
(conde
[(== x 'tea) (== y 'biscuit)]
[(== x 'coffee) (== y 'cookie)])))
(define conso
(lambda (x y o)
(== `(,x . ,y) o)))
(ns hs-js-clj.core)
(def foo {:bar 1})
(defn fooify [n] (str "foo" n))
(defn commaify [[x y]]
(str x ", " y))