Re: PHP Brain Teasers
| From: | Colin Guthrie | Date: | Tue, 26 Jun 2007 23:53:02 +0000 |
| Subject: | Re: PHP Brain Teasers | ||
| References: | 1 2 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-257824@lists.php.net to get a copy of this message | ||
Colin Guthrie wrote:
> Daniel Brown wrote:
>> What the hell? Why not start a thread that can be fun and
>> challenging for all of us.
>
> One more before bed:
>
> class pin
> {
> private $mVisible;
> private $mInstantiateTime;
>
> public function __construct()
> {
> $this->mInstantiateTime = floor(time() / 86400) * 86400;
> $this->mVisible = rand() % 2;
> }
>
> public function isVisible()
> {
> return $this->mVisible;
> }
>
> public function pickup()
> {
> if ($this->mVisible)
> {
> $now = time();
> if (($now - $this->mInstantiateTime) < 86400)
> return 'Good Luck!';
> }
> return '';
> }
> }
>
> $pin = new pin();
> if ($pin->isVisible())
> $have = $pin->pickup();
>
PS I KNOW this is not LC_TIME aware and I know I double check a
condition but it's needed in the context I think ;)
Night all.
/me should have gone to be ages ago.....