プログラミングのお題スレ Part12at TECH
プログラミングのお題スレ Part12 - 暇つぶし2ch247:デフォルトの名無しさん
18/11/07 12:58:28.67 jk7t6Ngg.net
>>230 Squeak Smalltalk
| fn |
fn := [:points |
| xs ys fi gi |
xs := points collect: #x.
ys := points collect: #y.
fi := [:x :i | ((1 to: xs size) copyWithout: i) inject: 1 into: [:prod :k | prod * (x - (xs at: k))]].
gi := [:i |
(0 to: xs size - 1) collect: [:n | n = 0 ifTrue: [1] ifFalse: [
(Array streamContents: [:ss |
(xs copyWithoutIndex: i) combinations: n atATimeDo: [:comb |
ss nextPut: (comb negated reduce: #*)]
]
) sum
]]
].
(ys * ((1 to: xs size) collect: gi) / (xs collectWithIndex: fi)) sum
].
fn value: {0@1. 1@3}. "=> #(2 1) "
fn value: {100@100}. "=> #(100) "
fn value: {0@1. -1@5. 2@2. 4@ -1. 1@0}. "=> {(-2/15) . (4/15) . (49/30) . (-83/30) . 1} "


次ページ
続きを表示
1を表示
最新レス表示
レスジャンプ
類似スレ一覧
スレッドの検索
話題のニュース
おまかせリスト
オプション
しおりを挟む
スレッドに書込
スレッドの一覧
暇つぶし2ch