Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
alexbotello committed Jan 21, 2017
2 parents fd21191 + af73be1 commit 1c5e94a
Show file tree
Hide file tree
Showing 54 changed files with 1,583 additions and 14 deletions.
14 changes: 14 additions & 0 deletions challenge_0/csharp/jfrancis2/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# Challenge 0 - Hello World
###### C#

### 1. Approach to Solving the problem

Output text "Hello World"

### 2. How to compile and run this code

From the /src directory, use `csc.exe hello.cs`

### 3. How this program works

Read the text! Hi :)
13 changes: 13 additions & 0 deletions challenge_0/csharp/jfrancis2/src/hello.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
using System;
namespace HelloWorld
{
class Hello
{
static void Main()
{
Console.WriteLine("Hello World!");
Console.WriteLine("Press any key to exit.");
Console.ReadKey();
}
}
}
16 changes: 16 additions & 0 deletions challenge_0/java/JakeBash/Challenge_0.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
/**
* This class holds the code needed to meet the requirements for Challenge 0 of
* the 2017 Year of Programming.
*
* @author Jake Bashaw
*/
public class Challenge_0
{
/**
* Prints "Hello World" for the user to view
*/
public static void main(String args[])
{
System.out.println("Hello World!");
}
}
1 change: 1 addition & 0 deletions challenge_1/c/tyleroar/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
String reversing in C
33 changes: 33 additions & 0 deletions challenge_1/c/tyleroar/src/strings.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
char *readLine() {
int length = 1;
char *string = NULL;
char c;
while (EOF!=(c=getchar()) && '\r'!=c && '\n' != c) {
string=realloc(string,length);
string[length-1]=c;
length++;
}
string[length-1]='\0';
return string;
}
int main(int argc, char **argv) {
char *input = readLine();
char temp;
int length=0, i=0;
for (temp=input[length]; temp!='\0'; length++) temp=input[length];
length--;
char *output = (char*) malloc(sizeof(char)*(length+1));
if(length==0) {
output[0]='\0';
}
else {
for (i=0; i<length; i++) {
output[i]=input[length-i-1];
}
output[i]='\0';
}
printf("%s\n", output);
}
38 changes: 38 additions & 0 deletions challenge_1/c/xor-eax-eax/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
# Challenge_1
###### C compiled with gcc 4.2.1

### 1. Approch to Solving the problem

Reversing strings in C is a little bit more challenging than
higher level languages. Since basically everything is a pointer
to memory of a particular size, you must make sure that the variables
you're creating have the approprate space. In short, I created two
character arrays and looped through them from opposite directions,
the original's end filling the beginning of the reverse string.

### 2. How to compile and run this code

Make sure that you have gcc installed on your *nix machine. To see if you have
it installed you can type:

```
$ gcc --version
```

Compiling:
```
$ gcc -o challenge1 challenge1.c
```
Or optionally with symbols that aid in debugging.
```
$ gcc -g -o challenge0 challenge0.c
```

### 3. How this program works

After the program has compiled with no errors:
```
$ ./challenge1
olleH
```
28 changes: 28 additions & 0 deletions challenge_1/c/xor-eax-eax/src/challenge1.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
#include <stdio.h>
#include <stdlib.h>
#include <string.h> // for memset

int main()
{
// Initialize a character array with the string you want to reverse.
char helloString[] = "Hello";
// Get length of 0-indexed string, this will be used for index looping
int strSize = strlen(helloString);
// Instantiated character array equal to the size of the original
char revHelloStr[strSize];
// Set the values of the reverse character array to zero, this takes care of the null terminator at the end
memset(revHelloStr, 0, strSize*sizeof(char));
// subtracted one to disclude the null terminator. That is taken care of in revHelloStr by the memset
int i = strSize-1;
int j = 0;
// Perform a count from the front to back of the character array for the reverse string
// while counting from the back of the hello string, skipping the null terminator
for (i,j ; i>=0 && j<=strSize-1 ; i--, j++)
{
revHelloStr[j] = helloString[i];

}
printf("%s",revHelloStr);

return 0;
}
17 changes: 17 additions & 0 deletions challenge_1/csharp/jfrancis2/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# Challenge 1 - Reverse a String
###### C#

### 1. Approach to Solving the problem

I had to work out how to get a string, then make it backwards. Turns out there are inbuilt functions for this.

### 2. How to compile and run this code

From the /src directory, use `csc.exe program.cs`

### 3. How this program works

Takes a string from the console input
Converts to a char array
Uses the 'System.Reverse' function to change the order of the characters
Displays the reversed string
21 changes: 21 additions & 0 deletions challenge_1/csharp/jfrancis2/src/program.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
using System;
namespace YOP2017
{
class Program
{
static void Main(string[] args)
{
Console.WriteLine("Enter a string to reverse: ");
string input = Console.ReadLine();
Console.WriteLine("Your string in reverse: " + Program.reverseString(input));
Console.WriteLine("Press any key to exit.")
Console.ReadKey(true);
}
public static string reverseString(string input)
{
char[] arr = input.ToCharArray();
Array.Reverse(arr);
return new string(arr);
}
}
}
41 changes: 41 additions & 0 deletions challenge_1/java/JakeBash/Challenge_1.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
import java.util.Scanner;

/**
* This class holds the code needed to meet the requirements for Challenge 1 of
* the 2017 Year of Programming.
*
* @author Jake Bashaw
*/
public class Challenge_1
{
/**
* Prints the reversed version of the standard input supplied by the user
*/
public static void main(String args[])
{
System.out.print("> ");
Scanner kb = new Scanner(System.in);
String input = kb.nextLine();
System.out.println(reverseString(input));
}

/**
* Reverses and returns a String
*
* @param input The String to be reversed
*/
public static String reverseString(String input)
{
StringBuilder sb = new StringBuilder(input);
char forChar;
char revChar;
for(int i=0; i<sb.length()/2; i++)
{
forChar = sb.charAt(i);
revChar = sb.charAt(sb.length()-i-1);
sb.setCharAt(i, revChar);
sb.setCharAt(sb.length()-i-1, forChar);
}
return sb.toString();
}
}
24 changes: 24 additions & 0 deletions challenge_10/python/alexbotello/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# Valid Closers
###### Language Version (Python 3.6.0)


For this challenge we implement a list as a stack. As we iterate through the
string input we add every opener found into the stack sequentially.

As the iteration continues onto the closers, check the if closer matches the last
element in our stack. If match is successful, pop the element off the stack and continue.
If any pair fails to match then the string input contains an invalid closer and
the function returns False.

After iteration is complete if our stack is empty then every opener had a valid
closer and the function returns True.


Run ```test.py``` to test code against the unit test.
```
........
----------------------------------------------------------------------
Ran 8 tests in 0.001s
OK
```
35 changes: 35 additions & 0 deletions challenge_10/python/alexbotello/src/closers.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
# Valid Closers

def is_valid_closer(string):
"""
Returns True if every opener has a valid closer
"""
openers = ['[', '(', '{']
closers = [']', ')', '}']
stack = []

for ch in string:
# If there is a closer, but no openers
if not stack and ch in closers:
return False

# Add any opener into the stack
elif ch in openers:
stack.append(ch)

# If the following closers do not pair with the opener popped from stack
# then the function will return False
elif ch == ']':
if stack.pop() != '[':
return False

elif ch == ')':
if stack.pop() != '(':
return False

elif ch == '}':
if stack.pop() != '{':
return False

# Nothing in our stack == True
return not stack
33 changes: 33 additions & 0 deletions challenge_10/python/alexbotello/src/tests.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
import unittest

from closers import is_valid_closer

class Test(unittest.TestCase):

def test1(self):
self.assertEqual(is_valid_closer('{{{{{{{{{adfkjaefia}}}}}}}'), False)

def test2(self):
self.assertEqual(is_valid_closer('{{{{{{{{{[[[[[[kadfa{{{{{{{((({daljfdaf({{{[]}}kaldjfs})})))}}}}}}}]]]]]]}kjfela}}}}}}}}'), True)

def test3(self):
self.assertEqual(is_valid_closer('{{{[}}}}dafda'), False)

def test4(self):
self.assertEqual(is_valid_closer('{{{{{{{{{}}}}}}}}}'), True)

def test5(self):
self.assertEqual(is_valid_closer('[[[[[[[[[kafjalfeianfailfeja;fjai;efa;sfj]]]]]]]]]kjajdain'), True)

def test6(self):
self.assertEqual(is_valid_closer(''), True)

def test7(self):
self.assertEqual(is_valid_closer('((((((fjdalfeja((((alefjalisj(())))))))))))d'), True)

def test8(self):
self.assertEqual(is_valid_closer(')))(((d'), False)


if __name__ == '__main__':
unittest.main()
5 changes: 5 additions & 0 deletions challenge_12/python/slandau3/.vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"python.linting.pylintEnabled": true,
"python.pythonPath": "python3",
"python.formatting.provider": "autopep8"
}
Loading

0 comments on commit 1c5e94a

Please sign in to comment.