Skip welcome & menu and move to editor
Welcome to JS Bin
Load cached copy from
 
<!DOCTYPE html>
<html>
<head>
  <meta charset="utf-8">
  <title>JS Bin</title>
</head>
<body>
</body>
</html>
 
const testCases = [
  ['1', true],
  ['1234', true],
  ['1221', true],
  ['3333', true],
  ['143332', true],
  ['22234', true],
  ['2234', true],
  ['22214', true],
  ['1221441', true],
  ['41233', true],
  ['13', false],
  ['1224', false],
  ['121', false],
  ['12221', false],
  ['43221', false]
];
const p=(s,d)=>(h=s[0],t=s.slice(1),g=t[0],!g||(d?g==h?p(t,-d):g%4==(h-d)%4&&p(t,d):p(s,1)||p(s,-1)));
testCases.forEach(c => {
  let e = c[1];
  let a = p(c[0]);
  
  console.log(c[0] + ': ' + (a === e ? 'pass' : `fail (expected ${e}, got ${a})`));
});
Output

You can jump to the latest bin by adding /latest to your URL

Dismiss x
public
Bin info
anonymouspro
0viewers