Skip to content

Commit

Permalink
Merge pull request YearOfProgramming#141 from Flickdm/master
Browse files Browse the repository at this point in the history
Challenge 0 - Python, Challenge 1 - CPP,  Challenge 2 - Python
  • Loading branch information
Remillardj committed Jan 3, 2017
2 parents f30bf12 + a62baad commit 59546bf
Show file tree
Hide file tree
Showing 7 changed files with 117 additions and 0 deletions.
7 changes: 7 additions & 0 deletions challenge_0/python/flickdm/Readme.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# Challenge_0

Simple Hello_world

I import print_function because in Python2 print was a statement, whereas
starting in python3 print became a function. This line allows for use in both
versions of python.
9 changes: 9 additions & 0 deletions challenge_0/python/flickdm/hello_world.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#
# File: hello_world.py
# Author: Douglas Flick
# 2017Challenge_0

#import print_function for python2.7 support
from __future__ import print_function

print("Hello World!")
4 changes: 4 additions & 0 deletions challenge_1/cpp/flickdm/Readme.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# Challenge 1

We interate over half the length of the string and swap the characters for start
and end and move inwards.
41 changes: 41 additions & 0 deletions challenge_1/cpp/flickdm/src/main.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
#include <iostream>
#include <string.h>


// Prototypes
std::string reverseString(std::string myString);
void swap(char &a, char &b);

int main(int argc, char* argv[]) {

// define our input string
std::string inputString;

// use stdin to grab our string
// *Note using getline will allow us to grab a full sentence
std::getline(std::cin, inputString);
//output our reversal
std::cout << reverseString(inputString) << '\n';

return 0;
}

//swap function by reference
void swap(char &a, char &b) {
char tmp = a;
a = b;
b = tmp;
}

std::string reverseString(std::string inputStr) {
//Grab length
unsigned int inputStrLen = inputStr.length();

//Iterate over half of the length
for(int i=0; i < inputStrLen/2; i++) {
//swap first and last and loop
swap(inputStr[i], inputStr[inputStrLen-1-i]);
}

return inputStr;
}
4 changes: 4 additions & 0 deletions challenge_2/python/flickdm/Readme.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#Challenge_2


The code is mostly self documenting
26 changes: 26 additions & 0 deletions challenge_2/python/flickdm/challenge2.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
# should work with both python2 and python3

def findSingleton(sList):
""" Returns entries that only occured once in list """

# Count dict is used for storing if we've seen a element
# and how many times it occured
count_dict = {}
# Single dict is used for storing which elements we've seen only once
single_dict = {}

# Iterate over every key in our list
for key in sList:
# If the key exists in our count dict
if key in count_dict.keys():
# count up
count_dict[key] += 1
# remove element from single dict
single_dict.pop(key, None)
else:
#initiate key in both dicts
count_dict[key] = 1
single_dict[key] = True

# return the keys in dict
return single_dict.keys()
26 changes: 26 additions & 0 deletions challenge_2/python/flickdm/test.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import unittest

from challenge2 import findSingleton

class TestFindSingleton(unittest.TestCase):
def test_base_case(self):
aList = [2, 3, 4, 2, 3, 5, 4, 6, 4, 6, 9, 10, 9, 8, 7, 8, 10, 7]
bList = [2,'a', 'l', 3, 'l', 4, 'k', 2, 3, 4, 5, 'a', 6, 'c', 4, 'm', 6, 'm', 'k', 9, 10, 9, 8, 7, 8, 10, 7]

self.assertEqual(findSingleton(aList), [5])
self.assertEqual(findSingleton(bList), ['c', 5])

def test_empty(self):
aList = []
bList = [1, 1, 1]

self.assertEqual(findSingleton(aList), [])
self.assertEqual(findSingleton(bList), [])

def test_similiar_ascii(self):
aList = [73, 'I']

self.assertEqual(findSingleton(aList), ['I', 73])

if __name__ == '__main__':
unittest.main()

0 comments on commit 59546bf

Please sign in to comment.