Loading [Contrib]/a11y/accessibility-menu.js
Back
Close

PHP MasterMind

Anonymous
1,453 views

User Inputs

The script will need to read user inputs, and verify them before any processing.

You should never trust the user and implement a few ways to correct him of his mistake, leading him to provide a correct guess.

A mistake does not count as a try.

The script will read strings only composed of 4 numbers, removing blanks or spaces.

The codemaker will analyse a limited amount of codebreaker's guesses (10), providing either a win or a loose.

BONUS: You can implement a cheating word, resulting in an instant win, revealing the mystery code.

Hints

Here are some hints, but you really should try to find by yourself.

Click to see some hints

You can use iteration control structures such as:

You can use PHP built-in functions such as:

Solution: Ask user for input

Click to see a way to read an user input
<?php
    echo "Please guess a 4 digit number: ";
    $input = fopen("php://stdin", "r");
    $guess = fgets($input);
    $guess = trim($guess);
    $guess = str_replace(" ", "", $guess);
    var_dump($guess);
Click to see a way to do something multiple times
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
Create your playground on Tech.io
This playground was created on Tech.io, our hands-on, knowledge-sharing platform for developers.
Go to tech.io
codingame x discord
Join the CodinGame community on Discord to chat about puzzle contributions, challenges, streams, blog articles - all that good stuff!
JOIN US ON DISCORD
Online Participants