Todd Sundsted

A while back, I posted about creating a Forth-inspired programming language that uses emoji as words (functions) and said that I would post the source code. I keep my wordโ€”this weekend I cleaned up the code and published it.

I've built a tool that transpiles emoji source code into either Crystal or Python, and then builds and runs the transpiled source.

Here's the solution to Project Euler Problem 1, with comments so that you can more easily follow the flow:

๐Ÿ’ญ Project Euler Problem 1:
๐Ÿ’ญ Find the sum of all the multiples of 3 or 5 below 1000 => 233168

๐Ÿ’ญ Define a word to check if a number is divisible by 3 or 5
๐Ÿ“–โ“                    ๐Ÿ’ญ Stack: ( n -- bool )
  ๐Ÿ“š                    ๐Ÿ’ญ Duplicate n for two tests
  ๐Ÿ”ข3 ๐Ÿ”€ ๐Ÿ”ข0 ๐ŸŸฐ          ๐Ÿ’ญ (n%3==0)
  ๐Ÿ”„
  ๐Ÿ”ข5 ๐Ÿ”€ ๐Ÿ”ข0 ๐ŸŸฐ          ๐Ÿ’ญ (n%5==0)
  โšก                    ๐Ÿ’ญ (n%3==0 OR n%5==0)
๐Ÿ“•

๐Ÿ’ญ Declare variables
๐Ÿ“ฆ ๐Ÿ’ฏ                   ๐Ÿ’ญ sum variable
๐Ÿ“ฆ ๐Ÿงฎ                   ๐Ÿ’ญ counter variable

๐Ÿ’ญ Initialize variables
๐Ÿ”ข0 ๐Ÿ’พ ๐Ÿ’ฏ               ๐Ÿ’ญ sum = 0
๐Ÿ”ข1 ๐Ÿ’พ ๐Ÿงฎ               ๐Ÿ’ญ counter = 1

๐Ÿ’ญ Loop from 1 to 999 (inclusive)
๐Ÿ”
  ๐Ÿ’ญ Get counter and check if divisible by 3 or 5
  ๐Ÿ“ค ๐Ÿงฎ                 ๐Ÿ’ญ counter
  ๐Ÿ“š โ“                 ๐Ÿ’ญ counter bool

  ๐Ÿ‘
    ๐Ÿ’ญ If divisible, add counter to sum
    ๐Ÿ“ค ๐Ÿ’ฏ โž• ๐Ÿ’พ ๐Ÿ’ฏ       ๐Ÿ’ญ sum = sum + counter
  ๐Ÿ”š

  ๐Ÿ’ญ Increment counter
  ๐Ÿ“ค ๐Ÿงฎ ๐Ÿ”ข1 โž• ๐Ÿ’พ ๐Ÿงฎ     ๐Ÿ’ญ counter = counter + 1

  ๐Ÿ’ญ Test exit condition: counter > 999
  ๐Ÿ“ค ๐Ÿงฎ ๐Ÿ”ข999 โฌ†๏ธ
๐Ÿ”š

๐Ÿ’ญ Print the result
๐Ÿ“ค ๐Ÿ’ฏ ๐Ÿ˜€

Forth is fun because it is so easy to create a simple implementation of the language. It's also very very terse, which makes the emoji-nature of a project like this shine through. Here's the program above with emoji digits, fewer alphanumerics, and less whitespace:

๐Ÿ’ญ Project Euler Problem 1

๐Ÿ“–โ“ ๐Ÿ“š 3๏ธโƒฃ๐Ÿ”€0๏ธโƒฃ๐ŸŸฐ๐Ÿ”„5๏ธโƒฃ๐Ÿ”€0๏ธโƒฃ๐ŸŸฐโšก ๐Ÿ“•

๐Ÿ“ฆ๐Ÿ’ฏ
๐Ÿ“ฆ๐Ÿงฎ

0๏ธโƒฃ ๐Ÿ’พ๐Ÿ’ฏ
1๏ธโƒฃ ๐Ÿ’พ๐Ÿงฎ
๐Ÿ”
  ๐Ÿ“ค๐Ÿงฎ๐Ÿ“š
  โ“๐Ÿ‘๐Ÿ“ค๐Ÿ’ฏโž•๐Ÿ’พ๐Ÿ’ฏ๐Ÿ”š
  ๐Ÿ“ค๐Ÿงฎ1๏ธโƒฃโž•๐Ÿ’พ๐Ÿงฎ
  ๐Ÿ“ค๐Ÿงฎ๐Ÿ”ข999โฌ†๏ธ
๐Ÿ”š

๐Ÿ“ค๐Ÿ’ฏ ๐Ÿ˜€

The project README has more detail on the language features if you're interested.

#emoji #forth #esolang