Skip to content

Instantly share code, notes, and snippets.

//
// main.cpp
// Programming Assingment 4 - Water Jugs
//
// Created by Zachary Shakked on 10/21/15.
// Copyright © 2015 Zachary Shakked. All rights reserved.
//
#include <iostream>
#include <vector>
@shakked
shakked / main.swift
Last active October 22, 2015 04:38
Jug Problem
//
// main.swift
// Programming Assignment 4 - Water Jugs (Swift)
//
// Created by Zachary Shakked on 10/21/15.
// Copyright © 2015 Zachary Shakked. All rights reserved.
//
import Foundation
{
"quotes": [
{
"author": "Abraham Lincoln",
"quote": "Things may come to those who wait, but only the things left by those who hustle.",
"image": "http://upload.wikimedia.org/wikipedia/commons/1/1b/Abraham_Lincoln_November_1863.jpg"
},
{
"author": "Adam Smith",
"quote": "The great secret of education is to direct vanity to proper objects.",
let group = dispatch_group_create()
dispatch_group_enter(group)
self.analyticCrawler.fetchLikes { (succeeded, likes) -> (Void) in
if succeeded {
self.likes = likes
} else {
self.likes = []
}
dispatch_group_leave(group)
/*******************************************************************************
* Name : stairclimber.cpp
* Author :
* Date :
* Description : Lists the number of ways to climb n stairs.
* Pledge :
******************************************************************************/
#include <iostream>
#include <vector>
#include <algorithm>
func stairs(n: Int) -> [[Int]] {
if n == 0 {
return []
} else if n == 1 {
let one = [[1]] + stairs(n - 1)
let one2 = stairs(n - 1) + [[1]]
return one + one2
} else if n == 2 {
let one = [[1]] + stairs(n - 1)
let two = [[2]] + stairs(n - 2)
gravity.action = { () -> (Void) in
for paintBall in self.paintBalls {
if !contains(self.paintBallsToBeRelocated, paintBall) {
self.drawLineFrom(paintBall.lastPoint, toPoint: paintBall.center, color: paintBall.backgroundColor!, brushWidth: self.paintBallRadius * 2)
paintBall.lastPoint = paintBall.center
if self.shouldRelocatePaintBall(paintBall) {
if !contains(self.paintBallsToBeRelocated, paintBall) {
self.paintBallsToBeRelocated.append(paintBall)
func drawLineFrom(fromPoint: CGPoint, toPoint: CGPoint, color: UIColor, brushWidth: CGFloat) {
UIGraphicsBeginImageContext(view.frame.size)
let context = UIGraphicsGetCurrentContext()
paintCanvas.image?.drawInRect(CGRect(x: 0, y: 0, width: view.frame.size.width, height: view.frame.size.height))
let colorConverted = CIColor(color: color)!
let redComp = colorConverted.red()
let greenComp = colorConverted.green()
let blueComp = colorConverted.blue()