Recently, I got a job vacancy test and this is the one of questions i've got. I'm absolutely new here so CMIIW 😉
Simply download the gist and create new file called whatever.php
then copy-paste lines below:
!#/usr/bin/env php
<?php
// Load the file
require 'ThueMorse.php';
// Pop the last argument
$seq = (int) array_pop($_SERVER['argv']);
// Initiate the class
$thueMorse = new ThueMorse;
// Simply dump it
var_dump($thueMorse->calculate($seq));
// or concat the result as string
// echo implode('', $thueMorse->calculate($seq));
Back to your terminal and run
$ php whatever.php 5
You'll see something like this
array(6) {
[0] =>
string(1) "0"
[1] =>
string(2) "01"
[2] =>
string(4) "0110"
[3] =>
string(8) "01101001"
[4] =>
string(16) "0110100110010110"
[5] =>
string(32) "01101001100101101001011001101001"
}
Great!