• Welcome to the Speedsolving.com, home of the web's largest puzzle community!
    You are currently viewing our forum as a guest which gives you limited access to join discussions and access our other features.

    Registration is fast, simple and absolutely free so please, join our community of 35,000+ people from around the world today!

    If you are already a member, simply login to hide this message and begin participating in the community!

Oat in January (Ruby scrambler 2.0)

Joined
Nov 2, 2009
Messages
1,141
Likes
4
Thread starter #1
Still not perfect, but I improved the code, and added a little bit of move canceling.

lastnum = -1
moves = ["U","D","L","R","F","B","U'","D'","L'","R'","F'","B'","U2","D2","L2","R2","F2","B2"]
25.times do

pick = rand(18)
if lastnum == pick
until not pick == lastnum
pick = rand(18)
end
end
print moves[pick]
print " "
lastnum = pick
end
 
Joined
Nov 2, 2009
Messages
1,141
Likes
4
Thread starter #3
I can't say if its good or not because I don't know about programming in ruby.
But couldn't you wait until you're completely done and THEN release it?
I say this because I make the same mistake all the time.
I am completely done. It's just an experiment, not a huge project
 

Lucas Garron

Moderator
Staff member
Joined
Jul 6, 2007
Messages
3,557
Likes
92
Location
California
WCA
2006GARR01
YouTube
LucasGarron
#4
Code:
~/ruby a.rb 
L D R' D2 B2 U R L2 L L' R D' U R2 U' B2 U' U2 U' R D U R2 D' U
U' U2 U', seriously?
Just separate your suffices from the moves: ["U","D","L","R","F","B"] and ["", "2", "'"]. Makes move checking easier, and makes for cleaner code instead of hardcoding all the moves.
 
Joined
Feb 18, 2008
Messages
360
Likes
0
#5
You should get into the habit of using indentation so that your code is readable. I'm not sure about the specifics of Ruby, but I would do something like this:

(without Lucas' suggestion implemented, which is a good one by the way)
Code:
lastnum = -1
moves = ["U","D","L","R","F","B","U'","D'","L'","R'","F'"," B'","U2","D2","L2","R2","F2","B2"]

25.times do
    pick = rand(18)
    if lastnum == pick
        until not pick == lastnum
            pick = rand(18)
        end
    end
    print moves[pick]
    print " "
    lastnum = pick
end
You should keep working on this. It's not a successful "experiment" if it doesn't work right. You won't learn anything by stopping before your code works correctly. ;)

My result: L' D B' B2 U2 R D U2 F D U U' L2 U' B' R' L2 B2 L2 L B F' B' B2 F2

:eek:
 
Joined
Nov 2, 2009
Messages
1,141
Likes
4
Thread starter #6
You should get into the habit of using indentation so that your code is readable. I'm not sure about the specifics of Ruby, but I would do something like this:

(without Lucas' suggestion implemented, which is a good one by the way)
Code:
lastnum = -1
moves = ["U","D","L","R","F","B","U'","D'","L'","R'","F'"," B'","U2","D2","L2","R2","F2","B2"]

25.times do
    pick = rand(18)
    if lastnum == pick
        until not pick == lastnum
            pick = rand(18)
        end
    end
    print moves[pick]
    print " "
    lastnum = pick
end
You should keep working on this. It's not a successful "experiment" if it doesn't work right. You won't learn anything by stopping before your code works correctly. ;)

My result: L' D B' B2 U2 R D U2 F D U U' L2 U' B' R' L2 B2 L2 L B F' B' B2 F2

:eek:
It was indented, but the indentation was lost when I copied and pasted it.
 
Top