This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
--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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
i = 1 | |
last = 0 | |
sum = 0 | |
begin | |
temp_last, i = i, (i + last) | |
if i % 2 == 0 then | |
sum += i; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Fizz buzz! | |
sum = 0; | |
(0..999).each do |i| | |
if i % 5 == 0 || i % 3 == 0 then | |
sum += i | |
end | |
end | |
print sum |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
MAX_NUM = 999 | |
MIN_NUM = 100 | |
def is_palindrome?(num) | |
if num.to_s() == num.to_s().reverse | |
true | |
else | |
false | |
end |