Skip to content

Instantly share code, notes, and snippets.

View jamogriff's full-sized avatar

Jamison Griffith jamogriff

  • Arvada, CO
View GitHub Profile
@loganhasson
loganhasson / Sieve of Eratosthenes.md
Last active December 31, 2020 20:48
A Ruby example of using the Sieve of Eratosthenes to determine whether or not a number is prime

Using the Sieve of Eratosthenes to Find Prime Numbers in Ruby

The Sieve of Eratosthenes is a super efficient way to determine whether or not numbers are prime. Essentially, it takes a max number, and via the process of elimination, gives you an array that contains every prime number up to that max number.

The very short explanation is this:

  1. Create an array from 0..max
  2. Starting at 2, delete every multiple of 2 from the array.
  3. Then, go back to the beginning, and delete every multiple of 3.
  4. Repeat this starting from the next available number at the beginning of the array.
@mxriverlynn
mxriverlynn / 1-has_image.rb
Created September 27, 2011 21:30
capybara has_image? matcher
module Capybara
class Session
def has_image?(src)
has_xpath?("//img[contains(@src,\"/images/#{src}\")]")
end
end
end