[過去ログ] プログラミングのお題スレ Part13 (1002レス)
上下前次1-新
抽出解除 必死チェッカー(本家) (べ) 自ID レス栞 あぼーん
このスレッドは過去ログ倉庫に格納されています。
次スレ検索 歴削→次スレ 栞削→次スレ 過去ログメニュー
745: 2019/03/21(木)11:30 ID:4Lv8Ku6J(1/2)調 AAS
>>494 Squeak Smalltalk。コンマを分割と見なしそれぞれについての和を出力させてみた
| fn |
fn := [:columnName |
FileStream oldFileNamed: 'data.txt' do: [:file |
| index sum |
index := (file nextLine subStrings: ' ') indexOf: columnName.
sum := 0.
[file atEnd] whileFalse: [
| next |
next := ((file nextLine subStrings: ' ') at: index) subStrings: ','.
sum := sum + (next size = 1 ifTrue: [next anyOne] ifFalse: [next])].
sum
]
].
fn value: 'カラム3'. "=> 7.1 "
fn value: 'カラム1'. "=> #(3.1 2.1) "
748: 2019/03/21(木)22:33 ID:4Lv8Ku6J(2/2)調 AAS
>>723 Squeak Smalltalk
| fn |
fn := [:int1 :int2 |
| strings width digits interms ans max line |
strings := {int1. int2} collect: #asString.
width := (strings detectMax: #size) size.
digits := strings collect: [:str |
(str forceTo: width paddingStartWith: $0) reversed asArray collect: #asString].
interms := (digits reduce: #+) collectWithIndex: [:interm :idx |
interm, (String new: idx-1 withAll: Character space)].
ans := interms polynomialEval: '10'.
strings atLast: 1 put: '+ ', strings last.
max := ((strings, {ans}) collect: #size) max.
line := String new: max withAll: $-.
(strings, {line}, interms, {line. ans} collect: [:str |
(str forceTo: max paddingStartWith: Character space) withoutTrailingBlanks
]) asStringWithCr
].
fn value: 987 value: 65. "=>
' 987
+ 65
----
12
14
9
----
1052' "
上下前次1-新書関写板覧索設栞歴
スレ情報 赤レス抽出 画像レス抽出 歴の未読スレ AAサムネイル
ぬこの手 ぬこTOP 0.032s