Skip to content

Instantly share code, notes, and snippets.

@georgepradhan
georgepradhan / gist:5862931
Created June 25, 2013 22:11
Trying (not yet succeeding) to make a prime factorization method.
# Goal: Create a method that takes an input number and creates a hash of its prime factors and their exponents.
# e.g. prime_factorization(18) => { 2=>1, 3=>2 } #i.e. 2 * 3^2
# Logic: Take a number and divide by each prime number, and divide the resulting quotient by prime numbers, etc. to get the total factorization.
# e.g. 100 = 50 * 2.
# 50 = 25 * 2.
# 25 = 5 * 5.
# Prime factorization of 100 = 2*2*5*5 or 2^2*5^2.
factors = Hash.new(0)
@georgepradhan
georgepradhan / gist:5810047
Last active December 18, 2015 16:18
Project Euler #11
# Problem taken from: https://projecteuler.net/problem=11
# In the 2020 grid below, four numbers along a diagonal line have been marked in red.
# The product of these numbers is 26 63 78 14 = 1788696.
# What is the greatest product of four adjacent numbers in the same direction (up, down, left, right, or diagonally) in the 2020 grid?
n = '08 02 22 97 38 15 00 40 00 75 04 05 07 78 52 12 50 77 91 08
49 49 99 40 17 81 18 57 60 87 17 40 98 43 69 48 04 56 62 00
81 49 31 73 55 79 14 29 93 71 40 67 53 88 30 03 49 13 36 65
52 70 95 23 04 60 11 42 69 24 68 56 01 32 56 71 37 02 36 91