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
10 changes: 7 additions & 3 deletions README
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
Welcome to the Fall 2011 Code Contest

The Challenge:
Given any startomg number between 1 and 99, there is a sequence of numbers from that starting number to the number 4. The sequences always end at 4 and 4 leads to itself. The sequence is always the same for a given starting number. Examples of the sequence are:
Given any startimg number between 1 and 99, there is a sequence of numbers from that starting number to the number 4. The sequences always ends at 4 as 4 leads to itself. The sequence is always the same for a given starting number. Examples of the sequence are:

12 -> 6 -> 3 -> 5 -> 4 -> 4
1 -> 3 -> 5 -> 4 -> 4
35 -> 10 -> 3 -> 5 -> 4 -> 4
61 -> 8 -> 5 -> 4 -> 4
72 -> 10 -> 3 -> 5 -> 4 -> 4

The challenge is made up of two parts.
The challenge consists of two parts.
* Discover the algorithm that describes the number sequence.
* Submit working code that generates the sequence for all numbers between 1 and 99.

Expand All @@ -29,9 +30,12 @@ How to submit an entry:
1. Create an account on GitHub (http://github.com)
2. Fork the project: https://github.com/dcumberlandshopatron/Fall-2011-Code-Contest
If you are new to github, they have instructions at http://help.github.com/fork-a-repo/
3. Commit your code to your fork of the code contest
3. Create a directory in the project with your team name. Add all your code under this directory.
3. Commit your code to your fork of the code contest. You will want to wait until September 30th to push your solution to github.
4. Send us a pull request (http://help.github.com/send-pull-requests/). Only submitions with a pull request submitted will be accepted. The submitted code must include the name and email address of all contributors as comments in the code.

No submitions will be accepted after September 30th.


Accepted languages:
Java
Expand Down
22 changes: 22 additions & 0 deletions slotter/Builder.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
/* Fall 2011 Code Contest
* @author Tyler Shopshire (tshopshi@calpoly.edu)
* @author Michele Jenkins (mkjenkin@calpoly.edu)
*
*/

public class Builder
{
public static void main(String[] args)
{
int[] numLetters = new int[99];
NumbersToEnglish n2e = new NumbersToEnglish();

for (int i = 1; i < 100; i++)
{
String numEnglish = n2e.convert(i);
System.out.print(numEnglish.length() + ",");
}
System.out.print("\n");
}

}
21 changes: 21 additions & 0 deletions slotter/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# Fall 2011 Code Contest
# @author Tyler Shopshire (tshopshi@calpoly.edu)
# @author Michele Jenkins (mkjenkin@calpoly.edu)

CC=gcc
CFLAGS=-Wall -g -ansi -pedantic -D_XOPEN_SOURCE=500
LDFLAGS=

ALL= solver builder

all: $(ALL)

solver: solver.c
$(CC) $(CFLAGS) -o $@ $<

builder: Builder.java
javac $<

clean:
rm -f core* *.o *.class $(ALL)

29 changes: 29 additions & 0 deletions slotter/NumbersToEnglish.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
/* Fall 2011 Code Contest
* @author Tyler Shopshire (tshopshi@calpoly.edu)
* @author Michele Jenkins (mkjenkin@calpoly.edu)
*
*/

public class NumbersToEnglish {
static String[] unique = { "zero", "one", "two", "three", "four", "five", "six",
"seven", "eight", "nine", "ten", "eleven", "twelve", "thirteen",
"fourteen", "fifteen", "sixteen", "seventeen", "eighteen", "nineteen" };
static String[] tens = { "twenty", "thirty", "forty", "fifty", "sixty", "seventy", "eighty", "ninety"};

// convert a value < 100 to English.
public static String convert(int num) {
if (num < 20)
return unique[num];
for (int v = 0; v < tens.length; v++) {
String tDigit = tens[v];
int dval = 20 + 10 * v; //Start at 20
if (dval + 10 > num) {
if ((num % 10) != 0)
return tDigit + unique[num % 10];
return tDigit;
}
}
return "Fail\n";
}

}
19 changes: 19 additions & 0 deletions slotter/README.TXT
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
PROJECT TITLE: Fall 2011 Code Contest

AUTHORS: Tyler Shopshire (tshopshi@calpoly.edu)
Michele Jenkins (mkjenkin@calpoly.edu)

VERSION, DATE: v1, 09/26/2011

INFORMATION: The java files are used to generate the array map seen in solver.c
We copy pasted this array map into solver.c to save execution time,
instead of building the list at Runtime.
The algorithm to calculate and display the sequence are in solver.c
Our c file does not do any checks for valid input which is intentional for speed.
The program will not run correctly if an incorrect input is given.

HOW TO RUN: First, compile the code - 'make'
Display the array map for 1-99 - 'java Builder'
Execute the algorithm - './solver n' where 1 <= n <= 99


47 changes: 47 additions & 0 deletions slotter/solver.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
/* Fall 2011 Code Contest
* @author Tyler Shopshire (tshopshi@calpoly.edu)
* @author Michele Jenkins (mkjenkin@calpoly.edu)
*
*/

#include <stdio.h>
#include <stdlib.h>

int main(int argc, char * argv[])
{
/* Grabs the argument and converts it to
* to its integer representaion
*/
int num = atoi(argv[1]);

/* Array that maps the numbers 1-99 to the amount of
* letters in the English word with that number
* Excludes Hyphens
*/
int map[99] = {3, 3, 5, 4, 4, 3, 5, 5, 4, /*Numbers 1-9 */
3, 6, 6, 8, 8, 7, 7, 9, 8, 8, /* 10-19 */
6, 9, 9,11,10,10, 9,11,11,10, /* 20-29 */
6, 9, 9,11,10,10, 9,11,11,10, /* 30-39 */
5, 8, 8,10, 9, 9, 8,10,10, 9, /* 40-49 */
5, 8, 8,10, 9, 9, 8,10,10, 9, /* 50-59 */
5, 8, 8,10, 9, 9, 8,10,10, 9, /* 60-69 */
7,10,10,12,11,11,10,12,12,11, /* 70-79 */
6, 9, 9,11,10,10, 9,11,11,10, /* 80-89 */
6, 9, 9,11,10,10, 9,11,11,10}; /* 90-99 */


/* The algorithm prints the current number in the sequence
* and then the next number is assigned by accessing the array
* at the current number - 1. (0 based)
*/
while (num != 4)
{
printf("%d -> ", num);
num = map[num-1];
}

printf("%d -> %d\n", num, map[num-1]);

return 0;

}