-
Notifications
You must be signed in to change notification settings - Fork 153
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit 91da548
Showing
21 changed files
with
253 additions
and
0 deletions.
There are no files selected for viewing
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
#include <iostream> | ||
using namespace std; | ||
|
||
int main(int argc, char** argv) { | ||
cout << "Hello World!" << endl; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
#!/usr/bin/python | ||
print "Hello World!" | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
#include <iostream> | ||
#include <string> | ||
using namespace std; | ||
|
||
int main(int argc, char** argv) { | ||
int my_int = 4; | ||
double my_float = 2.5; | ||
string my_string = "hello"; | ||
|
||
cout << "string: " << my_string // Print the string | ||
<< "\tfloat: " << my_float // Print the float | ||
<< "\tint: " << my_int // Print the int | ||
<< endl; // Print the end of the line | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
#!/usr/bin/python | ||
|
||
my_int = 4 | ||
my_float = 2.5 | ||
my_string = "hello" | ||
|
||
print "string: %s\tfloat: %f\tint: %d" % (my_string, my_float, my_int) | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
#include <iostream> | ||
#include <string> | ||
using namespace std; | ||
|
||
int main(int argc, char** argv) { | ||
int my_variable = 5; | ||
|
||
if(my_variable == 4) { | ||
cout << "my_variable is 4" << endl; | ||
} else { | ||
cout << "my_variable is not 4" << endl; | ||
} | ||
|
||
for(int i = 1; i < 5; i++) { | ||
cout << "i == " << i << endl; | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
#!/usr/bin/python | ||
|
||
my_variable = 5 | ||
|
||
if my_variable == 4: | ||
print "my_variable is 4" | ||
else: | ||
print "my_variable is not 4" | ||
|
||
for i in range(1, my_variable): | ||
print "i == %d" % (i) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
#include <iostream> | ||
#include <vector> | ||
#include <boost/foreach.hpp> | ||
using namespace std; | ||
|
||
int main(int argc, char** argv) { | ||
vector<int> my_list(5); | ||
my_list[0] = 1; | ||
my_list[1] = 2; | ||
my_list[2] = 4; | ||
my_list[3] = 8; | ||
my_list[4] = 16; | ||
|
||
my_list.push_back(32); | ||
|
||
cout << my_list.size() << endl; | ||
|
||
cout << my_list[3] << endl << endl; | ||
|
||
BOOST_FOREACH(int value, my_list) { | ||
cout << value << endl; | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
#!/usr/bin/python | ||
|
||
my_list = [1, 2, 4, 8, 16] | ||
|
||
my_list.append(32) | ||
|
||
print len(my_list) | ||
|
||
print my_list[3] | ||
print "" | ||
|
||
for value in my_list: | ||
print value | ||
|
||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
#include <iostream> | ||
#include <string> | ||
#include <boost/tr1/unordered_map.hpp> | ||
#include <boost/foreach.hpp> | ||
using namespace std; | ||
using namespace std::tr1; | ||
|
||
int main(int argc, char** argv) { | ||
unordered_map<string,int> my_dict; | ||
my_dict["alan"] = 22; | ||
my_dict["bill"] = 45; | ||
my_dict["chris"] = 17; | ||
my_dict["dan"] = 27; | ||
|
||
my_dict["eric"] = 33; | ||
|
||
cout << my_dict.size() << endl; | ||
|
||
cout << my_dict["chris"] << endl << endl; | ||
|
||
// Boost foreach can not use pairs directly, so we must define a type | ||
// StringIntPair | ||
typedef pair<string,int> StringIntPair; | ||
|
||
BOOST_FOREACH(StringIntPair key_value, my_dict) { | ||
cout << key_value.first << " --> " << key_value.second << endl; | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
#!/usr/bin/python | ||
|
||
my_dict = {"alan": 22, "bill": 45, "chris": 17, "dan": 27} | ||
|
||
my_dict["eric"] = 33 | ||
|
||
print len(my_dict) | ||
print my_dict["chris"] | ||
|
||
if "dan" in my_dict: | ||
print "dan exists in my_dict" | ||
|
||
for foo, bar in sorted(my_dict.items()): | ||
print "%s --> %r" % (foo, bar) | ||
|
||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
#!/usr/bin/python | ||
|
||
from collections import defaultdict | ||
|
||
my_dict = defaultdict(lambda: 0) | ||
|
||
my_dict["eric"] = 33 | ||
|
||
print my_dict["eric"] | ||
print my_dict["fred"] | ||
|
||
for foo, bar in sorted(my_dict.items()): | ||
print "%s --> %r" % (foo, bar) | ||
|
||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
#include <iostream> | ||
#include <string> | ||
#include <vector> | ||
#include <boost/algorithm/string.hpp> | ||
#include <boost/foreach.hpp> | ||
using namespace std; | ||
using namespace boost; | ||
|
||
int main(int argc, char** argv) { | ||
|
||
string sentence = "this is a pen"; | ||
vector<string> words; | ||
split(words, sentence, is_any_of(" ")); | ||
|
||
BOOST_FOREACH(string word, words) { | ||
cout << word << endl; | ||
} | ||
|
||
cout << boost::algorithm::join(words, " ||| ") << endl; | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
#!/usr/bin/python | ||
|
||
import string | ||
|
||
sentence = "this is a pen" | ||
words = sentence.split(" ") | ||
|
||
for word in words: | ||
print word | ||
|
||
print string.join(words, " ||| ") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
#include <iostream> | ||
using namespace std; | ||
|
||
int add_and_abs(int x, int y) { | ||
int z = x + y; | ||
if(z >= 0) | ||
return z; | ||
else | ||
return z * -1; | ||
} | ||
|
||
int main(int argc, char** argv) { | ||
cout << add_and_abs(-4, 1) << endl; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
#!/usr/bin/python | ||
|
||
def add_and_abs(x, y): | ||
z = x + y | ||
if z >= 0: | ||
return z | ||
else: | ||
return z * -1 | ||
|
||
def test_add_and_abs(): | ||
if add_and_abs(3, 1) != 4: | ||
print "add_and_abs(3, 1) != 4 (== %d)" % add_and_abs(3, 1) | ||
return 0 | ||
if add_and_abs(-4, 1) != 3: | ||
print "add_and_abs(-4, 1) != 3 (== %d)" % add_and_abs(-4, 1) | ||
return 0 | ||
return 1 | ||
|
||
print test_add_and_abs() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
#include <iostream> | ||
#include <fstream> | ||
using namespace std; | ||
|
||
int main(int argc, char** argv) { | ||
ifstream my_file(argv[1]); | ||
string line; | ||
while(getline(my_file, line)) { | ||
if(line.length() != 0) { | ||
cout << line << endl; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
#!/usr/bin/python | ||
|
||
import sys | ||
my_file = open(sys.argv[1], "r") | ||
|
||
for line in my_file: | ||
|
||
line = line.strip() | ||
|
||
if len(line) != 0: | ||
print line |