Restrictive Move Solving

Ok, if you want to see short code then here's mine:
Code:
print+('R','U')[$_&1],('','\'','2')[int rand3],' 'for(0..24);
The original program is more useful, because it gives 20 scrambles every time you press Enter. But this works, too. 61 characters.
 
There's something wrong with your computer, then, if it's giving same random numbers every time. ;)
 
Its the 'int rand3', because rand3 is null it gives 0 all the time. If I change it to 'int rand 3', it works!

The $_&1 is clever, I'm trying to think of how I can do that in Ruby.

Here we go:
Code:
$><<(0..24).map{|x|%w(R U)[x&1]+"#{%w(' 2)[rand 2]} "}

54 characters.
 
Does your code ever give R or U, or just R' U2 R2 U' etc.? And does it print the scramble? Sorry, I don't know Ruby at all so I'm just guessing from the code.


Edit: 41
Code:
print+($_&1?R:U).qw(' 2)[rand 3]for 0..24
 
Last edited by a moderator:
Yes it gives R and U aswell, and it does print the scramble.

I'm sure ubuntu has it on default.

I was waiting for you to change ('R','U')to qw(R U)!

Edit: 46 characters

Code:
24.times{|x|$><<%w(R U)[x&1]<<%w(' 2)[rand 3]}
 
Last edited:
bash: ruby: command not found

I installed Ruby 1.8, and it's working now. I see you just changed [rand 2] to [rand 3], that gives also R and U. I'm sure you can't beat my 41, Perl is just better!
 
Perl, as everyone knows, is a golfers best tool!

Before I had: "#{%w(' 2)[rand 2]} "

If "%w(' 2)[rand 2]" was nil (or null in perl), it would just give a blank space. But since were now giving out scramble without spacees, ie RUR', rather than R U R'. I could remove all that and just do "%w(' 2)[rand 3]".
 
Which is easier to learn C++ or Java? And do they have a specific area of interest(one is better for games, other is better for application type stuff?).

I actually was going to learn C/C++ a while back because I wanted to code for the PSP(there's a huge hacker base there, just check pspupdates.qj.net). So I would think that C is better for me to learn.
 
Originally posted by dChan@May 14 2007, 05:32 PM
Which is easier to learn C++ or Java? And do they have a specific area of interest(one is better for games, other is better for application type stuff?).
I very rarely use Java. Although my application of programming only extends to programming competitions now, I almost always prefer C++ over it.

Java is used a lot for internet applications, C++ is used more for other programs. An example is Mangos (World of Warcraft server).
 
Originally posted by dChan@May 14 2007, 05:32 PM
Which is easier to learn C++ or Java? And do they have a specific area of interest(one is better for games, other is better for application type stuff?).

I actually was going to learn C/C++ a while back because I wanted to code for the PSP(there's a huge hacker base there, just check pspupdates.qj.net). So I would think that C is better for me to learn.
Easier to learn? Depends. Some people say C++ is quite hard to start out with; I disagree. I started out with C++ and didn't have much trouble.

Specific areas of interest? Let's see...Java is pretty much for web applications (though you can make standalone applications with it too). C/C++ works for just about everything outside of the web. Drawing things is a pain in C++ with Windows. Most commercial games are written in C++ with DirectX (which is very confusing for a beginner). Just a few notes.

I'd recommend C++.
 
Code:
<?
$end = array(' ', '2 ', '\' ');
for ($i=0; $i<25; $i++)
{
($i%2 == 0) ? $next = "R" : $next = "U";
 $next .= $end[rand(0,2)];
echo $next;
}
?>

Can't think of a way to make this any shorter besides renaming variables and taking out whitespace. Ah well...it's shorter than my original php code, anyway.

Edit: Actually, I take that back; here's some shorter code:

Code:
<?
$end = array(' ', '2 ', '\' ');
for ($i=0; $i<25; $i++)
{echo ($i%2 == 0) ? "R" : "U";
echo $end[rand(0,2)];}
?>

I know there's some simple way to combine the two echo's, but can't see how :unsure:
 
Back
Top