refactor: remove useless pow_b
This commit is contained in:
parent
2f0224643b
commit
3ad669853e
1 changed files with 3 additions and 6 deletions
|
@ -19,7 +19,7 @@ fn superscript(n: i64) -> String {
|
||||||
let mut combined = String::new();
|
let mut combined = String::new();
|
||||||
for c in n.chars() {
|
for c in n.chars() {
|
||||||
if c == '-' {
|
if c == '-' {
|
||||||
combined.push_str("-");
|
combined.push('-');
|
||||||
} else {
|
} else {
|
||||||
let pos = c.to_digit(10).unwrap();
|
let pos = c.to_digit(10).unwrap();
|
||||||
combined.push(EXPONENTS.chars().nth(pos as usize).unwrap())
|
combined.push(EXPONENTS.chars().nth(pos as usize).unwrap())
|
||||||
|
@ -41,20 +41,17 @@ fn main() {
|
||||||
let k = nums[2];
|
let k = nums[2];
|
||||||
|
|
||||||
let mut pow_a: u32 = k.try_into().unwrap();
|
let mut pow_a: u32 = k.try_into().unwrap();
|
||||||
let mut pow_b: u32 = 0;
|
|
||||||
|
|
||||||
let mut expansion: Vec<String> = vec![];
|
let mut expansion: Vec<String> = vec![];
|
||||||
|
|
||||||
for i in 0..k+1 {
|
for i in 0..k+1 {
|
||||||
let mut end = String::new();
|
let mut end = String::new();
|
||||||
if pow_b != k as u32 {
|
if i != k {
|
||||||
end = format!("x{}", superscript(pow_a.into()));
|
end = format!("x{}", superscript(pow_a.into()));
|
||||||
pow_a -= 1;
|
pow_a -= 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
expansion.push(format!("{} {}", choose(k as i64, i as i64) * (a.pow(pow_a) * b.pow(pow_b)) as i64, end));
|
expansion.push(format!("{} {}", choose(k, i) * (a.pow(pow_a) * b.pow(i as u32)), end));
|
||||||
|
|
||||||
pow_b += 1;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
println!("{}", expansion.join(" + "));
|
println!("{}", expansion.join(" + "));
|
||||||
|
|
Loading…
Reference in a new issue