M
BAN USERif there's a way to crash the system without sudo - meaning cause kernel panic, then its a security issue. so there can't be a way to do it without sudo.
if i have sudo, i'll download the kernel source code, add a seg fault inside the kernel, compile it, and replace the kernel executable in the filesystem.
sudo reboot and you'll get kernel panic.
number of steps tends to be cube root of the number of balls.
separate the initial set into three groups, one for each side of the scale and one to be kept aside.
if the scale shows equal, you know the lighter one is in the set set aside.
if the scale tips one way, you know the lighter is in the set that the scale tipped away from.
solve recursively.
something like this:
bool findEndianness() {
unsigned int x = 0xAABBCCDD;
char *px = (char *) &x;
char px0 = *px;
char px3 = *(px + 3);
if (px0 == (char) 0xDD && px3 == (char) 0xAA) {
cout << "you're big endian!" << endl;
} else if (px0 == (char) 0xAA && px3 == (char) 0xDD) {
cout << "you're little endian!" << endl;
} else {
cout << "you're mixed" << endl;
}
}
here's how i'd model this:
every resource can be represented using a point labeled r1..rn
for every process pi, that needs resource rj and requires resource rk, draw an edge from rj to rk and label the edge pi.
do this for all the processes.
if a cycle is formed in the graph, then there is a deadlock.
can also add the condition that the cycle must have at least one edge that is labelled differently from the rest of the edges in the cycle. this should always be true as such, since any adjacent edges that are labelled the same should anyways be collapsed.
can't edit previous post. posted again, with better formatting.
need to maintain a linkedlist (besides a usual map) that is ordered by recency. set's and get's move elements accordingly in this linkedlist.
public class Cache<Key, Val> {
private class CacheVal {
public int rank;
public Val val;
public CacheVal(int rank, Val val) {
this.rank = rank;
this.val = val;
}
}
public Cache(int limit) {
this.limit = limit;
}
public Val get(Key key) {
if (this.cache.containsKey(key)) {
CacheVal cacheVal;
// remove existing entry from ranked list
cacheVal = this.cache.get(key);
Key k = this.rankedList.remove(cacheVal.rank);
// add it to the top of the list
this.rankedList.addFirst(k);
return cacheVal.val;
} else {
return null;
}
}
public void set(Key key, Val val) {
// remove existing entry from ranked
if (this.cache.containsKey(key)) {
CacheVal oldVal;
oldVal = this.cache.get(key);
this.rankedList.remove(oldVal.rank);
}
// check if cache is full
if (this.cache.size() == this.limit) {
// make space in cache
Key toRemove = this.rankedList.removeLast();
this.cache.remove(toRemove);
}
// insert new element in cache and ranked list
CacheVal newVal = new CacheVal(0, val);
this.cache.put(key, newVal);
this.rankedList.addFirst(key);
}
private Map<Key, CacheVal> cache = new HashMap<Key, CacheVal>();
private LinkedList<Key> rankedList = new LinkedList<Key>();
private int limit;
}
median is correct. you want to ensure that the *sum* of the distances is the least.
- M March 20, 2011example:
take the following 10 values:
2,2,2,2,2,2,2,2,2,9
mean = 2.7, sum of differences = 12.6
median = 2, sum of differences = 7