A basic compiler based off of thejameskyle's super-tiny-compiler

advent02-1.mc 1.2KB

12345678910111213141516171819202122232425262728
  1. ; Requires the input for Advent of Code(http://adventofcode.com/) Day 2
  2. (include str fs maths)
  3. (assign input (fs::readIn "advent.txt"))
  4. (assign i 0)
  5. (assign resultone "")
  6. (assign resulttwo "")
  7. (assign resultthree "")
  8. (assign result 0)
  9. (assign currNum 1)
  10. (repeat (str::length input)
  11. (assign current (str::charAtIndex input i))
  12. (if (eq current "x")
  13. (assign currNum (maths::add currNum 1)) |
  14. (if (eq current "\n")
  15. (assign currNum 1)
  16. (assign result (maths::add result (maths::add (maths::add (maths::multiply 2 (maths::multiply resultone resulttwo)) (maths::add (maths::multiply 2 (maths::multiply resulttwo resultthree)) (maths::multiply 2 (maths::multiply resultone resultthree)))) (maths::min (maths::multiply resultone resulttwo) (maths::multiply resulttwo resultthree) (maths::multiply resultthree resultone)))))
  17. (assign resultone "")
  18. (assign resulttwo "")
  19. (assign resultthree "") |
  20. (if (eq currNum 1) (assign resultone (str::concat resultone current)))
  21. (if (eq currNum 2) (assign resulttwo (str::concat resulttwo current)))
  22. (if (eq currNum 3) (assign resultthree (str::concat resultthree current)))
  23. )
  24. )
  25. (assign i (maths::add i 1))
  26. )
  27. (log result)