-
-
Save azet/1703838 to your computer and use it in GitHub Desktop.
zufalls essen würfel dings
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/* | |
* ---------------------------------------------------------------------------- | |
* "THE BEER/COFFEE-WARE LICENSE" (Revision 42): | |
* <[email protected]> wrote this file. As long as you retain this notice you | |
* can do whatever you want with this stuff. If we meet some day, and you think | |
* this stuff is worth it, you can buy me a beer or a coffee in return. Andi Mery | |
* ---------------------------------------------------------------------------- | |
*/ | |
/** | |
* Wohin können wir essen gehn? | |
*/ | |
$wohin = array("pizza", "burgerking", "sushi", "mexicane", "vapiano", "machu machu","kent","wirt","comewok"); | |
/** | |
* Preferenzen der Locations auf einer Skala von 1 bis 10 | |
*/ | |
$preferenzen = array( | |
'besn' => array( | |
'pizza' => '10', | |
'burgerking' => '10', | |
'sushi' => '0', | |
'mexicane' => '8', | |
'billa' => '5', | |
'kent' => '8', | |
'wirt' => '8', | |
'comewok' => '5', | |
'schnitzelhaus' => '8' | |
), | |
'azet' => array( | |
'pizza' => '8', | |
'burgerking' => '4', | |
'sushi' => '5', | |
'mexicane' => '8', | |
'billa' => '2', | |
'kent' => '7', | |
'wirt' => '8', | |
'comewok' => '5', | |
'schnitzelhaus' => '5', | |
'oben' => '6', | |
'inder' => '6', | |
'kriterium' => '7', | |
'vapiano' => '5' | |
), | |
); | |
/** | |
* Gewichtung ausrechnen | |
*/ | |
foreach($preferenzen as $wer => $prefs) { | |
foreach($prefs as $was => $rating) { | |
$gewichtung[$was] = $gewichtung[$was] + $rating; | |
} | |
} | |
foreach($gewichtung as $was => $gewicht) { | |
for($x=0; $x<$gewichtung[$was]; $x++) | |
{ | |
$gewichtet[] = $was; | |
} | |
} | |
/** | |
* Würfeln wohin wir essen gehn | |
*/ | |
$x = count($gewichtet)-1; | |
for($y = 0 ; $y < 100 ; $y++) { | |
$i = mt_rand(0, $x); | |
$found[$gewichtet[$i]] = $found[$gewichtet[$i]] + 1; | |
} | |
/* | |
* Sortiern wir das ganze noch | |
*/ | |
ksort($found); | |
/** | |
* Das ganze ausgeben | |
*/ | |
foreach($found as $name => $value){ | |
echo "<p><a href=\"http://dilbert.com/strips/comic/2011-01-02/\" alt=\"food decisions\">Q.E.D.</a></p>"; | |
echo $name." ".$value."<br />\n"; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment