[Newbies] Teaching Smalltalk

David Mitchell david.mitchell at gmail.com
Tue May 4 03:31:40 UTC 2010


Doh! Was only playing with 10 doors. This makes it 100.

| count doors |
count := 100.
"Initialize the array of doors to 0 (closed)"
doors := (Array new: count) atAllPut:  false.

"Process the doors"
1 to: count do:
    [ :pass |
    pass to: count by: pass do:
        [ :door |
        doors
            at: door
            put: (doors at: door) not ] ].

"Print out the results"
1 to: count do:
    [ :n |
    Transcript
        show: 'door #', n, ' is ';
        show: ((doors at: door) ifTrue: [#open] ifFalse: [#closed]);
        cr]
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.squeakfoundation.org/pipermail/beginners/attachments/20100503/28276f59/attachment.htm


More information about the Beginners mailing list