Data commit
This commit is contained in:
parent
7387c8f97b
commit
cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions
45
Task/Averages-Mode/Jakt/averages-mode.jakt
Normal file
45
Task/Averages-Mode/Jakt/averages-mode.jakt
Normal file
|
|
@ -0,0 +1,45 @@
|
|||
fn mode<T, U>(anon iterable: U) throws -> {T} {
|
||||
mut dictionary = Dictionary<T, u64>()
|
||||
for item in iterable {
|
||||
if dictionary.contains(item) {
|
||||
dictionary[item]++
|
||||
} else {
|
||||
dictionary[item] = 1
|
||||
}
|
||||
}
|
||||
|
||||
mut items = dictionary.iterator()
|
||||
|
||||
let mode = items.next()
|
||||
if not mode.has_value() {
|
||||
let empty_set: {T} = {}
|
||||
return empty_set
|
||||
}
|
||||
|
||||
mut modes = [mode.value()]
|
||||
for item in items {
|
||||
if item.1 > modes[0].1 {
|
||||
modes = [item]
|
||||
} else if item.1 == modes[0].1 {
|
||||
modes.push(item)
|
||||
}
|
||||
}
|
||||
|
||||
mut mode_set: {T} = {}
|
||||
for mode in modes {
|
||||
mode_set.add(mode.0)
|
||||
}
|
||||
|
||||
return mode_set
|
||||
}
|
||||
|
||||
fn main() {
|
||||
println("{}", mode<i64>([1, 3, 6, 6, 6, 6, 7, 7, 12, 12, 17]))
|
||||
println("{}", mode<i64>([1, 1, 2, 4, 4]))
|
||||
|
||||
let empty_array: [i64] = []
|
||||
println("{}", mode<i64>(empty_array))
|
||||
|
||||
let test_string = "abcabbcaca"
|
||||
println("{}", mode<u32>(test_string.code_points()))
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue