Loading/progress indicator for shell with aging emojis


Recently, while waiting for a long-running script to finish, I thought that it would be nice to have some sort of loader with aging emojis. TLDR: we-are-waiting.

The โ€œlifeโ€ of an emoji is simple:

๐Ÿ‘ถ๐Ÿฟ โ†’ ๐Ÿ‘ง๐Ÿฟ โ†’ ๐Ÿ‘ฉ๐Ÿฟ โ†’ ๐Ÿ‘ฑ๐Ÿฟโ€โ™€๏ธ โ†’ ๐Ÿ‘ฉ๐Ÿฟโ€โš•๏ธ โ†’ ๐Ÿ‘ต๐Ÿฟ

It contains aging from a baby to grown-up person, one profession, and oldness.

And as we have four colors, two genders, five ages, and 22 professions. We can have a great variety of lives. So as the first thing to do I decided to generate all those variants. Initially, I was planning to implement everything in Go, but itโ€™s not possible to use emojis in Go code, only codepoints. Because of that, I decided to write a little Python script, that will generate Go code with all variants with codepoints instead of emojis.

For that I just copied lines with emojis from getemoji.com and put them in lists:

ages = [
    "๐Ÿ‘ถ ๐Ÿ‘ฆ ๐Ÿ‘ง ๐Ÿ‘จ ๐Ÿ‘ฉ ๐Ÿ‘ฑโ€โ™€๏ธ ๐Ÿ‘ฑ ๐Ÿ‘ด ๐Ÿ‘ต",
    "๐Ÿ‘ถ๐Ÿป ๐Ÿ‘ฆ๐Ÿป ๐Ÿ‘ง๐Ÿป ๐Ÿ‘จ๐Ÿป ๐Ÿ‘ฉ๐Ÿป ๐Ÿ‘ฑ๐Ÿปโ€โ™€๏ธ ๐Ÿ‘ฑ๐Ÿป ๐Ÿ‘ด๐Ÿป ๐Ÿ‘ต๐Ÿป",
    "๐Ÿ‘ถ๐Ÿผ ๐Ÿ‘ฆ๐Ÿผ ๐Ÿ‘ง๐Ÿผ ๐Ÿ‘จ๐Ÿผ ๐Ÿ‘ฉ๐Ÿผ ๐Ÿ‘ฑ๐Ÿผโ€โ™€๏ธ ๐Ÿ‘ฑ๐Ÿผ ๐Ÿ‘ด๐Ÿผ ๐Ÿ‘ต๐Ÿผ",
    "๐Ÿ‘ถ๐Ÿฝ ๐Ÿ‘ฆ๐Ÿฝ ๐Ÿ‘ง๐Ÿฝ ๐Ÿ‘จ๐Ÿฝ ๐Ÿ‘ฉ๐Ÿฝ ๐Ÿ‘ฑ๐Ÿฝโ€โ™€๏ธ ๐Ÿ‘ฑ๐Ÿฝ ๐Ÿ‘ด๐Ÿฝ ๐Ÿ‘ต๐Ÿฝ",
    "๐Ÿ‘ถ๐Ÿพ ๐Ÿ‘ฆ๐Ÿพ ๐Ÿ‘ง๐Ÿพ ๐Ÿ‘จ๐Ÿพ ๐Ÿ‘ฉ๐Ÿพ ๐Ÿ‘ฑ๐Ÿพโ€โ™€๏ธ ๐Ÿ‘ฑ๐Ÿพ ๐Ÿ‘ด๐Ÿพ ๐Ÿ‘ต๐Ÿพ",
    "๐Ÿ‘ถ๐Ÿฟ ๐Ÿ‘ฆ๐Ÿฟ ๐Ÿ‘ง๐Ÿฟ ๐Ÿ‘จ๐Ÿฟ ๐Ÿ‘ฉ๐Ÿฟ ๐Ÿ‘ฑ๐Ÿฟโ€โ™€๏ธ ๐Ÿ‘ฑ๐Ÿฟ ๐Ÿ‘ด๐Ÿฟ ๐Ÿ‘ต๐Ÿฟ",
]
ages = [x.split(' ') for x in ages]

roles = [
    "๐Ÿ‘ฎโ€โ™€๏ธ ๐Ÿ‘ฎ ๐Ÿ‘ทโ€โ™€๏ธ ๐Ÿ‘ท ๐Ÿ’‚โ€โ™€๏ธ ๐Ÿ’‚ ๐Ÿ•ต๏ธโ€โ™€๏ธ ๐Ÿ•ต๏ธ ๐Ÿ‘ฉโ€โš•๏ธ ๐Ÿ‘จโ€โš•๏ธ ๐Ÿ‘ฉโ€๐ŸŒพ ๐Ÿ‘จโ€๐ŸŒพ ๐Ÿ‘ฉโ€๐Ÿณ ๐Ÿ‘จโ€๐Ÿณ ๐Ÿ‘ฉโ€๐ŸŽ“ ๐Ÿ‘จโ€๐ŸŽ“ ๐Ÿ‘ฉโ€๐ŸŽค ๐Ÿ‘จโ€๐ŸŽค ๐Ÿ‘ฉโ€๐Ÿซ ๐Ÿ‘จโ€๐Ÿซ ๐Ÿ‘ฉโ€๐Ÿญ ๐Ÿ‘จโ€๐Ÿญ ๐Ÿ‘ฉโ€๐Ÿ’ป ๐Ÿ‘จโ€๐Ÿ’ป ๐Ÿ‘ฉโ€๐Ÿ’ผ ๐Ÿ‘จโ€๐Ÿ’ผ ๐Ÿ‘ฉโ€๐Ÿ”ง ๐Ÿ‘จโ€๐Ÿ”ง ๐Ÿ‘ฉโ€๐Ÿ”ฌ ๐Ÿ‘จโ€๐Ÿ”ฌ ๐Ÿ‘ฉโ€๐ŸŽจ ๐Ÿ‘จโ€๐ŸŽจ ๐Ÿ‘ฉโ€๐Ÿš’ ๐Ÿ‘จโ€๐Ÿš’ ๐Ÿ‘ฉโ€โœˆ๏ธ ๐Ÿ‘จโ€โœˆ๏ธ ๐Ÿ‘ฉโ€๐Ÿš€ ๐Ÿ‘จโ€๐Ÿš€ ๐Ÿ‘ฉโ€โš–๏ธ ๐Ÿ‘จโ€โš–๏ธ ๐Ÿคถ ๐ŸŽ… ๐Ÿ‘ธ ๐Ÿคด",
    "๐Ÿ‘ฎ๐Ÿปโ€โ™€๏ธ ๐Ÿ‘ฎ๐Ÿป ๐Ÿ‘ท๐Ÿปโ€โ™€๏ธ ๐Ÿ‘ท๐Ÿป ๐Ÿ’‚๐Ÿปโ€โ™€๏ธ ๐Ÿ’‚๐Ÿป ๐Ÿ•ต๐Ÿปโ€โ™€๏ธ ๐Ÿ•ต๐Ÿป ๐Ÿ‘ฉ๐Ÿปโ€โš•๏ธ ๐Ÿ‘จ๐Ÿปโ€โš•๏ธ ๐Ÿ‘ฉ๐Ÿปโ€๐ŸŒพ ๐Ÿ‘จ๐Ÿปโ€๐ŸŒพ ๐Ÿ‘ฉ๐Ÿปโ€๐Ÿณ ๐Ÿ‘จ๐Ÿปโ€๐Ÿณ ๐Ÿ‘ฉ๐Ÿปโ€๐ŸŽ“ ๐Ÿ‘จ๐Ÿปโ€๐ŸŽ“ ๐Ÿ‘ฉ๐Ÿปโ€๐ŸŽค ๐Ÿ‘จ๐Ÿปโ€๐ŸŽค ๐Ÿ‘ฉ๐Ÿปโ€๐Ÿซ ๐Ÿ‘จ๐Ÿปโ€๐Ÿซ ๐Ÿ‘ฉ๐Ÿปโ€๐Ÿญ ๐Ÿ‘จ๐Ÿปโ€๐Ÿญ ๐Ÿ‘ฉ๐Ÿปโ€๐Ÿ’ป ๐Ÿ‘จ๐Ÿปโ€๐Ÿ’ป ๐Ÿ‘ฉ๐Ÿปโ€๐Ÿ’ผ ๐Ÿ‘จ๐Ÿปโ€๐Ÿ’ผ ๐Ÿ‘ฉ๐Ÿปโ€๐Ÿ”ง ๐Ÿ‘จ๐Ÿปโ€๐Ÿ”ง ๐Ÿ‘ฉ๐Ÿปโ€๐Ÿ”ฌ ๐Ÿ‘จ๐Ÿปโ€๐Ÿ”ฌ ๐Ÿ‘ฉ๐Ÿปโ€๐ŸŽจ ๐Ÿ‘จ๐Ÿปโ€๐ŸŽจ ๐Ÿ‘ฉ๐Ÿปโ€๐Ÿš’ ๐Ÿ‘จ๐Ÿปโ€๐Ÿš’ ๐Ÿ‘ฉ๐Ÿปโ€โœˆ๏ธ ๐Ÿ‘จ๐Ÿปโ€โœˆ๏ธ ๐Ÿ‘ฉ๐Ÿปโ€๐Ÿš€ ๐Ÿ‘จ๐Ÿปโ€๐Ÿš€ ๐Ÿ‘ฉ๐Ÿปโ€โš–๏ธ ๐Ÿ‘จ๐Ÿปโ€โš–๏ธ ๐Ÿคถ๐Ÿป ๐ŸŽ…๐Ÿป ๐Ÿ‘ธ๐Ÿป ๐Ÿคด๐Ÿป",
    "๐Ÿ‘ฎ๐Ÿผโ€โ™€๏ธ ๐Ÿ‘ฎ๐Ÿผ ๐Ÿ‘ท๐Ÿผโ€โ™€๏ธ ๐Ÿ‘ท๐Ÿผ ๐Ÿ’‚๐Ÿผโ€โ™€๏ธ ๐Ÿ’‚๐Ÿผ ๐Ÿ•ต๐Ÿผโ€โ™€๏ธ ๐Ÿ•ต๐Ÿผ ๐Ÿ‘ฉ๐Ÿผโ€โš•๏ธ ๐Ÿ‘จ๐Ÿผโ€โš•๏ธ ๐Ÿ‘ฉ๐Ÿผโ€๐ŸŒพ ๐Ÿ‘จ๐Ÿผโ€๐ŸŒพ ๐Ÿ‘ฉ๐Ÿผโ€๐Ÿณ ๐Ÿ‘จ๐Ÿผโ€๐Ÿณ ๐Ÿ‘ฉ๐Ÿผโ€๐ŸŽ“ ๐Ÿ‘จ๐Ÿผโ€๐ŸŽ“ ๐Ÿ‘ฉ๐Ÿผโ€๐ŸŽค ๐Ÿ‘จ๐Ÿผโ€๐ŸŽค ๐Ÿ‘ฉ๐Ÿผโ€๐Ÿซ ๐Ÿ‘จ๐Ÿผโ€๐Ÿซ ๐Ÿ‘ฉ๐Ÿผโ€๐Ÿญ ๐Ÿ‘จ๐Ÿผโ€๐Ÿญ ๐Ÿ‘ฉ๐Ÿผโ€๐Ÿ’ป ๐Ÿ‘จ๐Ÿผโ€๐Ÿ’ป ๐Ÿ‘ฉ๐Ÿผโ€๐Ÿ’ผ ๐Ÿ‘จ๐Ÿผโ€๐Ÿ’ผ ๐Ÿ‘ฉ๐Ÿผโ€๐Ÿ”ง ๐Ÿ‘จ๐Ÿผโ€๐Ÿ”ง ๐Ÿ‘ฉ๐Ÿผโ€๐Ÿ”ฌ ๐Ÿ‘จ๐Ÿผโ€๐Ÿ”ฌ ๐Ÿ‘ฉ๐Ÿผโ€๐ŸŽจ ๐Ÿ‘จ๐Ÿผโ€๐ŸŽจ ๐Ÿ‘ฉ๐Ÿผโ€๐Ÿš’ ๐Ÿ‘จ๐Ÿผโ€๐Ÿš’ ๐Ÿ‘ฉ๐Ÿผโ€โœˆ๏ธ ๐Ÿ‘จ๐Ÿผโ€โœˆ๏ธ ๐Ÿ‘ฉ๐Ÿผโ€๐Ÿš€ ๐Ÿ‘จ๐Ÿผโ€๐Ÿš€ ๐Ÿ‘ฉ๐Ÿผโ€โš–๏ธ ๐Ÿ‘จ๐Ÿผโ€โš–๏ธ ๐Ÿคถ๐Ÿผ ๐ŸŽ…๐Ÿผ ๐Ÿ‘ธ๐Ÿผ ๐Ÿคด๐Ÿผ",
    "๐Ÿ‘ฎ๐Ÿฝโ€โ™€๏ธ ๐Ÿ‘ฎ๐Ÿฝ ๐Ÿ‘ท๐Ÿฝโ€โ™€๏ธ ๐Ÿ‘ท๐Ÿฝ ๐Ÿ’‚๐Ÿฝโ€โ™€๏ธ ๐Ÿ’‚๐Ÿฝ ๐Ÿ•ต๐Ÿฝโ€โ™€๏ธ ๐Ÿ•ต๐Ÿฝ ๐Ÿ‘ฉ๐Ÿฝโ€โš•๏ธ ๐Ÿ‘จ๐Ÿฝโ€โš•๏ธ ๐Ÿ‘ฉ๐Ÿฝโ€๐ŸŒพ ๐Ÿ‘จ๐Ÿฝโ€๐ŸŒพ ๐Ÿ‘ฉ๐Ÿฝโ€๐Ÿณ ๐Ÿ‘จ๐Ÿฝโ€๐Ÿณ ๐Ÿ‘ฉ๐Ÿฝโ€๐ŸŽ“ ๐Ÿ‘จ๐Ÿฝโ€๐ŸŽ“ ๐Ÿ‘ฉ๐Ÿฝโ€๐ŸŽค ๐Ÿ‘จ๐Ÿฝโ€๐ŸŽค ๐Ÿ‘ฉ๐Ÿฝโ€๐Ÿซ ๐Ÿ‘จ๐Ÿฝโ€๐Ÿซ ๐Ÿ‘ฉ๐Ÿฝโ€๐Ÿญ ๐Ÿ‘จ๐Ÿฝโ€๐Ÿญ ๐Ÿ‘ฉ๐Ÿฝโ€๐Ÿ’ป ๐Ÿ‘จ๐Ÿฝโ€๐Ÿ’ป ๐Ÿ‘ฉ๐Ÿฝโ€๐Ÿ’ผ ๐Ÿ‘จ๐Ÿฝโ€๐Ÿ’ผ ๐Ÿ‘ฉ๐Ÿฝโ€๐Ÿ”ง ๐Ÿ‘จ๐Ÿฝโ€๐Ÿ”ง ๐Ÿ‘ฉ๐Ÿฝโ€๐Ÿ”ฌ ๐Ÿ‘จ๐Ÿฝโ€๐Ÿ”ฌ ๐Ÿ‘ฉ๐Ÿฝโ€๐ŸŽจ ๐Ÿ‘จ๐Ÿฝโ€๐ŸŽจ ๐Ÿ‘ฉ๐Ÿฝโ€๐Ÿš’ ๐Ÿ‘จ๐Ÿฝโ€๐Ÿš’ ๐Ÿ‘ฉ๐Ÿฝโ€โœˆ๏ธ ๐Ÿ‘จ๐Ÿฝโ€โœˆ๏ธ ๐Ÿ‘ฉ๐Ÿฝโ€๐Ÿš€ ๐Ÿ‘จ๐Ÿฝโ€๐Ÿš€ ๐Ÿ‘ฉ๐Ÿฝโ€โš–๏ธ ๐Ÿ‘จ๐Ÿฝโ€โš–๏ธ ๐Ÿคถ๐Ÿฝ ๐ŸŽ…๐Ÿฝ ๐Ÿ‘ธ๐Ÿฝ ๐Ÿคด๐Ÿฝ",
    "๐Ÿ‘ฎ๐Ÿพโ€โ™€๏ธ ๐Ÿ‘ฎ๐Ÿพ ๐Ÿ‘ท๐Ÿพโ€โ™€๏ธ ๐Ÿ‘ท๐Ÿพ ๐Ÿ’‚๐Ÿพโ€โ™€๏ธ ๐Ÿ’‚๐Ÿพ ๐Ÿ•ต๐Ÿพโ€โ™€๏ธ ๐Ÿ•ต๐Ÿพ ๐Ÿ‘ฉ๐Ÿพโ€โš•๏ธ ๐Ÿ‘จ๐Ÿพโ€โš•๏ธ ๐Ÿ‘ฉ๐Ÿพโ€๐ŸŒพ ๐Ÿ‘จ๐Ÿพโ€๐ŸŒพ ๐Ÿ‘ฉ๐Ÿพโ€๐Ÿณ ๐Ÿ‘จ๐Ÿพโ€๐Ÿณ ๐Ÿ‘ฉ๐Ÿพโ€๐ŸŽ“ ๐Ÿ‘จ๐Ÿพโ€๐ŸŽ“ ๐Ÿ‘ฉ๐Ÿพโ€๐ŸŽค ๐Ÿ‘จ๐Ÿพโ€๐ŸŽค ๐Ÿ‘ฉ๐Ÿพโ€๐Ÿซ ๐Ÿ‘จ๐Ÿพโ€๐Ÿซ ๐Ÿ‘ฉ๐Ÿพโ€๐Ÿญ ๐Ÿ‘จ๐Ÿพโ€๐Ÿญ ๐Ÿ‘ฉ๐Ÿพโ€๐Ÿ’ป ๐Ÿ‘จ๐Ÿพโ€๐Ÿ’ป ๐Ÿ‘ฉ๐Ÿพโ€๐Ÿ’ผ ๐Ÿ‘จ๐Ÿพโ€๐Ÿ’ผ ๐Ÿ‘ฉ๐Ÿพโ€๐Ÿ”ง ๐Ÿ‘จ๐Ÿพโ€๐Ÿ”ง ๐Ÿ‘ฉ๐Ÿพโ€๐Ÿ”ฌ ๐Ÿ‘จ๐Ÿพโ€๐Ÿ”ฌ ๐Ÿ‘ฉ๐Ÿพโ€๐ŸŽจ ๐Ÿ‘จ๐Ÿพโ€๐ŸŽจ ๐Ÿ‘ฉ๐Ÿพโ€๐Ÿš’ ๐Ÿ‘จ๐Ÿพโ€๐Ÿš’ ๐Ÿ‘ฉ๐Ÿพโ€โœˆ๏ธ ๐Ÿ‘จ๐Ÿพโ€โœˆ๏ธ ๐Ÿ‘ฉ๐Ÿพโ€๐Ÿš€ ๐Ÿ‘จ๐Ÿพโ€๐Ÿš€ ๐Ÿ‘ฉ๐Ÿพโ€โš–๏ธ ๐Ÿ‘จ๐Ÿพโ€โš–๏ธ ๐Ÿคถ๐Ÿพ ๐ŸŽ…๐Ÿพ ๐Ÿ‘ธ๐Ÿพ ๐Ÿคด๐Ÿพ",
    "๐Ÿ‘ฎ๐Ÿฟโ€โ™€๏ธ ๐Ÿ‘ฎ๐Ÿฟ ๐Ÿ‘ท๐Ÿฟโ€โ™€๏ธ ๐Ÿ‘ท๐Ÿฟ ๐Ÿ’‚๐Ÿฟโ€โ™€๏ธ ๐Ÿ’‚๐Ÿฟ ๐Ÿ•ต๐Ÿฟโ€โ™€๏ธ ๐Ÿ•ต๐Ÿฟ ๐Ÿ‘ฉ๐Ÿฟโ€โš•๏ธ ๐Ÿ‘จ๐Ÿฟโ€โš•๏ธ ๐Ÿ‘ฉ๐Ÿฟโ€๐ŸŒพ ๐Ÿ‘จ๐Ÿฟโ€๐ŸŒพ ๐Ÿ‘ฉ๐Ÿฟโ€๐Ÿณ ๐Ÿ‘จ๐Ÿฟโ€๐Ÿณ ๐Ÿ‘ฉ๐Ÿฟโ€๐ŸŽ“ ๐Ÿ‘จ๐Ÿฟโ€๐ŸŽ“ ๐Ÿ‘ฉ๐Ÿฟโ€๐ŸŽค ๐Ÿ‘จ๐Ÿฟโ€๐ŸŽค ๐Ÿ‘ฉ๐Ÿฟโ€๐Ÿซ ๐Ÿ‘จ๐Ÿฟโ€๐Ÿซ ๐Ÿ‘ฉ๐Ÿฟโ€๐Ÿญ ๐Ÿ‘จ๐Ÿฟโ€๐Ÿญ ๐Ÿ‘ฉ๐Ÿฟโ€๐Ÿ’ป ๐Ÿ‘จ๐Ÿฟโ€๐Ÿ’ป ๐Ÿ‘ฉ๐Ÿฟโ€๐Ÿ’ผ ๐Ÿ‘จ๐Ÿฟโ€๐Ÿ’ผ ๐Ÿ‘ฉ๐Ÿฟโ€๐Ÿ”ง ๐Ÿ‘จ๐Ÿฟโ€๐Ÿ”ง ๐Ÿ‘ฉ๐Ÿฟโ€๐Ÿ”ฌ ๐Ÿ‘จ๐Ÿฟโ€๐Ÿ”ฌ ๐Ÿ‘ฉ๐Ÿฟโ€๐ŸŽจ ๐Ÿ‘จ๐Ÿฟโ€๐ŸŽจ ๐Ÿ‘ฉ๐Ÿฟโ€๐Ÿš’ ๐Ÿ‘จ๐Ÿฟโ€๐Ÿš’ ๐Ÿ‘ฉ๐Ÿฟโ€โœˆ๏ธ ๐Ÿ‘จ๐Ÿฟโ€โœˆ๏ธ ๐Ÿ‘ฉ๐Ÿฟโ€๐Ÿš€ ๐Ÿ‘จ๐Ÿฟโ€๐Ÿš€ ๐Ÿ‘ฉ๐Ÿฟโ€โš–๏ธ ๐Ÿ‘จ๐Ÿฟโ€โš–๏ธ ๐Ÿคถ๐Ÿฟ ๐ŸŽ…๐Ÿฟ ๐Ÿ‘ธ๐Ÿฟ ๐Ÿคด๐Ÿฟ",
]
roles = [x.split(' ') for x in roles]

As emojis have a strange order, generation of all variants is a bit tricky, but itโ€™s easier than rearranging them in code because my editor doesnโ€™t work quite well with emojis:

def get_life(color, gender, role):
    yield ages[color][0]
    yield ages[color][1 + gender]
    yield ages[color][3 + gender]
    yield ages[color][6 - gender]
    yield roles[color][role * 2 + 1 - gender]
    yield ages[color][7 + gender]
>>> list(get_life(0, 0, 0))
['๐Ÿ‘ถ', '๐Ÿ‘ฆ', '๐Ÿ‘จ', '๐Ÿ‘ฑ', '๐Ÿ‘ฎ', '๐Ÿ‘ด']
def get_variants():
    for color in range(len(ages)):
        for gender in (0, 1):
            for role in range(len(roles[0]) // 2):
                yield color, gender, role
>>> list(get_life(*list(get_variants())[23]))
['๐Ÿ‘ถ', '๐Ÿ‘ง', '๐Ÿ‘ฉ', '๐Ÿ‘ฑ\u200dโ™€๏ธ', '๐Ÿ‘ท\u200dโ™€๏ธ', '๐Ÿ‘ต']

And after that itโ€™s very easy to generate Go package with all possible variants:

code = b'package variants\n\nvar All = [][]string{\n'

for variant in get_variants():
    code += b'\t{\n'
    for emoji in get_life(*variant):
        code += b'\t\t"' + emoji.encode('unicode-escape') + b'",\n'
    code += b'\t},\n'

code += b'}\n'

with open('variants/variants.go', 'wb') as f:
    f.write(code)

So weโ€™ll have something like this in variants/variants.go:

package variants

var All = [][]string{
	{
		"\U0001f476",
		"\U0001f466",
		"\U0001f468",
		"\U0001f471",
		"\U0001f46e",
		"\U0001f474",
	},
	...
}

The logic of the loader isnโ€™t that interesting, although I want to highlight some moments. At the high level we just read lines from a pipe, if thereโ€™s no new line arrived before tick seconds, we update our emojis:

func main() {
        ...
        go watchApp(lines)
        
        for {
            select {
            case line, isOpen := <-lines:
                ...
                os.Stdout.WriteString(line)
                ...
                printPeople(people)
            case <-time.After(time.Duration(*tick) * time.Second):
                people = updatePeople(people, *count)
                printPeople(people)
            }
        }
}

While updating, we can add new emoji, make one emoji older or โ€œkillโ€ the oldest:

func updatePeople(people []*human, count int) []*human {
	addNew := rand.Intn(5) == 0
	toMakeOlder := canMakeOlder(people)

	if addNew || len(toMakeOlder) == 0 {
		people = append(people, getRandomHuman())
	} else {
		index := toMakeOlder[rand.Intn(len(toMakeOlder))]
		people[index].position += 1
	}

	if len(people) > count {
		oldest := getOldest(people)
		return append(people[:oldest], people[oldest+1:]...)
	} else {
		return people
	}
}

And thatโ€™s all. You can find the source code on GitHub.



comments powered by Disqus