Scrambling rubik’s cube in bash

If you don’t like oneliners or prefer pure-bash, here is how to print a sequence of moves to scramble the cube.

Si vous n’aimes pas les oneliners ou préférez le pure bash, voilà comment afficher une séquence de coups pour mélanger le cube.

#!/bin/bash

# Note variables spread over multiple lines.

t=(U R F L B D)
t2=(" " "'" "2")

MAXCOUNT=$((15+$RANDOM%10))
count=1

while [ "$count" -le $MAXCOUNT ]
do
echo -n ${t[$((RANDOM%6))]}
echo -n ${t2[$((RANDOM%3))]}" "
let "count += 1"
done

echo

exit 0

Via: Advanced Bash-Scripting Guide

~ by loquehumaine on 2008, July 28 - Monday.

3 Responses to “Scrambling rubik’s cube in bash”

  1. Thanks, very useful :-)

  2. Nice code, im working on a way to make it non-cancelling (which is against WCA regulations), ill post back

  3. Thanks =]
    One way to avoid cancelling is to split the move:
    tu=(U D)
    tr=(R L)
    tf=(F B)
    and then force one move of tr to succeed one move of tu, etc.
    It won’t solve everything but it should reduce a lot the possibilities of going backward

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

 
%d bloggers like this: