Using Python's built-in defaultdict we can easily define a tree data structure:
def tree(): return defaultdict(tree)
That's it!
// This shows a bug in Swift 2.2 (and 2.3) where `self` gets released in a recursive call | |
extension Dictionary { | |
mutating func append(_ other: [String: AnyObject]) { | |
// 2. After the call 1. below, `other` would have been dealloced in the recursive call :( | |
for (key, value) in other { | |
if let otherSubDict = value as? [String: AnyObject], | |
var selfSubDict = self[key] as? AnyObject as? [String: AnyObject] | |
{ | |
// 1. Make a recursive call |
//: Playground - noun: a place where people can play | |
struct Room: IntegerLiteralConvertible { | |
let number: Int | |
init(integerLiteral value: Int) { | |
number = value | |
} | |
} |
Using Python's built-in defaultdict we can easily define a tree data structure:
def tree(): return defaultdict(tree)
That's it!
import java.util.Random; | |
class Counter { | |
private int c=0; | |
public synchronized void increment() { | |
c++; | |
} | |
public synchronized void decrement() { | |
c--; |
import java.util.Random; | |
class Runner implements Runnable { | |
public void run() { | |
int c = 0; | |
while (c++ < 10000) | |
if (c % 100 == 0) | |
System.out.println("still at " + c); | |
} | |
} |
import java.util.Random; | |
public class ThreadingThings implements Runnable{ | |
int myID; | |
Random gen; | |
public ThreadingThings(int anID) { | |
myID = anID; | |
gen = new Random(); |
#import <Foundation/Foundation.h> | |
@interface MyClass : NSObject | |
@end | |
@implementation MyClass | |
static NSMutableArray *instances; |
totalInversions = 0 | |
countInversions (array, start, end) | |
if (start < end) | |
int mid = (start + end)/2 | |
countInversions(array, start, mid) | |
countInversion(array, mid+1, end) | |
merge(array, start, mid, end) | |
// else do nothing | |
- (BOOL) createRelationshipsForDestinationInstance:(NSManagedObject *) destinationAttendance entityMapping:(NSEntityMapping *)mapping manager:(NSMigrationManager *)manager error:(NSError **)error { | |
NSArray *sourceAttendances = [manager sourceInstancesForEntityMappingNamed:[mapping name] | |
destinationInstances:[NSArray arrayWithObject:destinationAttendance]]; | |
NSManagedObject *sourceAttendance = [sourceAttendances objectAtIndex:0]; | |
NSArray *allStudents = [[[sourceAttendance valueForKey:@"theSchedule"] valueForKey:@"theCourse"] valueForKey:@"students"]; | |
NSArray *presentStudents = [sourceAttendance valueForKey:@"students"]; | |
NSLog(@"For attendance on %@", [sourceAttendance valueForKey:@"date"]); | |
<p>There are three threading problems listed <a href="http://www.d.umn.edu/~cprince/courses/cs5631spring10/lectures/ThreadAndSynch.pdf">here</a>. Do all three of them (separately).</p> | |
<p>This will be due by next Wednesday, Dec. 14th. But, I want you to show me the running code instead of submitting it. Let me know before Monday when you can see me next week.</p> |