JSFiddle - React, Tailwind, and code Playground
HTML
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<script src="https://fonts.googleapis.com/css?family=Inconsolata"></script>
CSS
html{
overflow-x: hidden;
overflow-y: scroll;
}
body{
overflow: hidden;
font-family: 'Inconsolata', Open Sans, sans-serif, Arial;
}
h1, h2, p{
font-family: Open Sans, sans-serif, Arial;
}
p{
text-align: justify;
}
h2{
margin: .5em 0 0;
}
span{
font-weight: bold;
color: blue;
}
JavaScript
/* global $ */
var options = {
sequence: [4, 8, 15, 16, 23, 42],
tries: 1000,
listTries: 1000
}
var sequence = options.sequence
var used = ''
var base = 11
var split = 'a'
for (var i = 0; i < 10; i++) {
for (var u = 0; u < sequence.length; u++) {
if (sequence[u].toString().indexOf(i.toString()) !== -1) {
used += i.toString()
}
}
if (used.indexOf(i.toString()) === -1) {
base = ''
split = i
break
}
}
var number
if (base === 11) {
number = parseInt(sequence.join(split), 11)
} else {
number = sequence.join(split)
}
var string = number.toString()
$('body').append(
'<h1>' + sequence.join(', ') + '</h1>' +
'<p>' + sequence.join(' ') + ' becomes ' + number + ' when we replace every space with the character <span>' + split + '</span>' + (base === 11 ? ' and then convert it back to decimal' : '') + '. This makes sure we have a breakpoint for when we want to get the sequence back.</p>' +
'<p>Whenever a "match" has been found, this means that <span>dividing ' + number + '</span> by the match number, then applying <span>Math.sqrt()</span> to it, then applying <span>Math.pow()</span> to it and then <span>multiplying</span> it by that number again, will yield the same result. After that, A for-loop divides this number by every number up to 100000, that when divided and then multiplied by, will yield the same result. Again.</p>' +
'<p>All steps make sure you don\'t have to use the numbers <span>' + sequence.join('</span>, <span>') + '</span> when reversing everything back.</p>'
)
function noMatch (a) {
for (var i = 0; i < sequence.length; i++) {
if (a.toString().indexOf(sequence[i].toString()) !== -1) {
return false
}
}
return true
}
function check (a) {
if (a.toString() === string) {
return true
} else {
return false
}
}
var temp
for (var i = 2; i < options.tries; i++) {
if (noMatch(i)) {
temp = number / i
temp = temp * i
if (check(temp)) {
temp = Math.sqrt(number / i, 2)
...