Pathologically Eclectic Rubbish Lister PerlMonks

### comment on

 Need Help??
Eek, you're right. I just checked the Mastermind rules and it should not work like that. That is how I coded it to work, however. Here's a quick hack that seems to correct the problem... now to fix the obfuscated version...
```#!/usr/bin/perl -w

sub q {
\$; = 1;                        # \$; stores how many tries you've h
for (0..3) {
\$;[\$_] = int(rand(9))      # @; stores the correct four number
+s; set it up here
}
}

sub _ {
print @_
}

&q;

for (;;) {
\$: = \$~ = 0;        # set \$: (right number in the right spot) and
+\$~ (right number) to 0
_ "\$/\$; ";          # prints a newline then the number of tries yo
\$_ = <>;            # read a line into \$_

if (/^\d{4}\$/) {    # if the line is exactly 4 digits...
@q = split //;  # @q holds the 4 digits

--\$#q;          # set \$#q = 3, ignoring the newline at \$q[4]
\$@ = -1;        # set \$@ to -1

# This loops through the input digits and checks for correctne
+ss

my @j = @;;
for (@q) {                   # set \$_ to each of the 4 input d
+igits
(\$_ eq \$j[++\$@]) && ++\$: && (\$j[\$@]='X') && (\$q[\$@]='Y')
}
for (@q) {                   # set \$_ to each of the 4 input d
+igits
\$a = \$_;                 # set \$a to the current digit (wh
+y not leave it \$_?)
(grep /\$a/, @j) && ++\$~  # else increment \$~ if you have a
+ right number in the wrong spot
}

_ "\$~W\$:B ";  # print out the total of right/wrong (\$~W) and r
+ight/right (\$:B)
++\$;;         # increment number of tries

\$: == 4       # if we have four right numbers all in the right
+ spots
| \$; > 10 # or we have already had 10 tries
&& _ (@;) # print out the correct answer
&& &q     # and start the game over
}
}

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":

• Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
• Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
• Read Where should I post X? if you're not absolutely sure you're posting in the right place.
• Posts may use any of the Perl Monks Approved HTML tags:
a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
• You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
 For: Use: & & < < > > [ [ ] ]
• Link using PerlMonks shortcuts! What shortcuts can I use for linking?

Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others making s'mores by the fire in the courtyard of the Monastery: (5)
As of 2024-09-16 12:35 GMT
Sections?
Information?
Find Nodes?
Leftovers?
Voting Booth?
The PerlMonks site front end has:

Results (22 votes). Check out past polls.

Notices?
 • erzuuli ‥ 🛈The London Perl and Raku Workshop takes place on 26th Oct 2024. If your company depends on Perl, please consider sponsoring and/or attending.