March 2014 update

This commit is contained in:
Ingy döt Net 2014-04-02 16:56:35 +00:00
parent 09687c4926
commit a25938f123
1846 changed files with 21876 additions and 5203 deletions

View file

@ -0,0 +1,29 @@
function modes(values)
dict = Dict() # Values => Number of repetitions
modesArray = typeof(values[1])[] # Array of the modes so far
max = 0 # Max of repetitions so far
for v in values
# Add one to the dict[v] entry (create one if none)
if v in keys(dict)
dict[v] += 1
else
dict[v] = 1
end
# Update modesArray if the number of repetitions
# of v reaches or surpasses the max value
if dict[v] >= max
if dict[v] > max
empty!(modesArray)
max += 1
end
append!(modesArray, [v])
end
end
return modesArray
end
println(modes([1,3,6,6,6,6,7,7,12,12,17]))
println(modes((1,1,2,4,4)))

View file

@ -9,9 +9,7 @@
NSCountedSet *seen = [NSCountedSet setWithArray:self];
int max = 0;
NSMutableArray *maxElems = [NSMutableArray array];
NSEnumerator *enm = [seen objectEnumerator];
id obj;
while( (obj = [enm nextObject]) ) {
for ( obj in seen ) {
int count = [seen countForObject:obj];
if (count > max) {
max = count;