Skip to content

Commit

Permalink
let it begin
Browse files Browse the repository at this point in the history
  • Loading branch information
djp424 committed Oct 24, 2016
0 parents commit 660b622
Show file tree
Hide file tree
Showing 10 changed files with 194 additions and 0 deletions.
10 changes: 10 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# Ignore all
*

# Unignore anything with extention
!*/
!*.*

# Except for the following
*.DS_Store
*.class
29 changes: 29 additions & 0 deletions concepts/1_arrays_and_strings/unique_string/unique.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
public class unique {

public static void main(String[] args) {
System.out.println(is_unique( "abcdefghijklmnopqrstuvwxyz" )); // true
System.out.println(is_unique( "abcdefghijklmnopqrstuvwxyzz" )); // false
System.out.println(is_unique( "aa" )); // false
System.out.println(is_unique( "aba" )); // false
System.out.println(is_unique( "aaaaaaaaaaaaaaaaaaaaaaaaaaa" )); // false
System.out.println(is_unique( " " )); // false
System.out.println(is_unique( " " )); // true
}

public static boolean is_unique(String str) {
if (str.length() > 128) { // assume ascii, not unicode
return false;
}

boolean[] alf = new boolean[128];
for (int i = 0; i < str.length(); i++) {
int val = str.charAt(i);
if (alf[val]) {
return false;
}
alf[val] = true;
}
return true;
}

}
30 changes: 30 additions & 0 deletions concepts/1_arrays_and_strings/unique_string/unique.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
<?php

echo is_unique( 'abcdefghijklmnopqrstuvwxyz' ) . "\n"; // true
echo is_unique( 'abcdefghijklmnopqrstuvwxyzz' ) . "\n"; // false
echo is_unique( 'aa' ) . "\n"; // false
echo is_unique( 'aba' ) . "\n"; // false
echo is_unique( 'aaaaaaaaaaaaaaaaaaaaaaaaaaa' ) . "\n"; // false
echo is_unique( ' ' ) . "\n"; // false
echo is_unique( ' ' ) . "\n"; // true

function is_unique( $string ) {
$strlen = strlen( $string ); // calculate once instead of twice

if ( 128 < $strlen ) { // TODO understand the difference between ascii and unicode
return 'false';
}

$alf = array();
for ( $i = 0; $i <= $strlen; $i++ ) { // not foreach
$char = substr( $string, $i, 1 );

if ( ! $alf[ $char ] ) { // true (already set)
$alf[ $char ] = 'true';
} else { // false
return 'false';
}
}

return 'true';
}
23 changes: 23 additions & 0 deletions concepts/1_arrays_and_strings/unique_string/unique.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
def is_unique( str ):
strlen = len( str );

if strlen > 128:
return;

checker = []

for letter in str:
checker.append( letter );

if len(checker) > len(set(checker)):
return 'false'

return 'true'

print is_unique("abcdefghijklmnopqrstuvwxyz"); # true
print is_unique("abcdefghijklmnopqrstuvwxyzz"); # false
print is_unique("aa"); # false
print is_unique("aba"); # false
print is_unique("aaaaaaaaaaaaaaaaaaaaaaaaaaa"); # false
print is_unique(" "); # false
print is_unique(" "); # true
21 changes: 21 additions & 0 deletions concepts/2_linked_lists/1_single_linked/single.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
// gcc -o single single.c

#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <stdbool.h>

struct node {
int data;
int key;
struct node *next;
};

struct node *head = NULL;
struct node *current = NULL;

int main(void) {
printf("Original List: ");
printf("Coming Soon!\n");
return 0;
}
37 changes: 37 additions & 0 deletions concepts/2_linked_lists/1_single_linked/single.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
import java.util.*;

public class single {
public static void main(String args[]) {
LinkedList<String> ll = new LinkedList<String>(); // You should use <String> here

// add
ll.add("J");
ll.add("U");
ll.add("S");
ll.add("T");
ll.add("I");
ll.add("C");
ll.add("E");
ll.addLast("Parsons");
ll.addFirst("David");
ll.add(1, "to the");
ll.addLast("III");
ll.addLast("III");
System.out.println("Linked List after add: " + ll);

// remove
ll.remove("III"); // this only removes one of the III node's above
ll.remove(1); // remove from position 1 (the second node)
System.out.println("Linked List after remove: " + ll);

// remove first and last
ll.removeFirst();
ll.removeLast();
System.out.println("Linked List after removing first and last: " + ll);

// get and set a value
Object temp = ll.get(2);
ll.set(2, (String) temp + " is same same but different but still same");
System.out.println("Linked List after changing second element: " + ll);
}
}
17 changes: 17 additions & 0 deletions concepts/2_linked_lists/1_single_linked/single_simple.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# Empty list
thelist = []

# add values to list
for i in range(0, 6):
thelist.append(i) # add value to array

thelist.append(1234)
thelist.append(1235)
thelist.append(1236)
thelist.append(1237)
thelist.append(1238)
thelist.append(1239)

# print list
for i in thelist:
print "Current Value: %d" % i
9 changes: 9 additions & 0 deletions language/php/preg/preg.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<?php

$input = '[wibbitz id="b40d336b69af74f6ca51416b177a23858" autoplay="false"]';

if ( preg_match( '\[[a-z]+.*\]', $input ) ) {
echo 'pass';
} else {
echo 'fail';
}
9 changes: 9 additions & 0 deletions language/php/preg/strpos.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<?php

$input = '[wibbitz id="b40d336b69af74f6ca51416b177a23858" autoplay="false"]';

if ( 0 === strpos( $input, '[' ) && strlen( $input ) - 1 === strpos( $input, ']' ) ) {
echo 'pass';
} else {
echo 'fail';
}
9 changes: 9 additions & 0 deletions language/php/preg/substr.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<?php

$input = '[wibbitz id="b40d336b69af74f6ca51416b177a23858" autoplay="false"]';

if ( '[' === substr( $input, 0, 1 ) && ']' === substr( $input, -1 ) ) {
echo 'pass';
} else {
echo 'fail';
}

0 comments on commit 660b622

Please sign in to comment.