Page 1
Page 1
Started By
Message

Code.org = great site...and I need help on problem #71

Posted on 6/13/14 at 9:59 am
Posted by Pectus
Internet
Member since Apr 2010
67302 posts
Posted on 6/13/14 at 9:59 am
If you've never been to Code.org and you're looking to get into coding, or at least understand some of it, you should check it out!

There's computer scientists, educators, and celebrities who talk about how coding is important, and when you do exercises, they introduce each section with a practical example of code we use in the real world without even knowing!

If anything, these projects are fun to do...it's like playing a video game. You assemble code by snapping together blocks in the right order to complete each problem. You can view the code you made in real code in a separate panel.

It's fun!

Here's where I'm stuck: I can't seem to get this farmer to do what it's supposed to do. Maybe I didn't flesh out all the commands I should have.

#71

Do you think you know how to make this guy walk the whole field without leaving it and level it by filling holes and removing piles? How few blocks can you do it in?

ETA I can do this we 40 lines of code, if I spell it out for the farmer. But that's not the point of coding....

This post was edited on 6/13/14 at 10:08 am
Posted by Hu_Flung_Pu
Central, LA
Member since Jan 2013
22164 posts
Posted on 6/13/14 at 10:04 am to
I'm no help but I'm jumping on this bandwagon.
Posted by Doldil
The Ham
Member since Jan 2010
6214 posts
Posted on 6/13/14 at 10:19 am to
did it with 21 lines the first time and then didn't look at the code and lost it, did it in 24 lines the second time. at least on the first puzzle. kind of fun.
Posted by Pectus
Internet
Member since Apr 2010
67302 posts
Posted on 6/13/14 at 10:24 am to
quote:

did it with 21 lines the first time and then didn't look at the code and lost it, did it in 24 lines the second time. at least on the first puzzle. kind of fun.



I just feel like it should be fewer lines.

How did you implement the "while path ahead" block?
Posted by InVolNerable
Member since Jan 2012
10203 posts
Posted on 6/13/14 at 10:31 am to


There's probably a more efficient way, but that's what I came up with.

(15 lines of code)
This post was edited on 6/13/14 at 10:33 am
Posted by Doldil
The Ham
Member since Jan 2010
6214 posts
Posted on 6/13/14 at 10:32 am to
It can definitely be fewer lines, I just was being lazy with a couple of move forwards once the first path was done but it was essentially...

while path ahead
.....do 1 time (this defaults to 10 and I changed)
..........move forward
..........dig
Posted by Pectus
Internet
Member since Apr 2010
67302 posts
Posted on 6/13/14 at 10:35 am to
quote:



There's probably a more efficient way, but that's what I came up with.



Awesome.

Thanks for the pic to go with it.

Seem like you still spelled it out for the farmer, though. I feel like there's an easier way. Maybe they don't want the user to think ahead that much and exploit the blocks they can use, but then why would they let you use any amount?

So far, I think you've devised the shortest way.

This has me thinking...I think we should as admins for a way to make a pane in a post to post code, and make it keep its format and make it easy to copy and paste as well as not screwed up from TD's own coding for posting...and make it only work on the tech board.

Pretty sure there's free lines of code out there for this...
Posted by Doldil
The Ham
Member since Jan 2010
6214 posts
Posted on 6/13/14 at 10:38 am to
quote:

Seem like you still spelled it out for the farmer, though. I feel like there's an easier way


I don't understand what you mean by this.
Posted by Pectus
Internet
Member since Apr 2010
67302 posts
Posted on 6/13/14 at 10:41 am to
quote:

quote:

quote:
Seem like you still spelled it out for the farmer, though. I feel like there's an easier way



I don't understand what you mean by this.



I think you can get the farmer to walk all around the plot and do what they need to do to level it without having to tell it to walk this way this many steps and turn.

I feel like there's enough variety in the blocks that using the right commands could have the farmer do their job without having to tell them how many times to do it on each side, basically.
Posted by InVolNerable
Member since Jan 2012
10203 posts
Posted on 6/13/14 at 11:01 am to


A little longer, but not specific to the field. It moves horizontally then up. Then, if it has nowhere else to go, checks the last plot for a pile/hole.

Still seems verbose though.
This post was edited on 6/13/14 at 11:05 am
Posted by Doldil
The Ham
Member since Jan 2010
6214 posts
Posted on 6/13/14 at 11:06 am to
last one I did was in 20 lines of code...I hate that once you press play, if it succeeds you can't don anything with your blocks and it just goes on.

Mine latest basically worked like this:

Remove
Turn left
While path ahead - repeat 1 move forward remove
turn right
while path ahead - move forward - if hole - remove
turn right
while path ahead - repeat 1 move forward remove
repeat 2 turn right move forward fill

all movements are based on whether or not there is a path ahead save for the last line which is just the repeat loop.
Posted by Pectus
Internet
Member since Apr 2010
67302 posts
Posted on 6/13/14 at 11:12 am to
That's it! It is hefty, but it's what I envisioned!
Posted by Pectus
Internet
Member since Apr 2010
67302 posts
Posted on 6/13/14 at 11:12 am to
first pageprev pagePage 1 of 1Next pagelast page
refresh

Back to top
logoFollow TigerDroppings for LSU Football News
Follow us on Twitter, Facebook and Instagram to get the latest updates on LSU Football and Recruiting.

FacebookTwitterInstagram