diff --git a/app.rb b/app.rb index 521d3ed..9f001c6 100644 --- a/app.rb +++ b/app.rb @@ -1,8 +1,8 @@ require 'sinatra' require './lib/profile' -set :application_id, 'EDIT_ME' -set :secret, 'EDIT_ME' +set :application_id, '8edabf285482485b7c735f82e559050ffce6db2ebd877c27c25501e795c4d834' +set :secret, '34e6a6a04e2361f836270c708a70c57cc97d6191b264b18b7359e763408492b4' set :redirect_uri, 'http://localhost:4567/callback' set :site_url, 'https://wegotcoders.com' set :session_secret, 'secret' diff --git a/primes.rb b/primes.rb index ec74770..0ec737a 100644 --- a/primes.rb +++ b/primes.rb @@ -1,6 +1,102 @@ class Primes - def self.sum_to(limit = 100) + def self.sum_to(limit = 20) # TODO - add your prime number solution here... - "I'm working on it!" + # Ruby code added below by Paul O'Hara 01/07/2017 post "We got coders" entrance test. + # Code below was a third attempt at an algorithm to add up prime numbers. I decided that a pure algorithm approach + # would never work, and that a more precise mathematical formula - as part of my own algorithm - was needed. My first + # year university maths was now rusty, so I turned to wikipedia for a formula that would work (not a trusted academic + # source, but still useful in its own right). The algorithm below contains pseudo code from the following web source: + # https://en.wikipedia.org/wiki/Primality_test. + # + # The pseudo code from the above wiki source is as follows: + # + # function is_prime(n) + # if n ≤ 1 + # return false + # else if n ≤ 3 + # return true + # else if n mod 2 = 0 or n mod 3 = 0 + # return false + # let i ← 5 + # while i * i ≤ n + # if n mod i = 0 or n mod (i + 2) = 0 + # return false + # i ← i + 6 + # return true + # + # Hence, the ruby algorithm below implements this formula to identify and add up prime numbers - to the value determined by var limit. + # + count = 0 + num_to_check = 0 + + while num_to_check <= 20 + + is_prime = true + + if num_to_check <= 1 + is_prime = false + elsif num_to_check <= 3 + is_prime = true + elsif (((num_to_check % 2 == 0) || (num_to_check % 3 == 0)) ) + is_prime = false + else + int_var = 5 + while int_var * int_var < num_to_check + if ((num_to_check % int_var == 0) || (num_to_check % (int_var + 2) == 0)) + is_prime = false + end + num_to_check += 6 + end + end + + if is_prime + count += num_to_check + end + + num_to_check += 1 + end + + return count + end -end \ No newline at end of file +end + + +# Ruby code added below by Paul O'Hara 19/06/2017 for entrance test. +# Note: I ran out of time to implement a correct algorithm to add up prime numbers. +# Instead, to show some knowledge of Ruby, I have implemented a routine to add up positive odd numbers to 100. +#index = 1 +#count = 0 +#while index < limit +# if index % 2 > 0 +# count += index +# end +# index += 1 +#end + +#Code below was an attempt over 1.5 hours, on 19/06/2017, to implement an algorithm to add up prime numbers, but in hind sight I should +#have used an array to hold dividing values up to num being checked - within the inner loop - to get the code to work correctly. +# n = 0 +# m = 0 +# count = 0 +# +# while n <= limit +# +# m = n - 1 +# +# while m > 1 +# +# if m <= Math.sqrt(n) +# if n % m > 0 +# count += n +# m = 0 #break inner loop +# end +# end +# +# m -= 1 +# end +# +# n += 1 +# end +# +# puts "Final count = #{count}" \ No newline at end of file diff --git a/public/stylesheets/main.css b/public/stylesheets/main.css index 1ef5a44..745f724 100644 --- a/public/stylesheets/main.css +++ b/public/stylesheets/main.css @@ -37,3 +37,46 @@ h3 { } /* TODO - Add your own styles here */ +/* CSS code below has been added by Paul O'Hara 17/06/2017 - 18/06/2017, for we Got Coders admission test. */ + +.tableStats { + background: linear-gradient(to bottom right, grey, yellow); + font-family: Helvetica; + color: navy; +} + +.contentsList { + background: linear-gradient(to bottom right, white, grey); +} + +.photo { + position:absolute; top:10px; right:40px; z-index:10; + + +} + +h5 { + bold; font-size: 2.5em; + color: olive; +} + +li { + font-family: sans-serif; + font-size: 1.5; + color: purple; +} + +th { + font-family: monospace; + padding:10px; + border:2px solid black; + color: maroon; + font-size: 1.0; +} + +td { + padding:5px; + border:1px solid black +} + + diff --git a/views/index.erb b/views/index.erb index 44368ca..7ba5f14 100644 --- a/views/index.erb +++ b/views/index.erb @@ -2,17 +2,67 @@

<%= @profile["first_name"] %>'s Amazing Profile

+ + + + + +
+
+
Your profile is broken down as follows:
+
+
  • Your photo
  • +
  • Table of personal details
  • +
  • Word stats
  • +
  • Programming problems
  • +
  • Link to Coding Academy website
  • +
  • Edit profile option
  • +
    +
    + + + + +
    + + + + + + + + + + + + + <% @profile.each do |field, value| %> + + + + <% end %> + +
    Your 'We Got Coders' personal information for <%= @profile["first_name"] %>
    Personal valueDetails
    <%= field %><%= value %>
    +
    +

    Stats

    - 0 words found. + + + click this link for words found (n.b. at present just shows number of Personal value rows in table of personal details, and not number of words in details section of table - to correct in future version). + +
    @@ -20,6 +70,11 @@ My Prime Number Solution
    + +

    Edit Profile

    @@ -28,6 +83,21 @@
    "/> + + + "/> + + "/> + + "/> + + "/> + + "/> + + + "/> +
    @@ -46,14 +116,23 @@ + \ No newline at end of file