Relative Frequency by kaeso

fn main() {\x0d
\x09for io::stdin().each_line() |line| {\x0d
\x09\x09let mut total = 0.0;\x0d
\x09\x09let mut count = 0.0;\x0d
\x09\x09let pivot=line.char_at(0);\x0d
\x09\x09for str::each_char(line.slice(2, line.char_len())) |c| {\x0d
\x09\x09\x09total += 1.0;\x0d
\x09\x09\x09if c == pivot {\x0d
\x09\x09\x09\x09count += 1.0;\x0d
\x09\x09\x09};\x0d
\x09\x09};\x0d
\x09\x09io::println(fmt!("%0.6f", count/total));\x0d
\x09}\x0d
}\x0d

Note that non-ascii characters in the above source code will be escaped (such as \x9f).

download

return to the top page