This is a read-only archive of the old Scratch 1.x Forums.
Try searching the current Scratch discussion forums.

#1 2012-10-07 11:51:16

weaselnut
Scratcher
Registered: 2009-07-02
Posts: 3

Please Help With My Rats

I'm making a project to automate the solving of a homework problem. It's due on Tuesday, 10/9/12. The project is giving me a slightly lower answer than others who have completed the problem already, and I don't know what's wrong. It really would be so great if you helped, given the deadline.

Here are the parameters of the problem:
-Two rats, male and female, have landed on an island full of food and good rat things. They start multiplying. We need to know how many rats there are at the end of one year; for our purposes, 360 days.
-I am considering every pair of rats to be one, since the males aren't important, and then multiplying by two at the very end.
-The original female rat gives birth to 6 rats (3 pairs) on the first day. She then produces another litter of 3 every 40 days.
-Every other rat must wait for 120 days for its first litter, then have another every 40 days after.
-No rats die.

    when gf clicked
        set (Time) to [0]
        delete [all] of [Kid Rats]
        delete [all] of [Adult Rats] //for a blank slate, of course
        add [0] to [Adult Rats] //the original pair
        repeat [9] //9 * 40=360 days
            set (Total) to < [2] * <(length of "Kid Rats" ) + (length of "Adult Rats" )> > //*
            change (Time) by [40] //40 days passes, the only important unit of time
            repeat (length of [Kid Rats] )  //age each kid rat
                if ("80" = (item "1" of "Kid Rats" )) //**
                    add (Time) to [Adult Rats] //New adult rat (the name of the item in the...
                else //...list doesn't really matter, so I made it show what date the rat... 
                    add <[40] + (item 1 of "Kid Rats" )> to [Kid Rats] //...reached adulthood.)
                delete [1] of [Kid Rats] //if not adult, age and cycle to the bottom of...
            repeat (length of [Adult Rats] )   //...the kid stack.
                repeat [3]  
                    add [0] to [Kid Rats] //add three 0-age kids for each adult.
    end
*to update the total as we go.
**80, not 120, because it checks for adulthood BEFORE aging for the turn.

Last edited by weaselnut (2012-10-08 10:47:11)

Offline

 

#2 2012-10-07 13:29:23

AtomicBawm3
Scratcher
Registered: 2009-06-27
Posts: 1000+

Re: Please Help With My Rats

It looks like you might be missing when the new litters of 3 come in.


http://i50.tinypic.com/j0yw0p.jpg

Offline

 

#3 2012-10-08 10:30:00

weaselnut
Scratcher
Registered: 2009-07-02
Posts: 3

Re: Please Help With My Rats

That is the "Repeat (length of [Adult Rats]): Repeat [3]: Add '0' to Kid Rats" at the bottom. Here, I'll put notes on it. I was in a hurry before.

Offline

 

#4 2012-10-08 15:28:04

ErnieParke
Scratcher
Registered: 2010-12-03
Posts: 1000+

Re: Please Help With My Rats

weaselnut wrote:

I'm making a project to automate the solving of a homework problem. It's due on Tuesday, 10/9/12. The project is giving me a slightly lower answer than others who have completed the problem already, and I don't know what's wrong. It really would be so great if you helped, given the deadline.

Here are the parameters of the problem:
-Two rats, male and female, have landed on an island full of food and good rat things. They start multiplying. We need to know how many rats there are at the end of one year; for our purposes, 360 days.
-I am considering every pair of rats to be one, since the males aren't important, and then multiplying by two at the very end.
-The original female rat gives birth to 6 rats (3 pairs) on the first day. She then produces another litter of 3 every 40 days.
-Every other rat must wait for 120 days for its first litter, then have another every 40 days after.
-No rats die.

    when gf clicked
        set [Time v] to [0]
        delete [all v] of [Kid Rats v]
        delete [all v] of [Adult Rats v] //for a blank slate, of course
        add [0] to [Adult Rats v] //the original pair
        repeat [9] //9 * 40=360 days
            set [Total v] to < [2] * <(length of [Kid Rats v] ) + (length of [Adult Rats v])> > //*
            change [Time v] by [40] //40 days passes, the only important unit of time
            repeat (length of [Kid Rats v] )  //age each kid rat
                if <[80] = (item (1) of [Kid Rats v] )> //**
                    add (Time) to [Adult Rats v] //New adult rat (the name of the item in the...
                else //...list doesn't really matter, so I made it show what date the rat... 
                    add <[40] + (item (1) of [Kid Rats v] )> to [Kid Rats v] //...reached adulthood.)
                delete [1] of [Kid Rats v] //if not adult, age and cycle to the bottom of...
            repeat (length of [Adult Rats v] )   //...the kid stack.
                repeat [3]  
                    add [0] to [Kid Rats v] //add three 0-age kids for each adult.
    end
end
end
end
end
*to update the total as we go.
**80, not 120, because it checks for adulthood BEFORE aging for the turn.

I fixed some of your code.

Last edited by ErnieParke (2012-10-08 15:40:06)


http://i46.tinypic.com/35ismmc.png

Offline

 

Board footer