Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

We Got Coders entrance test for Paul O'Hara #83

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
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
4 changes: 2 additions & 2 deletions app.rb
Original file line number Diff line number Diff line change
@@ -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'
Expand Down
102 changes: 99 additions & 3 deletions primes.rb
Original file line number Diff line number Diff line change
@@ -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
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}"
43 changes: 43 additions & 0 deletions public/stylesheets/main.css
Original file line number Diff line number Diff line change
Expand Up @@ -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
}


93 changes: 86 additions & 7 deletions views/index.erb
Original file line number Diff line number Diff line change
Expand Up @@ -2,24 +2,79 @@
<h3><%= @profile["first_name"] %>'s Amazing Profile</h3>

<!-- TODO- Perhaps re-jig this to fit your new design / layout -->
<!-- Note: original code commented out by Paul O'Hara 17/06/2017 but left in for reference/comparison testing purposes -->
<!--
<% @profile.each do |field, value| %>
<div class="profile-section box">
<h4><%= field %></h4>
<p class="profile-value"><%= value %></p>
</div>
<% end %>
-->


<!--HTML code below has been added by Paul O'Hara 17/06/2017 - 18/06/2017, for we Got Coders admission test. -->
<div id="listSection" class="contentsList">
<br>
<h5>Your profile is broken down as follows: </h5>
<br>
<li>Your photo</li>
<li>Table of personal details</li>
<li>Word stats</li>
<li>Programming problems</li>
<li>Link to Coding Academy website</li>
<li>Edit profile option</li>
<br>
</div>

<div id="Paul_logo" class="photo";>
<img src="/images/Paul_O'Hara_photo.png" alt="Paul's photo" width="300" height="300"/>
</div>


<div id="personalDetails" class="tableStats">
<table border="100px">
<thead>
<tr>
<th colspan="2">Your <span style="font-family: Impact;">'We Got Coders'</span> personal information for <%= @profile["first_name"] %></th>
</tr>

<tr>
<th>Personal value</th>
<th>Details</th>
</tr>


<% @profile.each do |field, value| %>
<tr><span id="numberOfTableValues">
<td><%= field %></td>
<td><%= value %></td>
<% end %>
</tr></span>
</table>
</div>
<!-- End of HTML code added by Paul O'Hara 17/06/2017 - 18/06/2017 -->

<div id="stats" class="box">
<h3>Stats</h3>
<!-- TODO - Set the contents of this span with JavaScript -->
<span id="word-count">0</span> words found.
<!-- JS Code added below by Paul O'Hara 18/06/2017... can't get function working correctly in time limit, deeper DOM study needed -->
<!-- Note: unable to call function without triggering an event (otherwise not sure how this can be done ?) -->
<span id="word-count"><a href="javascript:countValuesInTableFunction();">click this link for</a></span> 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).

<!-- End of JS code added below by Paul O'Hara 18/06/2017. -->
</div>

<div id="problems" class="box">
<h3>Programming Problems</h3>
<a href="/primes">My Prime Number Solution</a>
</div>

<div id="codeAcademyLink" class="box">
<h3>Link to Coding Academy website</h3>
<a href="https://www.codecademy.com">Link to Coding Academy website</a>
</div>

<div class="box">
<h3>Edit Profile</h3>

Expand All @@ -28,6 +83,21 @@
<div class="form-group">
<label for="trainee[about]">About</label>
<input type="text" name="trainee[about]" value="<%= @profile["about"] %>"/>
<!-- Code added below by Paul O'Hara 18/06/2017 to allow extra profile fields to be updated - part of admission test -->
<label for="trainee[projects]">Projects</label>
<input type="text" name="trainee[projects]" value="<%= @profile["projects"] %>"/>
<label for="trainee[rationale]">Rationale</label>
<input type="text" name="trainee[rationale]" value="<%= @profile["rationale"] %>"/>
<label for="trainee[ambition]">Ambition</label>
<input type="text" name="trainee[ambition]" value="<%= @profile["ambition"] %>"/>
<label for="trainee[learning_experience]">Learning experience</label>
<input type="text" name="trainee[learning_experience]" value="<%= @profile["learning_experience"] %>"/>
<label for="trainee[how_did_you_hear]">How did you hear</label>
<input type="text" name="trainee[how_did_you_hear]" value="<%= @profile["how_did_you_hear"] %>"/>
<!-- Note: Unsure how to write "code academy" values back to "We Got Coders" server without changing client Ruby modules ?-->
<label for="trainee[code_academy_acc]">Code Academy Account</label>
<input type="text" name="trainee[code_academy_acc]" value="<%= @profile["code_academy_acc"] %>"/>
<!-- End of code added below by Paul O'Hara 18/06/2017 to allow extra profile fields to be updated -->
</div>

<!-- TODO - Add more fields so that your profile can be edited -->
Expand All @@ -46,14 +116,23 @@


<!-- Add your Javascript to this script tag -->
<!-- Code added below by Paul O'Hara 18/06/2017 - (N.B. due to lack of knowledge of DOM, unable to get working properly in time limit) -->
<script language="javascript">
console.log("I am Javascript!");

var profile_values = document.getElementsByClassName('profile-value');
var total_words = 0;
function countValuesInTableFunction()
{
console.log("I am Javascript!");
var total_values_in_table = 0;

//N.B. complex DOM looping needed to count actual section words for each table value - unable to do so (or refactor) in time limit.
// I think coding a table above has made the process of going via innerHTML for element IDs too complex/unworkable (i.e. to
// count words in each section). DOM loops within loops might be needed to go through all table elements for work count.
total_values_in_table = document.getElementById('numberOfTableValues').innerHTML.length; // Does not give correct result !

//alert(total_values_in_table);
return total_values_in_table;
}

// TODO - Count the number of words in the profile.
// hint - look at what the innerHTML property provides.

document.getElementById('word-count').innerHTML = total_words;
//document.getElementById('rationale').innerHTML = total_words;
</script>