Skip to content

Instantly share code, notes, and snippets.

View courtneyfaulkner's full-sized avatar

Courtney Faulkner courtneyfaulkner

View GitHub Profile
@courtneyfaulkner
courtneyfaulkner / BinaryTreeBottomView.groovy
Created September 6, 2017 04:30
[BinaryTreeBottomView] #practice
class BinaryTreeBottomView {
public static void main(String[] args) {
Node root = new Node(20)
root.left = new Node(8)
root.right = new Node(22)
root.left.left = new Node(5)
root.left.right = new Node(3)
root.right.left = new Node(4)
root.right.right = new Node(25)
root.left.right.left = new Node(10)
@courtneyfaulkner
courtneyfaulkner / ZigZag.groovy
Created September 6, 2017 04:30
[ZigZag] #practice
class ZigZag {
/*
Example:
Input: arr[] = {4, 3, 7, 8, 6, 2, 1}
Output: arr[] = {3, 7, 4, 8, 2, 6, 1}
Input: arr[] = {1, 4, 3, 2}
Output: arr[] = {1, 4, 2, 3}
*/
static void main(String[] args) {
@courtneyfaulkner
courtneyfaulkner / SortedArrays.groovy
Created September 6, 2017 04:29
[SortedArrays] #practice
class SortedArrays {
/*
For Example
A = {10, 15, 25}
B = {1, 5, 20, 30}
The resulting arrays are:
10 20
10 20 25 30
10 30
@courtneyfaulkner
courtneyfaulkner / CountTriplets.groovy
Created September 6, 2017 04:28
[CountTriplets] #practice
class CountTriplets {
static void main(String[] args) {
// (-2, 0, 1) and (-2, 0, 3) == 2
println "count=${count([-2, 0, 1, 3] as int[], 2)}"
// (1, 3, 4), (1, 3, 5), (1, 3, 7), (1, 4, 5) == 4
println "count=${count([5, 1, 3, 4, 7] as int[], 12)}"
// (2, 3, 4), (2, 3, 5), (2, 3, 8), (2, 4, 5), (3, 4, 5) == 5
println "count=${count([9, 5, 3, 2, 4, 8] as int[], 14)}"
@courtneyfaulkner
courtneyfaulkner / FizzBuzz.groovy
Created September 6, 2017 04:28
[FizzBuzz] #practice
class FizzBuzz {
static void main(String[] args) {
(1..100).each {println((it % 3 ? '' : 'fizz') + (it % 5 ? '' : 'buzz') ?: it)}
}
}
@courtneyfaulkner
courtneyfaulkner / Palindrome.groovy
Created September 6, 2017 04:27
[Palindrome] #practice
import java.util.regex.Matcher
class Palindrome {
static void main(String[] args) {
def stuff = 'This, stuff ala ffuts, is a sentence to isPalindrome (tacocat)!!ONE!1!'
findPalindromes(stuff, true, true)
println '=================='
findPalindromes(stuff, true, true, true)
println '=================='
findPalindromes(stuff, false, true)
@courtneyfaulkner
courtneyfaulkner / ReverseArray.groovy
Created September 6, 2017 04:24
[ReverseArray] #practice
class ReverseArray {
/*
Input: str = "a,b$c"
Output: str = "c,b$a"
Note that $ and , are not moved anywhere.
Only subsequence "abc" is reversed
Input: str = "Ab,c,de!$"
Output: str = "ed,c,bA!$"
*/
@courtneyfaulkner
courtneyfaulkner / ReverseNumberArray.groovy
Created September 6, 2017 04:23
[ReverseNumberArray] #practice
class ReverseNumberArray {
static void main(String[] args) {
int[] arr = [1, 2, 3, 4, 5, 6, 7, 8, 9]
println "original: $arr"
println "reversed: ${reverse(arr, 0, arr.size() - 1)}"
}
static int[] reverse(int[] arr, int left, int right) {
int temp = arr[right]
arr[right] = arr[left]
@courtneyfaulkner
courtneyfaulkner / RPNCalculator.groovy
Created September 6, 2017 04:22
[RPNCalculator] #practice
import java.util.*;
class RpnCalculator {
static void main(String[] args) {
Calculator calc = new Calculator()
'4 6 3 + 9 3 - * 1 1 ^ - +'.split(' ').each {calc.enter(it)}
}
}
class Calculator {
@courtneyfaulkner
courtneyfaulkner / 1_root-docker_start_master.sh
Created February 14, 2017 18:50
Create a Jenkins instance in DDC
#!/bin/bash
# put this in root/docker_start_master.sh
# Make files owned by jenkins (not root). This didn't work when done from the Dockerfile build.
chown -R jenkins:jenkins /var/jenkins_home
# Need to make sure docker.sock is in the "docker" group so that the "jenkins" user can use it:
chown root:docker /var/run/docker.sock
# Work-around a problem we're having with the container (running as a UCP service) not having DNS set-up: