UNPKG

bulls-cows-solver

Version:

Get all the possible answers for Bulls and Cows game, based on the history of guesses in one round.

1 lines 2.62 kB
!function(r,t){"object"==typeof exports&&"object"==typeof module?module.exports=t():"function"==typeof define&&define.amd?define([],t):"object"==typeof exports?exports.bullsCowsSolver=t():r.bullsCowsSolver=t()}(this,(function(){return function(){"use strict";var r={d:function(t,e){for(var n in e)r.o(e,n)&&!r.o(t,n)&&Object.defineProperty(t,n,{enumerable:!0,get:e[n]})},o:function(r,t){return Object.prototype.hasOwnProperty.call(r,t)}},t={};function e(r,t){var e="undefined"!=typeof Symbol&&r[Symbol.iterator]||r["@@iterator"];if(!e){if(Array.isArray(r)||(e=function(r,t){if(r){if("string"==typeof r)return n(r,t);var e=Object.prototype.toString.call(r).slice(8,-1);return"Object"===e&&r.constructor&&(e=r.constructor.name),"Map"===e||"Set"===e?Array.from(r):"Arguments"===e||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(e)?n(r,t):void 0}}(r))||t&&r&&"number"==typeof r.length){e&&(r=e);var o=0,a=function(){};return{s:a,n:function(){return o>=r.length?{done:!0}:{done:!1,value:r[o++]}},e:function(r){throw r},f:a}}throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}var u,f=!0,i=!1;return{s:function(){e=e.call(r)},n:function(){var r=e.next();return f=r.done,r},e:function(r){i=!0,u=r},f:function(){try{f||null==e.return||e.return()}finally{if(i)throw u}}}}function n(r,t){(null==t||t>r.length)&&(t=r.length);for(var e=0,n=new Array(t);e<t;e++)n[e]=r[e];return n}function o(r){for(var t=(r=String(r)).length,e=0;e<t;e++){var n=r.charAt(e);if(r.indexOf(n)!=r.lastIndexOf(n))return!0}return!1}r.d(t,{default:function(){return l}});for(var a=[],u=123;u<=9876;u++){var f=("00"+u).substr(-4);o(f)||a.push(f)}function i(r,t){return!(!/^\d{4}$/.test(r)||o(r)||!{"0A0B":!0,"0A1B":!0,"0A2B":!0,"0A3B":!0,"0A4B":!0,"1A0B":!0,"1A1B":!0,"1A2B":!0,"1A3B":!0,"2A0B":!0,"2A1B":!0,"2A2B":!0,"3A0B":!0}[t.toUpperCase()])}function c(r,t){var e,n,o=0,a=0;for(e=0;e<4;e++)if(r.charAt(e)==t.charAt(e))o++;else for(n=0;n<4;n++)e!=n&&r.charAt(e)==t.charAt(n)&&a++;return o+"A"+a+"B"}function l(r){if(!(r instanceof Array))throw TypeError("Input must be an array");if(0!=r.length){for(var t=0;t<r.length;t++){var n=r[t];try{if(!i(n.guess,n.result))throw Error("Input "+(t+1)+" is invalid.")}catch(r){throw Error("Input "+(t+1)+" is invalid.")}}var o,u=new Array,f=!1,l=e(a);try{for(l.s();!(o=l.n()).done;){var s=o.value;f=!1;var y,p=e(r);try{for(p.s();!(y=p.n()).done;){var v=y.value;if(c(s,v.guess)!=v.result){f=!0;break}}}catch(r){p.e(r)}finally{p.f()}f||u.push(s)}}catch(r){l.e(r)}finally{l.f()}return u}}return t.default}()}));