Skip to content

Instantly share code, notes, and snippets.

@RafeHatfield
Last active October 11, 2017 22:02
Show Gist options
  • Save RafeHatfield/51d2505a89571e1afb39d8d7683cc7e9 to your computer and use it in GitHub Desktop.
Save RafeHatfield/51d2505a89571e1afb39d8d7683cc7e9 to your computer and use it in GitHub Desktop.
These aren't designed to be difficult, they are designed to showcase coding style. Please take the time you need to complete your answers to a quality that you would be comfortable submitting for a code review (i.e. production ready). Feel free to email me if you have any questions.
Question 1:
With the array (1,2,3,4,5,6), write a recursive function that outputs:
<1>
<2>
<3>
<4>
<5>
<6>
</6>
</5>
</4>
</3>
</2>
</1>
Question 2:
Given the following string:
"<a><b><c><d><e><f></f></e></d></c></b></a>"
Write a program to produce the following output:
<a>
<b>
<c>
<d>
<e>
<f>
</f>
</e>
</d>
</c>
</b>
</a>
If the string doesn’t parse to valid xml, print an error.
Question 3:
There are 2 SQL tables, Dogs (id, name, age) and Bones (id, dog_id, animal_type, rating)
Write a SQL query on the tables to return the number of bones each dog has (including 0 if a dog has none), and the average rating of those bones.
Bonus Credit for applicants with a Ruby background: Making some basic assumptions about the relationships between the models, write the ActiveRecord equivalent (i.e. return the same results using ActiveRecord).
Question 4:
a. Create a program that is capable of reading in the contents of a csv file.
b. This csv file holds information about various different regular polygons and circles. Each entry in the csv file holds the name of the shape and the length of it's side, or in the case of a circle, it's radius. You should be able to calculate the perimeter and area of these regular polygons.
eg contents of the csv
square,5
pentagon,3
triangle,2.5
circle,2
c. Your program should output the following:
Shape 1 is a square, with side length 5, having a perimeter of 20 and an area of 25 units square.
...
...
Shape 4 is a circle, with a radius of 2, having a perimeter of 12.57 and an area of 12.57 units square.
Your solution should ideally use objects and classes, and some unit testing. You don't need to adopt a unit test framework, just the basics to feel like you have decent coverage.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment