Sign in to follow this  
Followers 0
Rex

Dinner Menu creater for 4 weeks

10 posts in this topic

Hi

Long time ago i did this script, to generate a dinner menu for 4 weeks, and by a little help from a forum user i got i to work so i did't got the same meal 2 days in a row...

#include <GUIConstants.au3>; Includes Gui Constants
#include <file.au3>
#include <string.au3>
#include <Date.au3>

Global $Uge, $Sektioner

    $Y = 0
    $Uge = _WeekNumberISO()
    
    Do
        $Uge = $Uge + 2
        $Y = $Y+1
        If $y = 1 Then
            FileWrite("Menu.txt",">>>> Menu uge " & $Uge & " <<<<" & @CRLF)
            Else
        FileWrite("Menu.txt","" & @CRLF & ">>>> Menu uge " & $Uge & " <<<<" & @CRLF)
        EndIf
        _Retter()
        Until $Y = 3
    Exit


;Funktion choose meeals
Func _Retter()
    $i = 0
    $NumberOfLines = _FileCountLines(@ScriptDir & "\Retter.txt")
    Dim $Retter
    $prev_meal = ""

    Do
        $i = $i+1
        
       ;this loop will prevent 2 of the same meals in a row
         Do
               $Retter = Random(1,$NumberOfLines,1)
               $Read = IniRead("Retter.txt", $Retter, "key", "Valgfri ret")
           Until $Read <> $prev_meal
           IniDelete("Retter.txt", $Retter)
; If meeal fits a 2 day meeal then we cuts of a day of the week
        If $Read = "Johnnys chilisuppe" or $Read = "Johnnys tomatsuppe" Or $Read = "Pizza" Then
        $i = $i +1
    EndIf
    
    FileWrite("Menu.txt", $Read & @CRLF)
      
;record the meal to check for same meal in next loop iteration
     $prev_meal = $Read

Until $i = 7
EndFunc

Now after having used thi meal generator for some time, we (my wife and i) have fount that the meals ar't that random, the same meal some times comes 2-3 times a week or month.

So now i hope that i can get some help here, to make i work in arrayers sow i can be sure that the same meal only comes ones per month....

My prob is i can get into my head how thoes arrayers work, some on told me that i schould see it like a exel map, but i still don't get it.

Please if some on can help me make this meeal generator work :)

/Rex

Share this post


Link to post
Share on other sites



#3 ·  Posted (edited)

Hi

Long time ago i did this script, to generate a dinner menu for 4 weeks, and by a little help from a forum user i got i to work so i did't got the same meal 2 days in a row...

#include <GUIConstants.au3>; Includes Gui Constants
#include <file.au3>
#include <string.au3>
#include <Date.au3>

Global $Uge, $Sektioner

    $Y = 0
    $Uge = _WeekNumberISO()
    
    Do
        $Uge = $Uge + 2
        $Y = $Y+1
        If $y = 1 Then
            FileWrite("Menu.txt",">>>> Menu uge " & $Uge & " <<<<" & @CRLF)
            Else
        FileWrite("Menu.txt","" & @CRLF & ">>>> Menu uge " & $Uge & " <<<<" & @CRLF)
        EndIf
        _Retter()
        Until $Y = 3
    Exit
;Funktion choose meeals
Func _Retter()
    $i = 0
    $NumberOfLines = _FileCountLines(@ScriptDir & "\Retter.txt")
    Dim $Retter
    $prev_meal = ""

    Do
        $i = $i+1
        
       ;this loop will prevent 2 of the same meals in a row
         Do
               $Retter = Random(1,$NumberOfLines,1)
               $Read = IniRead("Retter.txt", $Retter, "key", "Valgfri ret")
           Until $Read <> $prev_meal
           IniDelete("Retter.txt", $Retter)
; If meeal fits a 2 day meeal then we cuts of a day of the week
        If $Read = "Johnnys chilisuppe" or $Read = "Johnnys tomatsuppe" Or $Read = "Pizza" Then
        $i = $i +1
    EndIf
    
    FileWrite("Menu.txt", $Read & @CRLF)
      
;record the meal to check for same meal in next loop iteration
     $prev_meal = $Read

Until $i = 7
EndFuncoÝ÷ ØÚ0iû^®¯x.±çm)jXêڶߢ»(ëbì,"}æ§v(Z½çèº{m«méj[¯m¶­­©Ý¢kazƦzgÊ&zئzÇ(ë6ÞئzÆ°yé(®j'¶¨"^¶­Æ§ël¢g¡zZaz·­¢f¤z,(®H§jºÚÉêì²"q©ÛzË«zØZ¶Ø^±©æ¥¢yrr²Þ²«íÌ©®â²'­{h(^iØhÂØhzÆ«­¬®Ì(®K(ê'¶]ëajجr.Ûz+eG{¥ª[ºØ¬¶)ev÷öض+Oæ¬z'ì¢g¨Æ§éiéëaÉy©`zw«jÚ+Âäº{.­ïÑ{êº^ȧWg§²*'j]CjºÚÊ+#ºËZéz·+-jëh×6#include <array.au3>

Dim $aVeg[4] = [Peas, Carrots, Zuccini, Corn]
_ArrayDisplay("Veggies", $aVeg)oÝ÷ ØÚ-Ç­«mç+y«^vX¬¶øצ²+'ºfÞ­çt¶îÜéÜ{*.¦ëm)à²)Úªëk,¨¹Æ§ué^µëazf®¶­sb6æ6ÇVFRfÇC¶'&æS2fwC° ¤FÒb33c¶fVu³EÒÒµV2Â6'&÷G2§V66æÂ6÷&åÐ¥ô'&FVÆWFRb33c¶fVrÂ"¥ô'&F7ÆgV÷CµfVvvW2gV÷C²Âb33c¶fVr

That should allow you to make a list and then remove things from the list to prevent repeating them.

:)

Edited by PsaltyDS

Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law

Share this post


Link to post
Share on other sites

A single dimensional (1D) array is just a numbered list:

#include <array.au3>

Dim $aVeg[4] = [Peas, Carrots, Zuccini, Corn]
_ArrayDisplay("Veggies", $aVeg)oÝ÷ ØÚ-Ç­«mç+^vX¬¶øצ²+'ºfÞ­çt¶îÜéÜ{*.¦ëm)à²)Úªëk,¨¹Æ§ué^µëazf®¶­sb6æ6ÇVFRfÇC¶'&æS2fwC° ¤FÒb33c¶fVu³EÒÒµV2Â6'&÷G2§V66æÂ6÷&åÐ¥ô'&FVÆWFRb33c¶fVrÂ"¥ô'&F7ÆgV÷CµfVvvW2gV÷C²Âb33c¶fVr

That should allow you to make a list and then remove things from the list to prevent repeating them.

:D

But i'm reading random from a txt file, how do i know what to del and ehat not to del, when i don't know whats in the array'er :P

And i still don't get the array'er thing, i do belive that i must finde som one who can teach me it in my own lang. first :)

But thx for trying to teach me it :D

/Rex

Share this post


Link to post
Share on other sites

Computers can't create random numbers. Even the helpfile states this is function "Returns a pseudo-random number between Min and Max." Since this is based off an equation, it will do it's best to create a "random" number, however the equation will keep hitting the same numbers. Why not try doing something like taking the random number multiplied by the minute or second so that it has constantly changing information to help increase it's "randomness".


Aha.. I have unlocked it's secrets.. world domination is within my grasp...

Share this post


Link to post
Share on other sites

Hey rex, im pretty sure i helped you on this thing last time. What exectly are you trying to change this script to do? Do you want unique meals for every day of the month. By this I mean to you only want to eat the same meal once a month? or can it happen as often as once a week? Let me know exactly what you need and I'd be more than willing to help out again.


_____________________________________________________"some people live for the rules, I live for exceptions"Wallpaper Changer - Easily Change Your Windows Wallpaper

Share this post


Link to post
Share on other sites

If you wouldn't mind, I would like to see the final working code. My wife can be "particular" on what she wants for dinner. This looks like it would really help.

NP, when the final code is final :) ill post it here

/Rex

Share this post


Link to post
Share on other sites

Hey rex, im pretty sure i helped you on this thing last time. What exectly are you trying to change this script to do? Do you want unique meals for every day of the month. By this I mean to you only want to eat the same meal once a month? or can it happen as often as once a week? Let me know exactly what you need and I'd be more than willing to help out again.

HI Don

That Sounds right, but coulden rember who helped me, normaly i adds Credits in my code to thoes who haved helped me, but this time i'd forgot...

What we (my whife and i) wants, is to get a random menu created for 4 weeks, problem with this generator is that we might get tha same mealt 2 - 3 times a month some times ig generates the same meal Sunday and monday or monday and sunday so the same meals comes 2 times a week...

/Rex

Share this post


Link to post
Share on other sites

Computers can't create random numbers. Even the helpfile states this is function "Returns a pseudo-random number between Min and Max." Since this is based off an equation, it will do it's best to create a "random" number, however the equation will keep hitting the same numbers. Why not try doing something like taking the random number multiplied by the minute or second so that it has constantly changing information to help increase it's "randomness".

That could might work, but i get my max from the readlines so if i multiply the "random" with the time(sec) im quite sure that i will end far away from my max :)

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0