Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.forth > #36492
| From | "WJ" <w_a_x_man@yahoo.com> |
|---|---|
| Newsgroups | comp.lang.forth |
| Subject | Re: Simple fractal |
| Date | 2015-02-12 04:27 +0000 |
| Organization | A noiseless patient Spider |
| Message-ID | <mbha3c$894$1@dont-email.me> (permalink) |
| References | <ksr2bn$ur8$1@dont-email.me> |
WJ wrote:
> Ruby:
>
> def neighbors( line, i )
> [i-1, i+1].select{|n| n >= 0 and n < line.size}.
> count{|i| line[i,1] != " "}
> end
>
> def next_line( old_line, cycles )
> return unless cycles > 0
> puts old_line
> line = " " * old_line.size
> line.size.times{|i| line[i] = " * "[ neighbors( old_line, i ) ] }
> next_line( line, cycles - 1 )
> end
>
> line = " " * 79 ; line[ line.size/2 ] = "*"
> next_line( line, 40 )
>
>
> *
> * *
> * *
> * * * *
> * *
> * * * *
> * * * *
> * * * * * * * *
> * *
> * * * *
> * * * *
> * * * * * * * *
> * * * *
> * * * * * * * *
> * * * * * * * *
> * * * * * * * * * * * * * * * *
> * *
> * * * *
> * * * *
> * * * * * * * *
> * * * *
> * * * * * * * *
> * * * * * * * *
> * * * * * * * * * * * * * * * *
> * * * *
> * * * * * * * *
> * * * * * * * *
> * * * * * * * * * * * * * * * *
> * * * * * * * *
> * * * * * * * * * * * * * * * *
> * * * * * * * * * * * * * * * *
> * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
> * *
> * * * *
> * * * *
> * * * * * * * *
> * * * *
> * * * * * * * *
> * * * * * * * *
> * * * * * * * * * * * * * * * *
Gauche Scheme:
(use gauche.sequence)
(define size 79)
(define line (make-vector size 0))
(vector-set! line (div size 2) 1)
(define (next-gen i line)
(if (= 1 (+ (ref line (- i 1) 0)
(ref line (+ i 1) 0)))
1 0))
(define (print-line line)
(print (list->string
(map (^n (if (zero? n) #\space #\*)) line))))
(let go ((line line) (count 40))
(print-line line)
(when (> count 1)
(go (vector-tabulate size (cut next-gen <> line))
(- count 1))))
Back to comp.lang.forth | Previous | Next | Find similar | Unroll thread
Re: Simple fractal "WJ" <w_a_x_man@yahoo.com> - 2015-02-12 04:27 +0000
csiph-web