)
}
}
)
(
}
{
)
)
(
)
(
(
{
}
)
(
)
}
)
)
{
(
(
)
)
}
)
(
}

Little Trading Program

  1. let id = 0;
  2. function person(startValue = 100) {
  3.   const props = {
  4.     id: id++, 
  5.     el: document.body.appendChild(
  6.       Object.assign(
  7.         document.createElement`b`, { 
  8.           innerText: startValue,
  9.           style: 'padding: 1em'
  10.       })
  11.     ),
  12.     value: startValue,
  13.     trade(other) {
  14.       if (props.value <= 0) return;
  15.       other.value += 1;
  16.       props.value -= 1;
  17.       other.el.innerText = other.value
  18.       props.el.innerText = props.value
  19.     }
  20.   }
  21.   return props
  22. }
  23.  
  24.  
  25. const NUM = 4
  26. const people = Array.from({ length: NUM }, person)
  27.  
  28. setInterval(() => {
  29.   const a = people[~~(Math.random() * people.length)]
  30.   const b = people[~~(Math.random() * people.length)]
  31.  
  32.   if (a.id != b.id) a.trade(b)
  33. }, 1)

4 “people” randomly trade…

I asked Chat GPT to describe this… funny response…

The trading program you provided is essentially an example of a random walk or “drunkard’s walk” problem. In such problems, each individual (in this case, the ‘people’) make random moves (in this case, trades), and we observe the resulting dynamics of the system as a whole. In this particular case, each trade involves one individual giving one unit of value to another individual. Since each trade is random, there’s a possibility that over time, all the value might get concentrated in one individual. This isn’t guaranteed, but given enough time, it’s likely. You could compare it to the idea that given enough time, a group of monkeys randomly typing on a keyboard would eventually type out the complete works of Shakespeare. It’s also worth noting that this concentration of value becomes more likely because the individuals with no value left cannot trade anymore, so they are essentially removed from the trading pool. This progressively reduces the number of individuals that can gain value and increases the probability of the remaining individuals gaining more value. This is a simple model of economic transactions and it illustrates how wealth can concentrate over time even if all the transactions are fair and random. Of course, it’s a very simplified model, and real-world economics are much more complex.
snippet.zone ~ 2021-24 /// {s/z}