Skip to content

Instantly share code, notes, and snippets.

@besn
Created January 30, 2012 10:43
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save besn/1703805 to your computer and use it in GitHub Desktop.
Save besn/1703805 to your computer and use it in GitHub Desktop.
zufalls essen würfel dings
<?php
/*
* ----------------------------------------------------------------------------
* "THE BEER/COFFEE-WARE LICENSE" (Revision 42):
* <besn@besn.at> 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
* ----------------------------------------------------------------------------
*/
/**
* 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',
'oben' => '2',
'inder' => '2',
'kriterium' => '7',
'mader' => '7',
),
'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'
),
'michi' => array(
'pizza' => '8',
'burgerking' => '1',
'sushi' => '7',
'mexicane' => '7',
'billa' => '5',
'kent' => '3',
'wirt' => '8',
'comewok' => '3',
'schnitzelhaus' => '3',
'oben' => '9',
'inder' => '8',
'kriterium' => '7',
'vapiano' => '7'
),
);
/**
* 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
*/
arsort($found);
/**
* Das ganze ausgeben
*/
foreach($found as $name => $value)
{
echo $name." ".$value."<br />\n";
}
?>
<p><a href="http://dilbert.com/strips/comic/2011-01-02/" alt="food decisions">Q.E.D.</a></p>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment