[過去ログ] Rust part24 (1002レス)
上下前次1-新
抽出解除 必死チェッカー(本家) (べ) 自ID レス栞 あぼーん
このスレッドは過去ログ倉庫に格納されています。
次スレ検索 歴削→次スレ 栞削→次スレ 過去ログメニュー
346(1): デフォルトの名無しさん [sage] 2024/06/25(火) 05:16:25.10 ID:6VG6SXsU(1) AAS
>>342342(2): デフォルトの名無しさん [sage] 2024/06/24(月) 23:33:41.46 ID:FIb4AZ4T(1/2) AAS
>>328-329
なんかダサい
外部リンク:paiza.io
pub fn f(x: i32) -> i32 {
(
-2413f64*(x.pow(6) as f64)/120960f64
+739f64*(x.pow(5) as f64)/1260f64
-157991f64*(x.pow(4) as f64)/24192f64
+69551f64*(x.pow(3) as f64)/2016f64
-2691673f64*(x.pow(2) as f64)/30240f64
+88679f64*(x as f64)/840f64
-905f64/21f64
+0.5)
as i32
}
pub fn g(y: i32) -> i32 {
(
13f64*(y.pow(6) as f64)/120960f64
-(y.pow(5) as f64)/315f64
+1415f64*(y.pow(4) as f64)/24192f64
-1511f64*(y.pow(3) as f64)/2016f64
+144793f64*(y.pow(2) as f64)/30240f64
-3053f64*(y as f64)/280f64
+185f64/21f64
+0.5)
as i32
}
pub fn main() {
let a = vec![(1, 2), (2, 1), (3, 3), (4, 10), (6, 4), (8, 8), (10, 6)];
for (x, _y) in &a { println!("{}, {}", x, f(*x)); }
for (_x, y) in &a { println!("{}, {}", y, g(*y)); }
}
6次式を使う場合それを展開することに意味があると思えないから展開前の>>336336(2): デフォルトの名無しさん [sage] 2024/06/24(月) 17:42:58.06 ID:Uuc2YNAP(1/2) AAS
>>328
const INPUT: &str = "
1→2
2→1
3→3
4→10
6→4
8→8
10→6
";
fn parse(s: &str) -> Vec<(i32, i32)> {
s.lines().filter_map(|line| {
line.split('→')
.map(str::parse::<i32>)
.collect::<Result<Vec<_ _>>()
.ok()
.and_then(|v| (v.len() == 2).then(|| (v[0], v[1])))
})
.collect::<Vec<_>>()
}
fn make_f(v: &[(i32, i32)]) -> impl Fn(i32) -> i32 + '_ {
move |x| {
v.iter().enumerate().map(|(i, (in1, out))| {
v.iter().enumerate().filter_map(|(j, (in2, _))| (i != j).then(|| x - in2)).product::<i32>() /
v.iter().enumerate().filter_map(|(j, (in2, _))| (i != j).then(|| in1 - in2)).product::<i32>() * out
})
.sum()
}
}
でいいんじゃない?
上下前次1-新書関写板覧索設栞歴
スレ情報 赤レス抽出 画像レス抽出 歴の未読スレ AAサムネイル
ぬこの手 ぬこTOP 0.043s