User:TedSwippet/Interactive calculator

 var bh_listing = "KGZ1bmN0aW9uICgpIHsKICB2YXIgc2NyaXB0cyA9IGRvY3VtZW50LmdldEVsZW1lbnRzQnlUYWdOYW1lKCJzY3JpcHQiKTsKICB2YXIgc2VsZiA9IHNjcmlwdHNbc2NyaXB0cy5sZW5ndGggLSAxXTsKICBzZWxmLmluc2VydEFkamFjZW50SFRNTCgiYmVmb3JlYmVnaW4iLCAiPHByZT4iICsgYXRvYihzY3JpcHQpLnJlcGxhY2UoLyYvZywgIiZhbXA7IikucmVwbGFjZSgvPC9nLCAiJmx0OyIpLnJlcGxhY2UoLz4vZywgIiZndDsiKS5yZXBsYWNlKC8iL2csICImcXVvdDsiKS5yZXBsYWNlKC8nL2csICImIzAzOTsiKSArICJcbjwvcHJlPiIpOwp9KSgpCg=="; var bh_calculator_base = "Ly8gU3RhcnQgQmFzZTY0IGVuY29kaW5nIGhlcmUuCmlmICghKCJiaF8iIGluIHdpbmRvdykpCiAgd2luZG93LmJoXyA9IHt9OwoKYmhfLmNhbGN1bGF0b3IgPSB7CiAgbmFtZTogImJoXy5jYWxjdWxhdG9yIiwKCiAgaW5pdGlhbGl6ZTogZnVuY3Rpb24oaGFuZGxlciwgc2NoZW1hLCBwcmVmaXgpIHsKICAgIHZhciBzdHlsZXMgPSB7CiAgICAgIHRhYmxlOiAiYm9yZGVyLXN0eWxlOiBzb2xpZDsgYm9yZGVyLXdpZHRoOiAxcHg7IGJhY2tncm91bmQtY29sb3I6ICNmOGY5ZmEiLAogICAgICBjZWxsOiAicGFkZGluZzogMnB4IiwKICAgICAgZmllbGQ6ICJib3JkZXItc3R5bGU6IHNvbGlkOyBib3JkZXItd2lkdGg6IDFweDsgYmFja2dyb3VuZC1jb2xvcjogI2ZmZmZmZiIsCiAgICAgIGJ1dHRvbjogImJvcmRlci1zdHlsZTogc29saWQ7IGJvcmRlci13aWR0aDogMXB4OyBiYWNrZ3JvdW5kLWNvbG9yOiAjZGNkY2RjOyBwYWRkaW5nOiA0cHg7IGN1cnNvcjogcG9pbnRlciIKICAgIH07CiAgICB2YXIgaW52b2tlID0gaGFuZGxlci5uYW1lICsgIi5jYWxjdWxhdGUoXCIiICsgcHJlZml4ICsgIlwiKSI7CiAgICB2YXIgZmllbGRzID0gc2NoZW1hLmZpZWxkczsKCiAgICB2YXIgdGFibGUgPQogICAgICAgICAgIjx0YWJsZSBpZD0nIiArIHByZWZpeCArICJ0YWJsZScgc3R5bGU9JyIgKyBzdHlsZXMudGFibGUgKyAiJz48dGJvZHk+IgogICAgICAgICsgIjx0cj4iOwogICAgdmFyIHJlc3VsdDsKICAgIGZpZWxkcy5mb3JFYWNoKGZ1bmN0aW9uKGZpZWxkKSB7CiAgICAgIGlmICgiaW5pdCIgaW4gZmllbGQpIHsKICAgICAgICB2YXIgaW5pdCA9IGZpZWxkLmZvcm1hdC5yZXBsYWNlKCJ7fSIsIGZpZWxkLmluaXQpOwogICAgICAgIHRhYmxlICs9CiAgICAgICAgICAgICAgIjx0ZCBzdHlsZT0nIiArIHN0eWxlcy5jZWxsICsgIic+IgogICAgICAgICAgICArICI8bGFiZWwgZm9yPSciICsgcHJlZml4ICsgZmllbGQuaWQgKyAiJz4iICsgZmllbGQubGFiZWwgKyAiIDwvbGFiZWw+IgogICAgICAgICAgICArICI8aW5wdXQgdHlwZT0ndGV4dCcgc3R5bGU9JyIgKyBzdHlsZXMuZmllbGQgKyAiJyBzaXplPSc2JyBpZD0nIiArIHByZWZpeCArIGZpZWxkLmlkICsgIiciCiAgICAgICAgICAgICsgIiB2YWx1ZT0nIiArIGluaXQgKyAiJyBvbmNoYW5nZT0nIiArIGludm9rZSArICInPiIKICAgICAgICAgICAgKyAiPC90ZD4iOwogICAgICB9IGVsc2UgewogICAgICAgIHJlc3VsdCA9IGZpZWxkOwogICAgICB9CiAgICB9KTsKICAgIHRhYmxlICs9CiAgICAgICAgICAiPC90cj48dHI+IgogICAgICAgICsgIjx0ZCBzdHlsZT0nIiArIHN0eWxlcy5jZWxsICsgIic+IgogICAgICAgICsgIjxidXR0b24gdHlwZT0nYnV0dG9uJyBzdHlsZT0nIiArIHN0eWxlcy5idXR0b24gKyAiJyBpZD0nIiArIHByZWZpeCArICIjYnV0dG9uJyIKICAgICAgICArICIgb25jbGljaz0nIiArIGludm9rZSArICInPkNhbGN1bGF0ZTwvYnV0dG9uPjwvdGQ+IgogICAgICAgICsgIjx0ZCBzdHlsZT0nIiArIHN0eWxlcy5jZWxsICsgIic+IgogICAgICAgICsgIjxsYWJlbCBmb3I9JyIgKyBwcmVmaXggKyByZXN1bHQuaWQgKyAiJz4iICsgcmVzdWx0LmxhYmVsICsgIiA8L2xhYmVsPiIKICAgICAgICArICI8aW5wdXQgdHlwZT0ndGV4dCcgc3R5bGU9JyIgKyBzdHlsZXMuZmllbGQgKyAiJyBzaXplPSc2JyBpZD0nIiArIHByZWZpeCArIHJlc3VsdC5pZCArICInIHJlYWRvbmx5PiIKICAgICAgICArICI8L3RkPiIKICAgICAgICArICI8L3RyPiIKICAgICAgICArICI8L3Rib2R5PjwvdGFibGU+IjsKICAgIGlmICgibG9nIiBpbiBiaF8uY2FsY3VsYXRvciAmJiBiaF8uY2FsY3VsYXRvci5sb2cpCiAgICAgIGNvbnNvbGUubG9nKHRhYmxlKTsKICAgIHJldHVybiB0YWJsZTsKICB9LAoKICBjYWxjdWxhdGU6IGZ1bmN0aW9uKHByZWZpeCkgewogICAgdmFyIHNjaGVtYSA9IGJoXy5jYWxjdWxhdG9yX2dsb2JhbFtwcmVmaXhdOwogICAgdmFyIGZpZWxkcyA9IHNjaGVtYS5maWVsZHM7CgogICAgdmFyIGdldF92YWx1ZXMgPSBmdW5jdGlvbigpIHsKICAgICAgdmFyIHZhbHVlcyA9IHt9OwogICAgICBmaWVsZHMuZm9yRWFjaChmdW5jdGlvbihmaWVsZCkgewogICAgICAgIHZhciB2YWx1ZSA9IGRvY3VtZW50LmdldEVsZW1lbnRCeUlkKHByZWZpeCArIGZpZWxkLmlkKS52YWx1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dHNbc2NyaXB0cy5sZW5ndGggLSAxXTsKICAgICAgc2VsZi5pbnNlcnRBZGphY2VudEhUTUwoImJlZm9yZWJlZ2luIiwgc3RyaW5nKTsKICAgIH0KCiAgICBpZiAoISgiY2FsY3VsYXRvcl9nbG9iYWwiIGluIGJoXykpCiAgICAgIGJoXy5jYWxjdWxhdG9yX2dsb2JhbCA9IHtjb3VudGVyOiAxfTsKCiAgICB2YXIgcHJlZml4ID0gbmFtZSArICItIiArIGJoXy5jYWxjdWxhdG9yX2dsb2JhbC5jb3VudGVyICsgIi0iOwogICAgYmhfLmNhbGN1bGF0b3JfZ2xvYmFsLmNvdW50ZXIrKzsKICAgIGJoXy5jYWxjdWxhdG9yX2dsb2JhbFtwcmVmaXhdID0gc2NoZW1hOwoKICAgIHdyaXRlKGhhbmRsZXIuaW5pdGlhbGl6ZShoYW5kbGVyLCBzY2hlbWEsIHByZWZpeCkpOwogIH0KfTsKCi8vIGJoXy5jYWxjdWxhdG9yLmxvZyA9IHRydWU7Ci8vIEVuZCBCYXNlNjQgZW5jb2RpbmcgaGVyZS4="; eval(atob(bh_calculator_base)); {{Documentation|content=

Calculator code


Listing code
}}