Ejemplo n.º 1
0
            $tweet = $tweetTo . " " . $phrasesForMentions[array_rand($phrasesForMentions)];
        } while (strlen($tweet) > 140);
        // Post the tweet
        $postfields = array('status' => $tweet, 'in_reply_to_status_id' => $mention->id_str);
        $url = "https://api.twitter.com/1.1/statuses/update.json";
        $requestMethod = "POST";
        $twitter->resetFields()->buildOauth($url, $requestMethod)->setPostfields($postfields)->performRequest();
    }
}
// THEN SURPRISE RANDOM TWEET
// The script should tweet randomly a few times per day depending on the number of followers
// The more followers, the more random tweets
function formula($nbfollowers, $calledEvery)
{
    $timesPerDay = 24 * (60 / $calledEvery);
    return $nbfollowers > 1 ? $nbfollowers * 2 / (log($timesPerDay, 2) * log($nbfollowers, 2)) / ($timesPerDay / 2) : 0.5 / ($timesPerDay / 2);
}
// Test if should tweet or not
$p = formula(count($followersList), $calledEvery);
if (mt_rand() / mt_getrandmax() < $p) {
    $randfollower = $followersList[array_rand($followersList)];
    $screenName = $randfollower->screen_name;
    do {
        $tweet = "@" . $screenName . " " . $phrases[array_rand($phrases)];
    } while (strlen($tweet) > 140);
    // Post the tweet
    $postfields = array('status' => $tweet);
    $url = "https://api.twitter.com/1.1/statuses/update.json";
    $requestMethod = "POST";
    $twitter->resetFields()->buildOauth($url, $requestMethod)->setPostfields($postfields)->performRequest();
}
Ejemplo n.º 2
0
$max_row = 3019 * 2;
// grid gets filled diagonally, so the value we need
$max_col = 3019 * 2;
// isn't present until grid is twice larger
function formula($n)
{
    return $n * 252533 % 33554393;
}
while ($row <= $max_row && $col <= $max_col) {
    if (!isset($grid[$row][$col])) {
        if ($col == 0) {
            $prev_col = $row - 1;
            $prev_row = 0;
        } else {
            $prev_row = $row + 1;
            $prev_col = $col - 1;
        }
        $grid[$row][$col] = formula($grid[$prev_row][$prev_col]);
    }
    if ($row == 0) {
        $row = $col + 1;
        if (!isset($grid[$row])) {
            $grid[$row] = array();
        }
        $col = 0;
    } else {
        $row--;
        $col++;
    }
}
var_dump($grid[$target_row][$target_col]);
Ejemplo n.º 3
0
<?php

$input = "Sprinkles: capacity 2, durability 0, flavor -2, texture 0, calories 3\n            Butterscotch: capacity 0, durability 5, flavor -3, texture 0, calories 3\n            Chocolate: capacity 0, durability 0, flavor 5, texture -1, calories 8\n            Candy: capacity 0, durability -1, flavor 0, texture 5, calories 8";
$max_spoons = 101;
$highest_score = 0;
function formula($first, $second, $third, $fourth)
{
    $capacity = max($first * 2 + $second * 0 + $third * 0 + $fourth * 0, 0);
    $durability = max($first * 0 + $second * 5 + $third * 0 + $fourth * -1, 0);
    $flavor = max($first * -2 + $second * -3 + $third * 5 + $fourth * 0, 0);
    $texture = max($first * 0 + $second * 0 + $third * -1 + $fourth * 5, 0);
    $calories = max($first * 3 + $second * 3 + $third * 8 + $fourth * 8, 0);
    return $calories == 500 ? $capacity * $durability * $flavor * $texture : 0;
}
for ($f = 0; $f < $max_spoons; $f++) {
    for ($s = 0; $s < $max_spoons - $f; $s++) {
        for ($t = 0; $t < $max_spoons - ($f + $s); $t++) {
            $o = 100 - ($t + $f + $s);
            $total = formula($f, $s, $t, $o);
            if ($total > $highest_score) {
                $highest_score = $total;
            }
        }
    }
}
var_dump($highest_score);
Ejemplo n.º 4
0
function formula($x)
{
    // $a - глобальная
    global $a;
    // $b - локальная
    $b = 10;
    return $a * $b + $x;
}
?>

<?php 
print "A = {$a}";
?>
 ($a всё ещё определена)<br>
Формула = <?php 
print formula($c);
?>
 (формула тоже)<br>

===============================================================================================================
<h2>Цикл - вывод таблицы</h2>

<?php 
print "<table border=\"1\" style='padding: 1px;'>";
for ($i = 1; $i <= 5; $i++) {
    print "<tr>";
    for ($j = 1; $j <= 10; $j++) {
        print "<td>Ячейка " . $i . " - " . $j . "</td>\n";
    }
    // для читабельности html - перенос кода но новую строку
    print "\n";