Got Questions? Get Answers.
Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

Thread Subject:
MATLAB golf challenge - game of life

Subject: MATLAB golf challenge - game of life

From: EBS

Date: 25 Aug, 2010 16:55:24

Message: 1 of 7

There's a code golf challenge on StackOverflow that we could use your help with!: http://stackoverflow.com/questions/3499538/code-golf-conways-game-of-life

Can y'all come up with a shorter solution than the existing 127-charater one posted for MATLAB? I was trying to come up with a way to read a text file directly into a character array that would use less characters than 'char(importdata('in.txt'))', but wasn't able to...

Cheers!

Subject: MATLAB golf challenge - game of life

From: Sean

Date: 25 Aug, 2010 17:16:21

Message: 2 of 7

"EBS " <ericDOTsampson@gmail.com> wrote in message <i53hts$9t1$1@fred.mathworks.com>...
> There's a code golf challenge on StackOverflow that we could use your help with!: http://stackoverflow.com/questions/3499538/code-golf-conways-game-of-life
>
> Can y'all come up with a shorter solution than the existing 127-charater one posted for MATLAB? I was trying to come up with a way to read a text file directly into a character array that would use less characters than 'char(importdata('in.txt'))', but wasn't able to...
>
> Cheers!

I think it's too 124 lines!
Could get rid of the end-of-line commas and semicolons?

Subject: MATLAB golf challenge - game of life

From: Andy

Date: 25 Aug, 2010 17:59:05

Message: 3 of 7

"Sean " <sean.dewolski@nospamplease.umit.maine.edu> wrote in message <i53j55$rra$1@fred.mathworks.com>...
> "EBS " <ericDOTsampson@gmail.com> wrote in message <i53hts$9t1$1@fred.mathworks.com>...
> > There's a code golf challenge on StackOverflow that we could use your help with!: http://stackoverflow.com/questions/3499538/code-golf-conways-game-of-life
> >
> > Can y'all come up with a shorter solution than the existing 127-charater one posted for MATLAB? I was trying to come up with a way to read a text file directly into a character array that would use less characters than 'char(importdata('in.txt'))', but wasn't able to...
> >
> > Cheers!
>
> I think it's too 124 lines!
> Could get rid of the end-of-line commas and semicolons?

Actually, the end-of-line commas and semicolons are functional. Remember, white space counts as characters also. A lot of the code is posted with white space to be easier to read. When you delete all of the white space (except the spaces after function and for, which are necessary), you get the 124 character count.

Subject: MATLAB golf challenge - game of life

From: Sean

Date: 25 Aug, 2010 18:39:05

Message: 4 of 7

"Andy " <myfakeemailaddress@gmail.com> wrote in message <i53ll9$8mo$1@fred.mathworks.com>...
> "Sean " <sean.dewolski@nospamplease.umit.maine.edu> wrote in message <i53j55$rra$1@fred.mathworks.com>...
> > "EBS " <ericDOTsampson@gmail.com> wrote in message <i53hts$9t1$1@fred.mathworks.com>...
> > > There's a code golf challenge on StackOverflow that we could use your help with!: http://stackoverflow.com/questions/3499538/code-golf-conways-game-of-life
> > >
> > > Can y'all come up with a shorter solution than the existing 127-charater one posted for MATLAB? I was trying to come up with a way to read a text file directly into a character array that would use less characters than 'char(importdata('in.txt'))', but wasn't able to...
> > >
> > > Cheers!
> >
> > I think it's too 124 lines! %Wow I didn't proofread this!
> > Could get rid of the end-of-line commas and semicolons?
>
> Actually, the end-of-line commas and semicolons are functional. Remember, white space counts as characters also. A lot of the code is posted with white space to be easier to read. When you delete all of the white space (except the spaces after function and for, which are necessary), you get the 124 character count.

Ahh, so the line feed/carriage returns count as characters?

Subject: MATLAB golf challenge - game of life

From: Andy

Date: 25 Aug, 2010 18:58:05

Message: 5 of 7

"Sean " <sean.dewolski@nospamplease.umit.maine.edu> wrote in message <i53o09$9bf$1@fred.mathworks.com>...
> "Andy " <myfakeemailaddress@gmail.com> wrote in message <i53ll9$8mo$1@fred.mathworks.com>...
> > "Sean " <sean.dewolski@nospamplease.umit.maine.edu> wrote in message <i53j55$rra$1@fred.mathworks.com>...
> > > "EBS " <ericDOTsampson@gmail.com> wrote in message <i53hts$9t1$1@fred.mathworks.com>...
> > > > There's a code golf challenge on StackOverflow that we could use your help with!: http://stackoverflow.com/questions/3499538/code-golf-conways-game-of-life
> > > >
> > > > Can y'all come up with a shorter solution than the existing 127-charater one posted for MATLAB? I was trying to come up with a way to read a text file directly into a character array that would use less characters than 'char(importdata('in.txt'))', but wasn't able to...
> > > >
> > > > Cheers!
> > >
> > > I think it's too 124 lines! %Wow I didn't proofread this!
> > > Could get rid of the end-of-line commas and semicolons?
> >
> > Actually, the end-of-line commas and semicolons are functional. Remember, white space counts as characters also. A lot of the code is posted with white space to be easier to read. When you delete all of the white space (except the spaces after function and for, which are necessary), you get the 124 character count.
>
> Ahh, so the line feed/carriage returns count as characters?

Yes, but the displayed code on the site is prettied up. You should put the code into your own file and delete unnecessary white space before counting characters.

Subject: MATLAB golf challenge - game of life

From: Sean

Date: 25 Aug, 2010 20:11:19

Message: 6 of 7

"Andy " <myfakeemailaddress@gmail.com> wrote in message <i53p3t$kb9$1@fred.mathworks.com>...
> "Sean " <sean.dewolski@nospamplease.umit.maine.edu> wrote in message <i53o09$9bf$1@fred.mathworks.com>...
> > "Andy " <myfakeemailaddress@gmail.com> wrote in message <i53ll9$8mo$1@fred.mathworks.com>...
> > > "Sean " <sean.dewolski@nospamplease.umit.maine.edu> wrote in message <i53j55$rra$1@fred.mathworks.com>...
> > > > "EBS " <ericDOTsampson@gmail.com> wrote in message <i53hts$9t1$1@fred.mathworks.com>...
> > > > > There's a code golf challenge on StackOverflow that we could use your help with!: http://stackoverflow.com/questions/3499538/code-golf-conways-game-of-life
> > > > >
> > > > > Can y'all come up with a shorter solution than the existing 127-charater one posted for MATLAB? I was trying to come up with a way to read a text file directly into a character array that would use less characters than 'char(importdata('in.txt'))', but wasn't able to...
> > > > >
> > > > > Cheers!
> > > >
> > > > I think it's too 124 lines! %Wow I didn't proofread this!
> > > > Could get rid of the end-of-line commas and semicolons?
> > >
> > > Actually, the end-of-line commas and semicolons are functional. Remember, white space counts as characters also. A lot of the code is posted with white space to be easier to read. When you delete all of the white space (except the spaces after function and for, which are necessary), you get the 124 character count.
> >
> > Ahh, so the line feed/carriage returns count as characters?
>
> Yes, but the displayed code on the site is prettied up. You should put the code into your own file and delete unnecessary white space before counting characters.


Ok: This Saves 3 characters
changing
b=~fix(filter2(ones(3),b)-b/2-3);
to
b=filter2(ones(3),b)-b/2-3>-1;

Subject: MATLAB golf challenge - game of life

From: Sean

Date: 25 Aug, 2010 20:22:04

Message: 7 of 7

"Sean " <sean.dewolski@nospamplease.umit.maine.edu> wrote in message <i53td7$t1p$1@fred.mathworks.com>...
> "Andy " <myfakeemailaddress@gmail.com> wrote in message <i53p3t$kb9$1@fred.mathworks.com>...
> > "Sean " <sean.dewolski@nospamplease.umit.maine.edu> wrote in message <i53o09$9bf$1@fred.mathworks.com>...
> > > "Andy " <myfakeemailaddress@gmail.com> wrote in message <i53ll9$8mo$1@fred.mathworks.com>...
> > > > "Sean " <sean.dewolski@nospamplease.umit.maine.edu> wrote in message <i53j55$rra$1@fred.mathworks.com>...
> > > > > "EBS " <ericDOTsampson@gmail.com> wrote in message <i53hts$9t1$1@fred.mathworks.com>...
> > > > > > There's a code golf challenge on StackOverflow that we could use your help with!: http://stackoverflow.com/questions/3499538/code-golf-conways-game-of-life
> > > > > >
> > > > > > Can y'all come up with a shorter solution than the existing 127-charater one posted for MATLAB? I was trying to come up with a way to read a text file directly into a character array that would use less characters than 'char(importdata('in.txt'))', but wasn't able to...
> > > > > >
> > > > > > Cheers!
> > > > >
> > > > > I think it's too 124 lines! %Wow I didn't proofread this!
> > > > > Could get rid of the end-of-line commas and semicolons?
> > > >
> > > > Actually, the end-of-line commas and semicolons are functional. Remember, white space counts as characters also. A lot of the code is posted with white space to be easier to read. When you delete all of the white space (except the spaces after function and for, which are necessary), you get the 124 character count.
> > >
> > > Ahh, so the line feed/carriage returns count as characters?
> >
> > Yes, but the displayed code on the site is prettied up. You should put the code into your own file and delete unnecessary white space before counting characters.
>
>
> Ok: This Saves 3 characters
> changing
> b=~fix(filter2(ones(3),b)-b/2-3);
> to
> b=filter2(ones(3),b)-b/2-3>-1;

I lied, that's not going to work :(

Tags for this Thread

What are tags?

A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.

Anyone can tag a thread. Tags are public and visible to everyone.

Contact us