Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file added .DS_Store
Binary file not shown.
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
DevPreWork01
#DevPreWork01
============

My prework for the [Startup Institute](www.startupinstitute.com).
8 changes: 8 additions & 0 deletions pe1.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
total = 0
(1...1000).each do |num|
if num%3 == 0 || num%5 == 0
total += num
end
end

puts total
23 changes: 23 additions & 0 deletions pe10.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
#THIS IS SLOW. ~5 MIN => Need to make more efficient

require 'Prime'
continue = true


while continue
prime_array = Array.new
sum = 0

Prime.each(2_000_000) do |prime|
puts prime
sum += prime
end

puts sum

puts "Continue? "
go = gets.chomp
if go != 't'
continue = false
end
end
19 changes: 19 additions & 0 deletions pe2.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
a = 0
b = 1
total = 0

fibs = [1,2]

while (fibs[a] + fibs[b]) < 4000000
fibs << (fibs[a] + fibs[b])
a += 1
b += 1
end

fibs.each do |num|
if num%2 == 0
total += num
end
end

puts total
26 changes: 26 additions & 0 deletions pe3.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
require 'Prime'



continue = true

while continue
max_num = 600851475143
primefact_array = Array.new

Prime.each(Math.sqrt(max_num)) do |prime|
if max_num%prime == 0
primefact_array << prime
end
end

puts primefact_array.last

puts 'Continue?'
go = gets.chomp
if go != 't'
continue = false
end
end


24 changes: 24 additions & 0 deletions pe4.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
start_num = 999
end_num = 1
product_array = Array.new
continue = true

while continue
start_num.downto(end_num) do |num1|
start_num.downto(end_num) do |num2|
product = num1*num2
if product.to_s == product.to_s.reverse
product_array << (num1*num2)
end
end
end

puts product_array.max

puts "Continue?"
go = gets.chomp

if go != 't'
continue = false
end
end
13 changes: 13 additions & 0 deletions pe5.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
continue = true

while continue
puts (1..20).inject(:lcm)

puts "\nContinue?"
go = gets.chomp
if go != 't'
continue = false
end
end


20 changes: 20 additions & 0 deletions pe6.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
def sum_square
total = 0
(1..100).each do |num|
square = num **2
total += square
end
return total
end

def square_sum
sum = 0
(1..100).each do |num|
sum += num
end
return sum **2
end

difference = (square_sum)- (sum_square)

puts difference
16 changes: 16 additions & 0 deletions pe7.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
require 'Prime'


continue = true

while continue
prime_array = Prime.first 10_001
puts prime_array.last
puts "Keep going? "
go = gets.chomp
if go != 't'
continue = false
end
end


53 changes: 53 additions & 0 deletions pe8.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
num = '73167176531330624919225119674426574742355349194934
96983520312774506326239578318016984801869478851843
85861560789112949495459501737958331952853208805511
12540698747158523863050715693290963295227443043557
66896648950445244523161731856403098711121722383113
62229893423380308135336276614282806444486645238749
30358907296290491560440772390713810515859307960866
70172427121883998797908792274921901699720888093776
65727333001053367881220235421809751254540594752243
52584907711670556013604839586446706324415722155397
53697817977846174064955149290862569321978468622482
83972241375657056057490261407972968652414535100474
82166370484403199890008895243450658541227588666881
16427171479924442928230863465674813919123162824586
17866458359124566529476545682848912883142607690042
24219022671055626321111109370544217506941658960408
07198403850962455444362981230987879927244284909188
84580156166097919133875499200524063689912560717606
05886116467109405077541002256983155200055935729725
71636269561882670428252483600823257530420752963450'


place = 0
digits = 5
continue = true

product_array = Array.new

def product (n)
total_product = 1
n.each_char do |char|
char = char.to_i
total_product *= char
end
return total_product
end


while continue
while place <= 995
string = num[place, digits]
product = product(string)
product_array << product
place += 1
end

puts product_array.max
puts "Continue? "
go = gets.chomp
if go != 't'
continue = false
end
end
11 changes: 11 additions & 0 deletions pe9.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
## This algorithm uses an algebraic manipulation of Euclid's equations

(2..30).each do |m|
(1...m).each do |n|
a = (m**2 - n**2)
b = 2*m*n
c = (m**2 + n**2)

puts a*b*c if a+b+c==1000
end
end
Empty file removed problem03.rb
Empty file.
Empty file removed problem05.rb
Empty file.
Empty file removed problem08.rb
Empty file.