Skip to content

Instantly share code, notes, and snippets.

@grisevg
Created May 21, 2015 17:39
Show Gist options
  • Save grisevg/01c2cd5e06721edd7b34 to your computer and use it in GitHub Desktop.
Save grisevg/01c2cd5e06721edd7b34 to your computer and use it in GitHub Desktop.
puzzle
class Collection {
var arr:Array<Int>;
var i:Int = 0;
public function new(arr:Array<Int>) {
this.arr = arr;
}
public var current(get, set):Int;
function get_current():Int { return arr[i]; }
function set_current(v:Int):Int { return arr[i] = v; }
public function next():Void { if (hasNext()) i++; }
public function prev():Void { if (hasPrev()) i--; }
public function hasNext():Bool { return i < arr.length - 1; };
public function hasPrev():Bool { return i > 0; };
}
class Test {
static function main() {
var originalArray = [10, 5, 0];
var collection = new Collection(originalArray);
sum(collection);
//Last number should be a sum of first two numbers
trace(originalArray[originalArray.length - 1]);
}
static function sum(collection:Collection):Void {
//Can only write your code inside the body of this function
//Can't change signature of this function
//No variable definitions are allowed at all
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment