Skip to content

Instantly share code, notes, and snippets.

View larryv's full-sized avatar

Lawrence Velázquez larryv

View GitHub Profile
#!/usr/bin/env python3.2
import csv
import datetime
import glob
import io
import os
import os.path
import sys
import tempfile
#!/usr/bin/env ruby1.9
# Project Euler, Problem 14
#
# The following iterative sequence is defined for the set of positive
# integers:
#
# n -> n / 2 (n is even)
# n -> 3n + 1 (n is odd)
#
/*
Project Euler, Problem 14
The following iterative sequence is defined for the set of positive
integers:
n -> n / 2 (n is even)
n -> 3n + 1 (n is odd)
Using the rule above and starting with 13, we generate the following
#!/usr/bin/env ruby1.9
# Project Euler, Problem 52
#
# It can be seen that the number 125874, and its double, 251748, contain
# exactly the same digits, but in a different order.
#
# Find the smallest positive integer x such that 2x, 3x, 4x, 5x, and 6x
# contain the same digits.
#
#!/usr/bin/env ruby1.9
# Project Euler, Problem 12
#
# The sequence of triangle numbers is generated by adding the natural
# numbers. So the 7th triangle number would be 1 + 2 + 3 + 4 + 5 + 6 + 7 =
# 28. The first ten terms would be:
#
# 1, 3, 6, 10, 15, 21, 28, 36, 45, 55, ...
#
-- Project Euler, Problem 97
--
-- ==========
-- The first known prime found to exceed one million digits was discovered
-- in 1999, and is a Mersenne prime of the form 2^6972593 - 1; it contains
-- exactly 2,098,960 digits. Subsequently other Mersenne primes, of the
-- form 2^p - 1, have been found which contain more digits.
--
-- However, in 2004 there was found a massive non-Mersenne prime which
-- contains 2,357,207 digits: 28433 * 2^7830457 + 1.
-- Project Euler, Problem 48
--
-- ==========
-- The series, 1^1 + 2^2 + 3^3 + ... + 10^10 = 10405071317.
--
-- Find the last ten digits of the series, 1^1 + 2^2 + 3^3 + ... + 1000^1000.
-- ==========
--
-- Lawrence Velazquez
-- 13 June 2011
class Integer
def to_binary_s(n)
(n - 1).downto(0).inject("") {|str, i| str << self[i].to_s}
end
end
#!/usr/bin/env ruby1.9
# Project Euler, Problem 36
#
# The decimal number, 585 = 1001001001 (binary), is palindromic in both
# bases.
#
# Find the sum of all numbers, less than one million, which are palindromic
# in base 10 and base 2.
#
#!/usr/bin/env ruby1.9
# Project Euler, Problem 57
#
# It is possible to show that the square root of two can be expressed as an
# infinite continued fraction.
#
# sqrt(2) = 1 + 1/(2 + 1/(2 + 1/(2 + ...))) = 1.414213...
#
# By expanding this for the first four iterations, we get: