Re: [Pharo-users] can I improve this
Op 3-12-2018 om 16:08 schreef Benoit St-Jean via Pharo-users: yep I did change it by the argument partTwo: aFileName    | total numbers index frequencies duplicate file | duplicate := false. frequencies := Set new: 150000. frequencies add: 0. numbers := OrderedCollection new: 1000. total := 0. file := self changesFrom: aFileName. index := 0. [duplicate] whileFalse: [index := index \\ (numbers size) + 1.                        total := total + numbers at: index.                        (frequencies includes: total)                            ifTrue: [duplicate := true]                            ifFalse: [frequencies add: total]]. ^total and changesFrom looks like this : changesFrom: aFileName    ^Array streamContents: [:changes |      aFileName asFileReference readStreamDo: [:in |        [in atEnd] whileFalse: [changes nextPut: in nextLine asInteger]]]
I'm on Squeak btw. Tried it in Pharo 6.1 and it looks like number parsing is different. Here's a version that works fine on Pharo 6.1 | file total numbers index frequencies duplicate | duplicate := false. frequencies := Set new: 150000. frequencies add: 0. numbers := OrderedCollection new: 1000. total := 0. file := StandardFileStream readOnlyFileNamed: 'C:\Recv\day.1.input'. [file atEnd] whileFalse: [numbers add: (file nextLine asInteger)]. file close. index := 0. [duplicate] whileFalse: [index := index \\ (numbers size) + 1.                   total := total + numbers at: index.                   (frequencies includes: total)                      ifTrue: [duplicate := true]                      ifFalse: [frequencies add: total]]. total ----------------- Benoît St-Jean Yahoo! Messenger: bstjean Twitter: @BenLeChialeux Pinterest: benoitstjean Instagram: Chef_Benito IRC: lamneth Blogue: endormitoire.wordpress.com "A standpoint is an intellectual horizon of radius zero". (A. Einstein) On Monday, December 3, 2018, 10:12:36 a.m. EST, Roelof Wobben <r.wobben@home.nl> wrote: Op 3-12-2018 om 16:08 schreef Benoit St-Jean via Pharo-users: yep I did change it by the argument partTwo: aFileName    | total numbers index frequencies duplicate file | duplicate := false. frequencies := Set new: 150000. frequencies add: 0. numbers := OrderedCollection new: 1000. total := 0. file := self changesFrom: aFileName. index := 0. [duplicate] whileFalse: [index := index \\ (numbers size) + 1.                        total := total + numbers at: index.                        (frequencies includes: total)                            ifTrue: [duplicate := true]                            ifFalse: [frequencies add: total]]. ^total and changesFrom looks like this : changesFrom: aFileName    ^Array streamContents: [:changes |      aFileName asFileReference readStreamDo: [:in |        [in atEnd] whileFalse: [changes nextPut: in nextLine asInteger]]]
participants (2)
-
Benoit St-Jean -
Roelof Wobben