From 8384152266468c68bc444d83e8a06c3b001ab374 Mon Sep 17 00:00:00 2001 From: dcumberlandshopatron Date: Tue, 30 Aug 2011 13:30:50 -0700 Subject: [PATCH 1/2] Clarifying rules --- README | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/README b/README index b3ac999..9ec77b8 100644 --- a/README +++ b/README @@ -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. @@ -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 From 6cf758af6f828212965aab2bd3ff9faed4f375ae Mon Sep 17 00:00:00 2001 From: Tyler Shopshire Date: Fri, 30 Sep 2011 17:29:18 -0700 Subject: [PATCH 2/2] Initial commit --- slotter/Builder.java | 22 ++++++++++++++++ slotter/Makefile | 21 ++++++++++++++++ slotter/NumbersToEnglish.java | 29 +++++++++++++++++++++ slotter/README.TXT | 19 ++++++++++++++ slotter/solver.c | 47 +++++++++++++++++++++++++++++++++++ 5 files changed, 138 insertions(+) create mode 100644 slotter/Builder.java create mode 100644 slotter/Makefile create mode 100644 slotter/NumbersToEnglish.java create mode 100644 slotter/README.TXT create mode 100644 slotter/solver.c diff --git a/slotter/Builder.java b/slotter/Builder.java new file mode 100644 index 0000000..a2c23a5 --- /dev/null +++ b/slotter/Builder.java @@ -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"); + } + +} diff --git a/slotter/Makefile b/slotter/Makefile new file mode 100644 index 0000000..0525124 --- /dev/null +++ b/slotter/Makefile @@ -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) + diff --git a/slotter/NumbersToEnglish.java b/slotter/NumbersToEnglish.java new file mode 100644 index 0000000..980df59 --- /dev/null +++ b/slotter/NumbersToEnglish.java @@ -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"; + } + +} diff --git a/slotter/README.TXT b/slotter/README.TXT new file mode 100644 index 0000000..e5e16d9 --- /dev/null +++ b/slotter/README.TXT @@ -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 + + diff --git a/slotter/solver.c b/slotter/solver.c new file mode 100644 index 0000000..259d4bc --- /dev/null +++ b/slotter/solver.c @@ -0,0 +1,47 @@ +/* Fall 2011 Code Contest + * @author Tyler Shopshire (tshopshi@calpoly.edu) + * @author Michele Jenkins (mkjenkin@calpoly.edu) + * + */ + +#include +#include + +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; + +}