aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--09-Special-Pythagorean-Triplet/.pyth.py.swpbin12288 -> 0 bytes
-rwxr-xr-x17-Number-Letter-Counts/wordnumsbin0 -> 17432 bytes
-rw-r--r--17-Number-Letter-Counts/wordnums.c (renamed from reworking/wordnums.c)43
-rw-r--r--17-Number-Letter-Counts/wordnums.py7
-rw-r--r--README.md10
-rwxr-xr-xreworking/wordnumsbin17416 -> 0 bytes
6 files changed, 38 insertions, 22 deletions
diff --git a/09-Special-Pythagorean-Triplet/.pyth.py.swp b/09-Special-Pythagorean-Triplet/.pyth.py.swp
deleted file mode 100644
index 73d234c..0000000
--- a/09-Special-Pythagorean-Triplet/.pyth.py.swp
+++ /dev/null
Binary files differ
diff --git a/17-Number-Letter-Counts/wordnums b/17-Number-Letter-Counts/wordnums
new file mode 100755
index 0000000..dc75675
--- /dev/null
+++ b/17-Number-Letter-Counts/wordnums
Binary files differ
diff --git a/reworking/wordnums.c b/17-Number-Letter-Counts/wordnums.c
index 5f48400..e1eaeba 100644
--- a/reworking/wordnums.c
+++ b/17-Number-Letter-Counts/wordnums.c
@@ -11,7 +11,7 @@ const char *teens[10] = {"ten", "eleven", "twelve", "thirteen", "fourteen", "fif
"sixteen", "seventeen", "eighteen", "nineteen"};
const char *tens[10] = {"","", "twenty", "thirty", "forty",
"fifty", "sixty", "seventy", "eighty", "ninety"};
-const char *nd = "AND";
+const char nd[4] = "AND";
int lengthOfName(char *num) {
@@ -19,7 +19,6 @@ int lengthOfName(char *num) {
// minus 1 for null terminator
int digits = strlen(num) - 1;
int n = atoi(num);
- printf("The num is now %s", num, digits);
if(digits == 1) {
word = (char *) ones[n];
printf("%s\n", word);
@@ -37,19 +36,17 @@ int lengthOfName(char *num) {
printf("%s\n", word);
return strlen(word);
} else {
- // since the input to the function expects a null terminator,
+ // since the input to the function expects a string,
// an extra '\n' is needed
char o[2];
int on;
word = (char *) tens[n / 10];
printf("%s", word);
- strncpy(o, &num[1], 2);
- printf("%s", o);
+ memcpy(o, &num[1], 2);
on = lengthOfName(o);
return (strlen(word) + on);
}
} else if(digits == 3) {
- printf("HERE\n\n");
word = (char *) ones[n / 100];
printf("%shundred", word);
if(num[1] == '0' && num[2] == '0') {
@@ -62,12 +59,24 @@ int lengthOfName(char *num) {
printf("%s", nd);
te = lengthOfName(t);
// example: the user inputs, num = 121
- // one hundred AND twenty one
-
- ////this line breaks the program for some reason
- //return (strlen(word) + strlen("hundred") + strlen(nd) + te);
+ // one hundred AND twenty one
+ return (strlen(word) + strlen("hundred") + strlen(nd) + te);
}
+ } else if(digits == 4) {
+ word = (char *) ones[n / 1000];
+ printf("%sthousand", word);
+ if(num[1] == '0' && num[2] == '0' && num[3] == '0') {
+ printf("\n");
+ return strlen(word) + strlen("thousand");
+ } /*else {
+ char h[4];
+ int hu;
+ strncpy(h, &num[1], 3);
+ hu = lengthOfName(h);
+ return (strlen(word) + strlen("thousand") + hu);
+ }*/
}
+
// error condition for debugging, i.e. in case I messed up, return something
return -1;
}
@@ -75,12 +84,20 @@ int lengthOfName(char *num) {
int main() {
// 4 is the max for this example, +1 for null terminator or if user tries to cheat
char n[5];
- int out;
+ int out = 0;
printf("Number from 1 to 1000: ");
fgets(n, 10, stdin);
if(atoi(n) > 1000)
return printf("only up to 1000 in this example, sorry :(\n");
- out = lengthOfName(n);
- printf("%d Characters... wow you'll hurt your hands typing that!\n", out);
+ // Test code to make sure the function works
+ //out = lengthOfName(n);
+ //printf("%d Characters... wow you'll hurt your hands typing that!\n", out);
+
+ for(int i = 1; i <= atoi(n); i++){
+ char curr[5];
+ sprintf(curr, "%d\n", i);
+ out += lengthOfName(curr);
+ }
+ printf("Sum of charachters: %d\n", out);
return 0;
}
diff --git a/17-Number-Letter-Counts/wordnums.py b/17-Number-Letter-Counts/wordnums.py
index 34b5705..168e1c4 100644
--- a/17-Number-Letter-Counts/wordnums.py
+++ b/17-Number-Letter-Counts/wordnums.py
@@ -1,10 +1,7 @@
-import PIL
-import math
-
-ones = ["", "one", "two", "three", "four",
+ones = ["","one", "two", "three", "four",
"five", "six", "seven", "eight", "nine"]
weirdos = ["thirteen", "twelve", "eleven", "ten"]
-tens = ["", "teen", "twenty", "thirty", "forty",
+tens = ["","teen", "twenty", "thirty", "forty",
"fifty", "sixty", "seventy", "eighty", "ninety"]
nd = "AND"
diff --git a/README.md b/README.md
index 9e888da..f8209ba 100644
--- a/README.md
+++ b/README.md
@@ -11,10 +11,12 @@ forces you to think up more efficient solutions :)
Some python solutions I had to remove since they don't work in Python 3 anymore.
Most were easy to update, but a few I couldn't figure out.
-Improving organization of these day by so apologies if it's not up to snuff!
+Improving organization of these day by so apologies if it's not up to snuff! The binaries
+included were compiled on Debian so sorry, Windows users.
-PLEASE do not use these solutions to cheat through the site! These are only provided
-as resource for you to learn when you get suck, you do not need to copy my solutions.
+*PLEASE* do not use these solutions to cheat through the site! These are only provided
+as resource for you to learn when you get stuck, you do not need to copy my solutions.
Please re-write my solutions in another language. Or if you can't, at least go and
retype each line, renaming the variables so they make sense to you (I was kind of
-deliberately cryptic).
+deliberately cryptic). Or even better, write a prettier solution! Some these are kind of
+inelegant. They get the job done but...
diff --git a/reworking/wordnums b/reworking/wordnums
deleted file mode 100755
index f30a9da..0000000
--- a/reworking/wordnums
+++ /dev/null
Binary files differ