# Division

Do you have questions or comments about this model? Ask them here! (You'll first need to log in.)

## WHAT IS IT?

"What's 65 divided by 14?" There are many ways to answer this question. Some examples are 4.643, 4, four and nine fourteenths, and 4 with 9 left over. The last answer is an example of the kind of result this model would give.

Just as there are many ways to answer the question of "What's 65 divided by 14?" there are many methods to coming up with each answer. This model shows an interesting method that distributes the work of finding a solution among a group of separate agents.

DIVIDEND circles get spread out as evenly as possible among the DIVISOR colorful blocks. The result is QUOTIENT with REMAINDER left over on the black block to the far left. Note that REMAINDER is smaller than the number of colorful blocks. Otherwise, each of the colorful blocks could have at least one more circle.

## HOW IT WORKS

The blocks take turns acting trying to accomplish the goal of distributing the circles evenly.

The colorful blocks act as follows: The block that's acting compares how many circles it has on itself with how many circles are on another colorful block. If it has at least two more than the other block, it can afford to give the other block one, so it does. If the acting block has exactly one more circle than the other block, it sends that extra circle to the black block on the far left. Since the colorful blocks act in this way, no colorful block can have more circles on it than any other colorful block.

The black block is special. While the colorful blocks are trying to spread the circles out evenly, the black block is keeping the extra circles. When the black block acts, it checks how many circles it has on it. If it has enough at least enough to put one circle on each of the colorful blocks, it sends all of the circles on it out to the colorful blocks randomly. Since the black block acts in this way, the maximum number of circles will be spread evenly on the colorful blocks.

## HOW TO USE IT

Set DIVIDEND and DIVISOR to the desired numbers, press SETUP to set the problem up, and press GO to have the model find the answer.

DIVIDEND is the number of circles that will get spread out.

DIVISOR is the number of colorful blocks the circles will be spread out onto.

SETUP sets the problem up.

GO solves the problem.

When the model stops, the QUOTIENT monitor displays the number of circles on each of the colorful blocks.

When the model stops, the REMAINDER monitor displays the number of circles on the black block, which is the number of circles left over.

If CYCLE-IN-ORDER? is on, the blocks take turns acting in order. If it's off, the next block to act is chosen randomly.

IF NEXT-IS-OTHER? is on, the colorful blocks compare with the block to their right. If it's off, they compare with a random other colorful block.

To help watch the algorithm working, there are a few other monitors and a GO ONCE button that has just one block act at a time.

BLOCK-TO-GO shows which block is acting.

CIRCLES-ON-BLOCK-TO-GO show how many circles are on BLOCK-TO-GO.

OTHER-BLOCK shows which block BLOCK-TO-GO is comparing itself with.

CIRCLES-ON-OTHER-BLOCK shows how many circles are on OTHER-BLOCK.

## THINGS TO NOTICE

Sometimes, the circles are piled up on top of each other. When this happens, it may look like there are fewer circles on a block than there actually are.

The time it takes for the algorithm to work varies quite a bit, even with the same settings.

Different remainders change how long the algorithm takes. What remainders are faster? What remainders are slower?

What else effects how long the algorithm takes? In what ways?

## THINGS TO TRY

What switches, if any, make a difference in the time it takes for the algorithm to work and in what way?

Can you find settings that you know the algorithm will never work for? If so, how do you know?

## EXTENDING THE MODEL

The QUOTIENT monitor finds the average number of circles on the colorful blocks. Finding the average involves dividing by DIVISOR. Figure out another way to display the QUOTIENT that doesn't use division.

Make a way to time the model.

Don't allow more than one circle to be on a single patch within a block unless there's no other way to fit the circles onto the block.

Modify the algorithm to speed it up. Some ideas: Try having the blocks balance out with each other as much as possible before moving on to the next block. Try having the algorithm "settle twice", that is, go through once trying to share among the colorful blocks and once to send extras to the remainder.

## CREDITS AND REFERENCES

The algorithm that this model uses comes from a post to the starlogo-users mailing list by Ted Kaehler.

Thanks to Josh Unterman for his work on this model.

## HOW TO CITE

If you mention this model in a publication, we ask that you include these citations for the model itself and for the NetLogo software:

- Wilensky, U. (2002). NetLogo Division model. http://ccl.northwestern.edu/netlogo/models/Division. Center for Connected Learning and Computer-Based Modeling, Northwestern Institute on Complex Systems, Northwestern University, Evanston, IL.
- Wilensky, U. (1999). NetLogo. http://ccl.northwestern.edu/netlogo/. Center for Connected Learning and Computer-Based Modeling, Northwestern Institute on Complex Systems, Northwestern University, Evanston, IL.

## COPYRIGHT AND LICENSE

Copyright 2002 Uri Wilensky.

This work is licensed under the Creative Commons Attribution-NonCommercial-ShareAlike 3.0 License. To view a copy of this license, visit http://creativecommons.org/licenses/by-nc-sa/3.0/ or send a letter to Creative Commons, 559 Nathan Abbott Way, Stanford, California 94305, USA.

Commercial licenses are also available. To inquire about commercial licenses, please contact Uri Wilensky at uri@northwestern.edu.

This model was created as part of the projects: PARTICIPATORY SIMULATIONS: NETWORK-BASED DESIGN FOR SYSTEMS LEARNING IN CLASSROOMS and/or INTEGRATED SIMULATION AND MODELING ENVIRONMENT. The project gratefully acknowledges the support of the National Science Foundation (REPP & ROLE programs) -- grant numbers REC #9814682 and REC-0126227.

## Comments and Questions

globals [ block-to-go ;; which block is acting during go circles-on-block-to-go other-block ;; the block with which block-to-go compares itself circles-on-other-block ] patches-own [ block-number ] ;;;;;;;;;;;;;;;;;;;;;; ;; SETUP PROCEDURES ;; ;;;;;;;;;;;;;;;;;;;;;; to setup clear-all setup-blocks setup-circles set block-to-go 0 set circles-on-block-to-go circles-on-block block-to-go reset-ticks end to setup-blocks let size-of-columns floor (world-width / (divisor + 1)) let extra-in-base world-width mod (divisor + 1) let active-block-number 0 let active-column-number 0 ;; draws a few extra columns in the base repeat extra-in-base + size-of-columns [ ask patches with [ pxcor = active-column-number + min-pxcor ] [ set pcolor black set block-number 0 ] set active-column-number active-column-number + 1 ] set active-block-number 1 ;; now the rest of the blocks get drawn repeat divisor [ repeat size-of-columns [ ask patches with [ pxcor = active-column-number + min-pxcor ] [ set pcolor 10 * active-block-number + 5 set block-number active-block-number ] set active-column-number active-column-number + 1 ] set active-block-number active-block-number + 1 ] ;; now go through and give each block a label with its number set active-block-number 0 let label-pxcor min-pxcor ask patch label-pxcor min-pycor [ set plabel-color white set plabel active-block-number ] set active-block-number active-block-number + 1 set label-pxcor label-pxcor + extra-in-base repeat divisor [ set label-pxcor label-pxcor + size-of-columns ask patch label-pxcor min-pycor [ set plabel-color black set plabel active-block-number ] set active-block-number active-block-number + 1 ] end to setup-circles set-default-shape turtles "circle" crt dividend [ set color white setxy ( min-pxcor ) random-ycor ] end ;;;;;;;;;;;;;;;;;;;;;;;; ;; RUNTIME PROCEDURES ;; ;;;;;;;;;;;;;;;;;;;;;;;; to go if done? [ stop ] compare-blocks get-new-blocks tick end to compare-blocks ifelse block-to-go = 0 [ if circles-on-block-to-go >= divisor [ ask turtles with [ block-number = 0 ] [ set xcor [pxcor] of one-of patches with [ block-number = ((random divisor) + 1)] ] ] ] [ ifelse (circles-on-block-to-go - circles-on-other-block) > 1 [ move-turtle block-to-go other-block ] [ if (circles-on-block-to-go - circles-on-other-block) = 1 [ move-turtle block-to-go 0 ] ] ] end to get-new-blocks ifelse cycle-in-order? [ set block-to-go block-to-go + 1 ] [ set block-to-go random (divisor + 1) ] if (block-to-go > divisor) [ set block-to-go 0 ] set circles-on-block-to-go circles-on-block block-to-go ifelse not next-is-other? [ set other-block (random divisor) + 1 while [ other-block = block-to-go ] [ set other-block (random divisor) + 1 ] ] [ ifelse block-to-go != divisor [ set other-block block-to-go + 1 ] [ set other-block 1 ] ] set circles-on-other-block circles-on-block other-block end ;; checks to see if anything is going to change ;; if nothing is going to, returns true to-report done? report equal-stripes-check and (circles-on-block 0 < divisor) end ;;;;;;;;;;;;;;;;;;;;;;; ;; MONITOR REPORTERS ;; ;;;;;;;;;;;;;;;;;;;;;;; to-report average-answer report count turtles-on patches with [block-number != 0] / divisor end to-report remainder-count report count turtles-on patches with [block-number = 0] end ;;;;;;;;;;;;;;;;;;;;;;; ;; HELPER PROCEDURES ;; ;;;;;;;;;;;;;;;;;;;;;;; ; reports how many circles are on the given block to-report circles-on-block [ index ] report count turtles-on patches with [block-number = index] end to move-turtle [ from-block to-block ] ask one-of turtles with [ block-number = from-block ] [ set xcor ([pxcor] of one-of patches with [ block-number = to-block]) ] end to-report equal-stripes-check let equal-stripes-answer true let index 1 repeat divisor - 1 [ if circles-on-block index != circles-on-block (index + 1) [ set equal-stripes-answer false ] set index index + 1 ] report equal-stripes-answer end ; Copyright 2002 Uri Wilensky. ; See Info tab for full copyright and license.

There are 10 versions of this model.

## Attached files

File | Type | Description | Last updated | |
---|---|---|---|---|

Division.png | preview | Preview for 'Division' | almost 10 years ago, by Uri Wilensky | Download |

This model does not have any ancestors.

This model does not have any descendants.