Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PHP Solution #17

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

claytonkreisel
Copy link

This function is a little slower, but it works tremendously well. I wrote about it and made a video showing my work on my own labs page. I would love for you to check it out when you can: https://claytonkreisel.com/viget-labs-unscramble-challenge/.

This function is a little slower, but it works tremendously well. I wrote about it and made a video showing my work on my own labs page. I would love for you to check it out when you can: https://claytonkreisel.com/viget-labs-unscramble-challenge/.
@claytonkreisel
Copy link
Author

This function is a little slower, but it works tremendously well. I wrote about it and made a video showing my work on my own labs page. I would love for you to check it out when you can: https://claytonkreisel.com/viget-labs-unscramble-challenge/.

I know there is no Rake file. That is because... well... PHP.

@cwmanning
Copy link
Member

thanks, @claytonkreisel! it works for me, but I made a couple of changes locally to get it to run in this repo format. interested in trying that out? here's what I did:

  1. renamed unscramble.php to unscramble
  2. made the file executable: chmod +x unscramble
  3. added one line to the top, and three to the bottom:
#!/usr/bin/env php
<?php

    //Take scrambled into and output a single unscrambled word
    function unscramble($input)
    {
        $output = '';

        //Collect an array of English words
        $words = json_decode(file_get_contents('https://raw.githubusercontent.com/dwyl/english-words/master/words_dictionary.json'), true);

        //Split our input into letters and sort alphaabetically
        $input_array = str_split($input);
        sort($input_array);

        //Loop through the array of words and split each word alphaabetically
        foreach ($words as $word => $number) {
            $word_array = str_split($word);
            sort($word_array);

            if ($input_array === $word_array) {
                $output = $word;
                break;
            }
        }

        return $output;
    }

$input = $argv[1];
$output = unscramble($input) . "\n";
echo $output;
  1. added a Rakefile:
namespace :PHP do
  task :check do
    `which php`
    raise "Please ensure that you have php installed" unless $?.success?
  end

  task :build => :check do
  end
end

After these steps, I was able to run the PHP version from the command line. Let me know if you have any questions! Also, thanks to some recent additions, if you rebase from master, you can use rake run[php] to run the PHP language tests only.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants