tasks a-s

This commit is contained in:
Ingy döt Net 2013-04-10 23:57:08 -07:00
parent 47bf37c096
commit b83f433714
12433 changed files with 156208 additions and 123 deletions

View file

@ -0,0 +1,6 @@
String extend [
includesAnyOf: aSet [
aSet do: [ :e | (self includes: e) ifTrue: [ ^true ] ].
^false
]
].

View file

@ -0,0 +1,43 @@
Object subclass: SEDOL [
|weight charList|
initialize [
weight := Array from: { 1. 3. 1. 7. 3. 9 }.
charList :=
('ABCDEFGHIJKLMNOPQRSTUVWXYZ' asOrderedCollection)
collect: [ :c | ('AEIOU' includes: c) ifTrue: [ nil ] ifFalse: [ c ] ].
]
SEDOL class >> new [
^ (self basicNew) initialize
]
"to be considered private"
blindCheckDigit: aSEDOL [ |sum|
sum := 0.
aSEDOL keysAndValuesDo: [ :i :c |
('0123456789' includes: c)
ifTrue: [ sum := sum +
((weight at: i) *
(Number readFrom: (c asString readStream))).
]
ifFalse: [ sum := sum + (((charList indexOf: c) + 9) *
(weight at: i))
]
].
^ ((10 - (sum rem: 10)) rem: 10) displayString
]
checked: aSEDOL [
(aSEDOL size < 6) |
(aSEDOL size > 7) |
(aSEDOL asUppercase includesAnyOf: 'AEIOU' asSet )
ifTrue: [ SystemExceptions.InvalidArgument
signalOn: aSEDOL
reason: 'Not a valid SEDOL'
]
ifFalse: [ |t| t := aSEDOL copyFrom: 1 to: 6.
^ t , (self blindCheckDigit: t)
]
]
].

View file

@ -0,0 +1,12 @@
|sedol|
sedol := SEDOL new.
{ '710889'.
'B0YBKJ'.
'406566'.
'B0YBLH'.
'228276'.
'B0YBKL'.
'557910'.
'B0YBKR'.
'585284'.
'B0YBKT' } do: [ :c | (sedol checked: c) displayNl ]