Friday, September 10, 2010

Tynt programming assignment (Part 1)

I was a approached by a recruiter for a position at a company in Draper called Tynt.

As part of the hiring process I was given this coding assignment.
Coding Assignment #1
Thank you for your interest in Tynt. As part of our recruitment process we ask candidates to complete a small programming assignment. The assignment is technically easy, but is intended to provide enough scope to allow you to demonstrate your knowledge of good programming practices. Assume that the code you are writing will reside in Tynt's main production codebase.
Development Notes
• There is no time limit to complete this exercise.
• If there are errors in the example, state your assumptions and continue.
• No user interface is required; the program will be run from the console and should
require no command line parameters to execute normally
• Assume that all files (input and output) will be found/created in the same directory as the program executes
• As part of the exercise, you may choose to write unit tests appropriate for the task.
• Use the development tools of your choice, but please write the software in Java.
• You may not use any external libraries with the exception of standard I/O and possibly a unit testing framework.
• You may not use any built-in data structures such as lists, vectors, queues etc. You
must build your solution using basic types such as integers, strings and arrays.
• You may not use any built-in sort or histogram functions.
• Please submit all available aspects of your work (source, buildfiles, executables, test
input/output etc)
• Have Fun!
====================================================================
1) Read an ascii text file named "THire_input.txt" that contains a list of numbers with integer
values, each number separated by a cr/lf
Sample input (THire_input.txt)
6
54
12
22
1
6
2) Sort the numbers in ascending order and write the results to an output file named
"THire_Ascending.txt". Format the file in the same manner as the input file (cr/lf delimiters).
Sample output (THire_Ascending.txt)
1
6
6
12
22
I completed the assignment and submitted my solution but never heard from them, then the recruiter told me they went with someone else. Since I never had the opportunity to hear back from Tynt's hiring team, I decided to blog about my solution and solicit feedback on how I could do a better job.

The assignment tied my hands by not allowing external libraries or built-in Java collections. This is done to make an otherwise simple programming assignment much more labor intensive and error prone in college CS classes. Java loses much of it's value as a programming language when you eliminate the vast libraries available. Ultimately, the code I ended up writing would not belong in an actual enterprise code base precisely because I was required to implement functionality that is provided by the language libraries. Typically you don't roll-your-own implementation of a collection unless you have a very specific need to do it, which this assignment lacks. There was no time limit to complete the exercise (a bit discouraging in that you would think Tynt would have an idea of when they needed to hire the candidate), but that didn't matter because I received five-ten nagging emails from the headhunter asking for status on my progress with it.

On to the implementation, I decided that since this was to be considered code I would put in production, Junit tests were mandatory, as well as a build script. Maven is a fantastic build tool for Java development so I created a new project using Maven as follows:

mvn archetype:create -DgroupId=com.tynt.app -DartifactId=program_assignment


This generated the structure of the project. I edited the maven pom.xml file to add a Junit dependency as well as configure the maven-pmd-plugin, which will evaluate your source and report on potential bugs or bad source formatting. Here is my final pom:

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.tynt.app</groupId>
<artifactId>program_assignment</artifactId>
<packaging>jar</packaging>
<version>1.0-SNAPSHOT</version>
<name>program_assignment</name>
<description>FourGablesGuy's implementation of programming assignment for Tynt. Reading and parsing text files for numbers.</description>
<url>http://maven.apache.org</url>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>2.3.1</version>
<configuration>
<compilerVersion>1.5</compilerVersion>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-pmd-plugin</artifactId>
<version>2.5</version>
<executions>
<execution>
<id>pmd_check</id>
<phase>package</phase>
<goals>
<goal>pmd</goal>
</goals>
</execution>
</executions>
<configuration>
<sourceEncoding>UTF-8</sourceEncoding>
<outputEncoding>UTF-8</outputEncoding>
<targetJdk>1.5</targetJdk>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-resources-plugin</artifactId>
<version>2.4.3</version>
<configuration>
<encoding>UTF-8</encoding>
</configuration>
</plugin>
</plugins>
</build>
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>3.8.1</version>
<scope>test</scope>
</dependency>
</dependencies>
</project>


To build/update the artifact Jar, you simply run:


mvn package


which will compile source files, run any unit tests, and package the final code.

No comments:

About Me

My photo
Lead Java Developer Husband and Father

Tags