use super::funejson::Value; /// B = S x S x D over the spells given. /// /// # Panics /// Panics if a spell is shorter than one day. pub fn bradford_factor(spell_days: &[i64]) -> BradfordFactor { let mut days = 0; for &d in spell_days { if d < 1 { panic!("each spell must be at least one whole day, received {}", d); } days += d; } let spells = spell_days.len() as i64; BradfordFactor { spells, days, score: spells * spells * days } } pub fn fune_vector(args: &[Value]) -> Value { let spells: Vec = args[0] .as_arr() .iter() .map(|v| match v { Value::Float(f) => panic!("each spell must be at least one whole day, received {}", f), other => other.as_i64(), }) .collect(); let b = bradford_factor(&spells); Value::obj(vec![ ("spells", Value::Int(b.spells)), ("days", Value::Int(b.days)), ("score", Value::Int(b.score)), ]) }