Skip to content

Commit 8304b13

Browse files
author
wesLaptop
committedAug 22, 2015
first commit
0 parents  commit 8304b13

File tree

9 files changed

+137
-0
lines changed

9 files changed

+137
-0
lines changed
 

‎228easy/Makefile

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
order: order.c
2+
c99 -Wall -Werror order.c -o order

‎228easy/order.c

+66
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
#include <stdio.h>
2+
#include <stdlib.h>
3+
#include <string.h>
4+
#include <ctype.h>
5+
6+
int is_ordered(char* word);
7+
int is_reverse_ordered(char* word);
8+
char* output_message(char* word);
9+
10+
int main(int argc, char* argv[]) {
11+
12+
if (argc != 2) {
13+
printf("Must provide text file as only command line argument!\n");
14+
}
15+
16+
FILE* infile = fopen(argv[1], "r");
17+
18+
if (infile) {
19+
char line[80];
20+
while(fgets(line, 80, infile)) {
21+
// Strip the \n from the end of the word
22+
char word[strlen(line) - 1];
23+
for (int i = 0; i < strlen(line) - 1; i++) {
24+
word[i] = line[i];
25+
}
26+
printf("%s %s\n", word, output_message(word));
27+
}
28+
}
29+
return 0;
30+
}
31+
32+
int is_ordered(char* word) {
33+
int low = 'a';
34+
for (int i = 0; i < strlen(word); i++) {
35+
int c = tolower(word[i]);
36+
if (c >= low) {
37+
low = c;
38+
} else {
39+
return 0;
40+
}
41+
}
42+
return 1;
43+
}
44+
45+
int is_reverse_ordered(char* word) {
46+
int high = 'z';
47+
for (int i = 0; i < strlen(word); i++) {
48+
int c = tolower(word[i]);
49+
if (c <= high) {
50+
high = c;
51+
} else {
52+
return 0;
53+
}
54+
}
55+
return 1;
56+
}
57+
58+
char* output_message(char* word) {
59+
if (is_ordered(word)) {
60+
return "IN ORDER";
61+
} else if (is_reverse_ordered(word)) {
62+
return "REVERSE ORDER";
63+
} else {
64+
return "NOT IN ORDER";
65+
}
66+
}

‎228easy/readme.md

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
[Letters in Alphabetical Order](https://www.reddit.com/r/dailyprogrammer/comments/3h9pde/20150817_challenge_228_easy_letters_in/)

‎228easy/words.txt

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
billowy
2+
biopsy
3+
chinos
4+
defaced
5+
chintz
6+
sponged
7+
bijoux
8+
abhors
9+
fiddle
10+
begins
11+
chimps
12+
wronged

‎228hard/golomb.py

+37
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
import itertools
2+
import time
3+
4+
5+
def check(mark_combo):
6+
diffs = set()
7+
for pair in itertools.combinations(mark_combo, 2):
8+
diff = abs(pair[0] - pair[1])
9+
if diff in diffs:
10+
return False
11+
diffs.add(diff)
12+
return True
13+
14+
15+
def find(order):
16+
found = False
17+
for max_mark in itertools.count(order):
18+
marks = range(0, max_mark)
19+
for mark_combo in [x for x in itertools.combinations(marks, order)]:
20+
if check(mark_combo):
21+
found = True
22+
print(str(order) + ' ' + str(max(mark_combo)) + ' ' +
23+
' '.join(str(mark) for mark in mark_combo))
24+
if found:
25+
return
26+
27+
28+
def main():
29+
for order in [3, 4, 5, 6, 7, 8]:
30+
start = time.clock()
31+
find(order)
32+
elapsed = time.clock() - start
33+
print(elapsed)
34+
35+
36+
if __name__ == '__main__':
37+
main()

‎228hard/readme.md

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
[Golomb Rulers](https://www.reddit.com/r/dailyprogrammer/comments/3hsgr0/08212015_challenge_228_hard_golomb_rulers/)

‎228int/bitcoins.py

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
import requests
2+
import csv
3+
import sys
4+
5+
6+
def main():
7+
market = sys.argv[1]
8+
currency = sys.argv[2]
9+
r = requests.get('http://api.bitcoincharts.com/v1/trades.csv?symbol=' + market + currency)
10+
result = float([row for row in csv.reader(r.text.splitlines())][0][1])
11+
print(result)
12+
return 0
13+
14+
15+
if __name__ == '__main__':
16+
main()

‎228int/readme.md

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
[Use a Web Service to Find Bitcoin Prices](https://www.reddit.com/r/dailyprogrammer/comments/3hj4o2/20150819_challenge_228_intermediate_use_a_web/)

‎readme.md

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
My solutions to [/r/dailyprogrammer](https://www.reddit.com/r/dailyprogrammer/) challenges.

0 commit comments

Comments
 (0)