Skip to content

Instantly share code, notes, and snippets.

View zschallz's full-sized avatar

Zachary Zimmerman zschallz

View GitHub Profile
@zschallz
zschallz / Problem4.rb
Created July 7, 2012 02:43
Project Euler Problem 4
MAX_NUM = 999
MIN_NUM = 100
def is_palindrome?(num)
if num.to_s() == num.to_s().reverse
true
else
false
end
@zschallz
zschallz / problem5.rb
Created July 8, 2012 17:56
Project Euler Problem 5
# This takes more around 5 minutes to run on a modern i5 machine. Need to optimize.
MIN_NUM = 1
MAX_NUM = 20
def is_consecutively_factorable?(number)
if number == 0 then
return false
end
@zschallz
zschallz / problem1.rb
Created July 8, 2012 17:57
Project Euler Problem 1
# Fizz buzz!
sum = 0;
(0..999).each do |i|
if i % 5 == 0 || i % 3 == 0 then
sum += i
end
end
print sum
@zschallz
zschallz / problem3.rb
Created July 8, 2012 17:58
Project Euler Problem 3
# This needs to be reworked. It provides the correct answer, but it is not elegant or efficient.
# On my list to rework later.
def get_prime_factors(number)
prime_array = sieve_upto(1000000) # hack ... generate prime numbers below 1000000
prime_array.each do | i |
if number % i == 0 then
print i.to_s + " "
end
@zschallz
zschallz / problem2.rb
Created July 8, 2012 17:59
Project Euler problem 2
i = 1
last = 0
sum = 0
begin
temp_last, i = i, (i + last)
if i % 2 == 0 then
sum += i;
@zschallz
zschallz / gist:5103605
Last active December 14, 2015 14:49
Anonymous block to apply a credit memo to an EBS transaction
--Copyright (c) 2012, Zachary Zimmerman
--All rights reserved.
--Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
--Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
--Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
--THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, D