Post History
#7: Post edited
Evaluate a univariate polynomial [FINALIZED]
# Challenge Given a list of n numbers and x, compute $a + bx^1 + cx^{2} + zx^{n-1}$, where a is the first value in the list, b is the second, etc. n is at most 256 and at least 0. The input value(s) can be any 32-bit float Input can be in any format of choice, as long as it is a list of numbers and x. (And this'll likely stay this way, even if input rules change over time) # Test inputs `1.0`, `182` -> `1`<br/> `1.0, 2.0`, `4` -> `9`<br/> `2.5, 2.0`, `0.5` -> `3.5`<br/> `1.0, 2.0, 3.0, 4.0`, `1.5` -> `24.25<br/> # Example ungolfed program (Rust) ```rust // dbg! is a logging function, prints the expression and it's output. // Good for seeing what's happening // Test setup pub fn main() { let inp: &[f32] = &[1.0, 2.0, 3.0, 4.0]; let x: f32 = 1.5; dbg!(evaluate_polynomial(inp, x)); // take inputs, print result } // Actual challenge answer function pub fn evaluate_polynomial(inp: &[f32], x: f32) -> f32 { let mut accum: f32 = 0.0; for (idx, val) in inp.iter().enumerate() { // x.pow(idx) * val accum += dbg!(x.powf(idx as f32) * val); } return accum; } ```
#5: Post edited
Compute a univariate polynomial
- Evaluate a univariate polynomial
NOTE: INCOMPLETE. I’m writing this on a phone because I can’t be bothered to wait.- # Challenge
Given a list of n numbers and x, compute <math>a + bx + cx^{2} + zx^{n-1}</math>, where a is the first value in the list, b is the second, etc. n is at most 256 and at least 0. If a v (TODO: Wording.)Input can be in any format of choice, as long as it is a list of numbers and x.- # Test inputs
`1`, `0` -> `1``1, 2`, `4` -> `9`
- # Challenge
- Given a list of n numbers and x, compute $a + bx^1 + cx^{2} + zx^{n-1}$, where a is the first value in the list, b is the second, etc. n is at most 256 and at least 0. The input value(s) can be any 32-bit float
- Input can be in any format of choice, as long as it is a list of numbers and x. (And this'll likely stay this way, even if input rules change over time)
- # Test inputs
- `1.0`, `182` -> `1`<br/>
- `1.0, 2.0`, `4` -> `9`<br/>
- `2.5, 2.0`, `0.5` -> `3.5`<br/>
- `1.0, 2.0, 3.0, 4.0`, `1.5` -> `24.25<br/>
- # Example ungolfed program (Rust)
- ```rust
- // dbg! is a logging function, prints the expression and it's output.
- // Good for seeing what's happening
- // Test setup
- pub fn main() {
- let inp: &[f32] = &[1.0, 2.0, 3.0, 4.0];
- let x: f32 = 1.5;
- dbg!(evaluate_polynomial(inp, x)); // take inputs, print result
- }
- // Actual challenge answer function
- pub fn evaluate_polynomial(inp: &[f32], x: f32) -> f32 {
- let mut accum: f32 = 0.0;
- for (idx, val) in inp.iter().enumerate() {
- // x.pow(idx) * val
- accum += dbg!(x.powf(idx as f32) * val);
- }
- return accum;
- }
- ```
#4: Post edited
- NOTE: INCOMPLETE. I’m writing this on a phone because I can’t be bothered to wait.
- # Challenge
Given a list of n numbers and x, compute <math>a + bx + cx^2 + ... zx^n-1</math>, where a is the first value in the list, b is the second, etc. n is at most 256 and at least 0. If a v (TODO: Wording.)Input can be in any format of choice, as long as it is a list of numbers.- # Test inputs
- `1`, `0` -> `1`
- `1, 2`, `4` -> `9`
- NOTE: INCOMPLETE. I’m writing this on a phone because I can’t be bothered to wait.
- # Challenge
- Given a list of n numbers and x, compute <math>a + bx + cx^{2} + zx^{n-1}</math>, where a is the first value in the list, b is the second, etc. n is at most 256 and at least 0. If a v (TODO: Wording.)
- Input can be in any format of choice, as long as it is a list of numbers and x.
- # Test inputs
- `1`, `0` -> `1`
- `1, 2`, `4` -> `9`
#3: Post edited
- NOTE: INCOMPLETE. I’m writing this on a phone because I can’t be bothered to wait.
- # Challenge
Given a list of n numbers and x, compute <math>a + bx + cx^2 + ... zx^n-1</math>, where a is the first value in the list, b is the second, etc. n is at most 256 and at least 1. If a v (TODO: Wording.)- Input can be in any format of choice, as long as it is a list of numbers.
- # Test inputs
- `1`, `0` -> `1`
- `1, 2`, `4` -> `9`
- NOTE: INCOMPLETE. I’m writing this on a phone because I can’t be bothered to wait.
- # Challenge
- Given a list of n numbers and x, compute <math>a + bx + cx^2 + ... zx^n-1</math>, where a is the first value in the list, b is the second, etc. n is at most 256 and at least 0. If a v (TODO: Wording.)
- Input can be in any format of choice, as long as it is a list of numbers.
- # Test inputs
- `1`, `0` -> `1`
- `1, 2`, `4` -> `9`
#2: Post edited
- NOTE: INCOMPLETE. I’m writing this on a phone because I can’t be bothered to wait.
- # Challenge
- Given a list of n numbers and x, compute <math>a + bx + cx^2 + ... zx^n-1</math>, where a is the first value in the list, b is the second, etc. n is at most 256 and at least 1. If a v (TODO: Wording.)
- Input can be in any format of choice, as long as it is a list of numbers.
- # Test inputs
- `1`, `0` -> `1`
- `1, 2`, `4` -> `9`
- NOTE: INCOMPLETE. I’m writing this on a phone because I can’t be bothered to wait.
- # Challenge
- Given a list of n numbers and x, compute <math>a + bx + cx^2 + ... zx^n-1</math>, where a is the first value in the list, b is the second, etc. n is at most 256 and at least 1. If a v (TODO: Wording.)
- Input can be in any format of choice, as long as it is a list of numbers.
- # Test inputs
- `1`, `0` -> `1`
- `1, 2`, `4` -> `9`
#1: Initial revision
Compute a univariate polynomial
NOTE: INCOMPLETE. I’m writing this on a phone because I can’t be bothered to wait. # Challenge Given a list of n numbers and x, compute <math>a + bx + cx^2 + ... zx^n-1</math>, where a is the first value in the list, b is the second, etc. n is at most 256 and at least 1. If a v (TODO: Wording.) Input can be in any format of choice, as long as it is a list of numbers. # Test inputs `1`, `0` -> `1` `1, 2`, `4` -> `9`