- プログラミングのお題スレ Part7 [転載禁止]©2ch.net
256 :デフォルトの名無しさん[sage]:2015/06/06(土) 10:45:55.83 ID:TEHNGSNb - >>255 Squeak/Pharo Smalltalk
| triangleAreaFrom | triangleAreaFrom := [:p1 :p2 :p3 | (p1 dist: p2) * (p3 dist: (p3 nearestPointAlongLineFrom: p1 to: p2)) / 2 ]. triangleAreaFrom value: 0@0 value: 4@0 value: 4@3. "=> 6 " triangleAreaFrom value: -10@ -10 value: 1@ -10 value: -2@3. "=> (143/2) " triangleAreaFrom value: 0@0 value: 1@1 value: 2@2. "=> 0.0 "
|
- プログラミングのお題スレ Part7 [転載禁止]©2ch.net
265 :デフォルトの名無しさん[sage]:2015/06/06(土) 13:45:34.90 ID:TEHNGSNb - >>257
念のため >>256 だけど、>>255 は別の人。 Smalltalkでも特にSqueak/PharoでAPIが充実してる類なので さくっと書き下ろしただけ。宿題スレとやらもどこか知らないので 仮にその自演の人がSmalltalk使いでも、俺ではない。
|
- プログラミングのお題スレ Part7 [転載禁止]©2ch.net
268 :デフォルトの名無しさん[sage]:2015/06/06(土) 23:13:35.73 ID:TEHNGSNb - >>173 Squeak/Pharo Smalltalk
| fn | fn := [:points | | max | max := 0 -> {0@0. 0@0}. points combinations: 2 atATimeDo: [:pair | | middlePt onlinePt count | middlePt := pair sum / 2. onlinePt := pair first rotateBy: #left centerAt: middlePt. count := points count: [:pt | | nearestPt | nearestPt := pt nearestPointAlongLineFrom: middlePt to: onlinePt. nearestPt ~= pt and: [points includes: (pt rotateBy: #pi centerAt: nearestPt)]]. max := max max: count -> {middlePt. onlinePt}]. max key ]. fn value: {0@1. 0@2. 0@3. 1@0. 2@0. 3@0} "=> 6 "
|