Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.forth > #43605
| From | "WJ" <w_a_x_man@yahoo.com> |
|---|---|
| Newsgroups | comp.lang.forth |
| Subject | Re: Simple fractal |
| Date | 2015-11-20 19:51 +0000 |
| Organization | A noiseless patient Spider |
| Message-ID | <n2ntkg$70a$1@dont-email.me> (permalink) |
| References | <ksr2bn$ur8$1@dont-email.me> <mbha3c$894$1@dont-email.me> |
WJ wrote:
> 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 )
> >
> >
> > *
> > * *
> > * *
> > * * * *
> > * *
> > * * * *
> > * * * *
> > * * * * * * * *
> > * *
> > * * * *
> > * * * *
> > * * * * * * * *
> > * * * *
> > * * * * * * * *
> > * * * * * * * *
> > * * * * * * * * * * * * * * * *
> > * *
> > * * * *
> > * * * *
> > * * * * * * * *
> > * * * *
> > * * * * * * * *
> > * * * * * * * *
> > * * * * * * * * * * * * * * * *
> > * * * *
> > * * * * * * * *
> > * * * * * * * *
> > * * * * * * * * * * * * * * * *
> > * * * * * * * *
> > * * * * * * * * * * * * * * * *
> > * * * * * * * * * * * * * * * *
> > * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
> > * *
> > * * * *
> > * * * *
> > * * * * * * * *
> > * * * *
> > * * * * * * * *
> > * * * * * * * *
> > * * * * * * * * * * * * * * * *
def new_cell i, line
n = [i-1,i+1].grep(0...line.size).map{|j| line[j]}.
count{|c| c!=" "}
" * "[n]
end
def new_line line
new = line.dup
new.size.times{|i| new[i] = new_cell(i, line)}
new
end
line = " " * 79 ; line[ line.size/2 ] = "*"
puts line ;
(puts line = new_line(line)) until " " != line[0]
Back to comp.lang.forth | Previous | Next — Next in thread | Find similar | Unroll thread
Re: Simple fractal "WJ" <w_a_x_man@yahoo.com> - 2015-11-20 19:51 +0000
Re: Simple fractal Mux <Yvo.Zoer@gmail.com> - 2015-11-20 12:44 -0800
Re: Simple fractal Michael Barry <barrym95838@yahoo.com> - 2015-11-20 22:44 -0800
Re: Simple fractal Paul Rubin <no.email@nospam.invalid> - 2015-11-20 22:51 -0800
Re: Simple fractal hughaguilar96@gmail.com - 2016-01-13 19:18 -0800
Re: Simple fractal "WJ" <w_a_x_man@yahoo.com> - 2015-11-21 15:09 +0000
Re: Simple fractal "WJ" <w_a_x_man@yahoo.com> - 2015-11-26 16:12 +0000
Re: Simple fractal "WJ" <w_a_x_man@yahoo.com> - 2015-11-26 17:13 +0000
csiph-web