const DICT: [&str; 24] = [
"N", "o m", "ore", " bottle", "s", " of beer", " on", " th", "e ", "wall", ", ", "n", ".\n", "Go to", "st", " and ", "buy som", "m", "99", "Take", " it ", "down", "pass", "around", ];
trait CalculateLength {
fn calculate_length(&self) -> usize;
}
struct Indices<'a>(&'a [usize]);
impl CalculateLength for Indices<'_> {
fn calculate_length(&self) -> usize {
self.0.iter().fold(0, |length, index| length + DICT[*index].len())
}
}
struct IndicesWithPrefixes<'a>(&'a [(&'a str, Indices<'a>)]);
impl CalculateLength for IndicesWithPrefixes<'_> {
fn calculate_length(&self) -> usize {
self.0.iter().fold(0, |a, (prefix, indices)| a + prefix.len() + indices.calculate_length())
}
}
impl IndicesWithPrefixes<'_> {
fn generate_verse(&self) -> String {
let mut out = String::with_capacity(self.calculate_length());
self.0.iter().for_each(|(prefix, indices)| {
out.push_str(prefix);
indices.0.iter().for_each(|index| out.push_str(DICT[*index]));
});
out
}
}
pub fn verse(n: u32) -> String {
match n {
0 => {
let indices = Indices(&[0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 1, 2, 3, 4, 5, 12, 13, 7, 8, 14, 2, 15, 16, 8, 17, 2, 10, 18, 3, 4, 5, 6, 7, 8, 9, 12]);
let mut out = String::with_capacity(indices.calculate_length());
indices.0.iter().for_each(|index| out.push_str(DICT[*index]));
out
}
1 => {
let n_string = n.to_string();
IndicesWithPrefixes(&[(&n_string, Indices(&[3, 5, 6, 7, 8, 9, 10])), (&n_string, Indices(&[3, 5, 12, 19, 20, 21, 15, 22, 20, 23, 10, 11, 1, 2, 3, 4, 5, 6, 7, 8, 9, 12]))]).generate_verse()
}
2 => {
let (n_string, m_string) = (n.to_string(), (n - 1).to_string());
IndicesWithPrefixes(&[(&n_string, Indices(&[3, 4, 5, 6, 7, 8, 9, 10])), (&n_string, Indices(&[3, 4, 5, 12, 19, 6, 8, 21, 15, 22, 20, 23, 10])), (&m_string, Indices(&[3, 5, 6, 7, 8, 9, 12]))]).generate_verse()
}
_ => {
let (n_string, m_string) = (n.to_string(), (n - 1).to_string());
IndicesWithPrefixes(&[(&n_string, Indices(&[3, 4, 5, 6, 7, 8, 9, 10])), (&n_string, Indices(&[3, 4, 5, 12, 19, 6, 8, 21, 15, 22, 20, 23, 10])), (&m_string, Indices(&[3, 4, 5, 6, 7, 8, 9, 12]))]).generate_verse()
}
}
}
pub fn sing(start: u32, end: u32) -> String {
"".to_string()
}