It’s Friday, and time again for the Friday Fragment: our weekly programming-related puzzle.
This Week’s Fragment
This week, we’ll take another step in our web service “bot wars:”
To “play along”, provide either the URL or the code for the solution. You can post it as a comment or send it via email. If you’d like, you can build atop results from our last Friday Fragment.
Last Week’s Fragment – Solution
Last week’s puzzle continued along our simple web service vein with the flip-side: calling a web service.
Write code to call your rock, paper, scissors web service and keep counts of how many times each is returned.
Here’s a really simple solution in PHP:
<?php $counts = array("rock" => 0, "paper" => 0, "scissors" => 0); $url = 'http://derekwilliams.us/bots/rps'; for ($i=0; $i<100; $i++) $counts[file_get_contents($url)]++; print_r($counts); ?>
It’s a bit oversimplified (e.g., no error handling), but does the job.