Skip to content

Instantly share code, notes, and snippets.

View syntacticsugar's full-sized avatar
🎯
Focusing

RomyRomy syntacticsugar

🎯
Focusing
View GitHub Profile
@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!
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

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:

@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,
class GuessTheNumber
def play
@nnn = 1.upto(100).to_a.sample
# play game
puts "Alright, I have a number in mind from 1-100. Pick a number."
guess = gets.chomp
puts "You said #{guess}."
attempt guess
end
textarea:focus,
input[type="text"]:focus,
input[type="password"]:focus,
input[type="datetime"]:focus,
input[type="datetime-local"]:focus,
input[type="date"]:focus,
input[type="month"]:focus,
input[type="time"]:focus,
input[type="week"]:focus,
input[type="number"]:focus,
@syntacticsugar
syntacticsugar / maybe.sml
Created September 17, 2014 22:09
tutorial from Nicky Bicky
type Maybe a = Nothing | Just a
type Option a = None | Some a
type Result a = Failure | Success a
max [] ----> Failure
max [1,2,3] -----> Success 3
@syntacticsugar
syntacticsugar / js_recursion_simple.js
Created October 6, 2014 16:14
A simple JS recursion using slice.
function sum (numbers) {
return !numbers.length ? 0 : numbers[0] + sum(numbers.slice(1));
};
module Sinatra
module Kittens
module Helpers
def kittens_page(x = 200..500, factor = 0.2)
sample_method = RUBY_VERSION >= '1.9' ? :sample : :choice
x = x.to_a.send(sample_method)
y = ((x - factor*x).floor..(x + factor*x).ceil).to_a.send(sample_method)
<<-HTML
<!DOCTYPE html>
@syntacticsugar
syntacticsugar / defining_lists.elm
Created March 16, 2015 03:05
wherein we try defining `list`
import Text (asText)
type Collection a = Nada | Glue a (Collection a)
summm xs =
case xs of
Nada -> 0
Glue face body -> face + (summm body)
listToCollection collection =