September Morn Update
This commit is contained in:
parent
4e2d22a71d
commit
aac6731f2c
6856 changed files with 141342 additions and 21127 deletions
1
Task/Trabb-Pardo-Knuth-algorithm/00META.yaml
Normal file
1
Task/Trabb-Pardo-Knuth-algorithm/00META.yaml
Normal file
|
|
@ -0,0 +1 @@
|
|||
--- {}
|
||||
|
|
@ -1,32 +1,33 @@
|
|||
import system'math
|
||||
import extensions.
|
||||
import system'math;
|
||||
import extensions;
|
||||
|
||||
program =
|
||||
[
|
||||
array<real> inputs := real<>(11).
|
||||
console printLine("Please enter 11 numbers :").
|
||||
0 till:11 do(:i)
|
||||
[
|
||||
inputs[i] := console readLine; toReal.
|
||||
].
|
||||
public program()
|
||||
{
|
||||
real[] inputs := new real[](11);
|
||||
console.printLine("Please enter 11 numbers :");
|
||||
for(int i := 0, i < 11, i += 1)
|
||||
{
|
||||
inputs[i] := console.readLine().toReal()
|
||||
};
|
||||
|
||||
console printLine("Evaluating f(x) = |x|^0.5 + 5x^3 for the given inputs :").
|
||||
10 to:0 do(:i)
|
||||
[
|
||||
var r1 := inputs[i] absolute; sqrt.
|
||||
var r2 := inputs[i] power(3).
|
||||
var r :=inputs[i] /*absolute;*/ sqrt + 5*r2.
|
||||
console.printLine("Evaluating f(x) = |x|^0.5 + 5x^3 for the given inputs :");
|
||||
for(int i := 10, i >= 0, i -= 1)
|
||||
{
|
||||
var r1 := inputs[i].Absolute.sqrt();
|
||||
var r2 := inputs[i].power(3);
|
||||
//var r :=inputs[i]/*absolute;*/.sqrt() + 5*r2;
|
||||
|
||||
real result := (inputs[i] absolute; sqrt) + 5 * (inputs[i] power(3)).
|
||||
real result := (inputs[i].Absolute.sqrt()) + 5 * inputs[i].power(3);
|
||||
|
||||
console print("f(", inputs[i], ")=").
|
||||
console.print("f(", inputs[i], ")=");
|
||||
|
||||
if (result > 400)
|
||||
[
|
||||
console printLine("Overflow!")
|
||||
];
|
||||
[
|
||||
console printLine(result).
|
||||
]
|
||||
]
|
||||
].
|
||||
{
|
||||
console.printLine("Overflow!")
|
||||
}
|
||||
else
|
||||
{
|
||||
console.printLine(result)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -0,0 +1,30 @@
|
|||
use std::io::{self, BufRead};
|
||||
|
||||
fn op(x: f32) -> Option<f32> {
|
||||
let y = x.abs().sqrt() + 5.0 * x * x * x;
|
||||
if y < 400.0 {
|
||||
Some(y)
|
||||
} else {
|
||||
None
|
||||
}
|
||||
}
|
||||
|
||||
fn main() {
|
||||
println!("Please enter 11 numbers (one number per line)");
|
||||
let stdin = io::stdin();
|
||||
|
||||
let xs = stdin
|
||||
.lock()
|
||||
.lines()
|
||||
.map(|ox| ox.unwrap().trim().to_string())
|
||||
.flat_map(|s| str::parse::<f32>(&s))
|
||||
.take(11)
|
||||
.collect::<Vec<_>>();
|
||||
|
||||
for x in xs.into_iter().rev() {
|
||||
match op(x) {
|
||||
Some(y) => println!("{}", y),
|
||||
None => println!("overflow"),
|
||||
};
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue