Jump to content

How To Convert This In To Arryers


Recommended Posts

I have cratet a script to generate a menu for 4 weeks.

But i cant finde out how to convert it so i writes a week in to an arrayer so i can pervent that the same meal comes up 2 times a week

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

Global $Uge, $Last

;While 1
;   Sleep(100)
;   _WriteMenu()
;   Exit
;WEnd

;Func _WriteMenu()
    $Y = 0
    $Uge = "19"
    
    Do
        $Uge = $Uge + 1
        $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 = 4
    Exit
;EndFunc


;Funktionen udvælg retter
Func _Retter()
    $i = 0
    $NumberOfLines = _FileCountLines(@ScriptDir & "\Retter.txt")
    Do 
        $i = $i+1
    $Retter = Random(1,$NumberOfLines,1)
    $Read = FileReadLine("Retter.txt", $Retter)
;Checker at den samme ret kommer 2 dage i træk
        If $Read = "Johnnys chilisuppe" Then
        $i = $i +1
    EndIf
    If $Read = "Pizza" Then
        $i = $i + 1
        EndIf
    FileWrite("Menu.txt", $Read & @CRLF)
Until $i = 7
EndFunc

#CE

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

Global $Uge

    $Y = 0
    $Uge = _WeekNumberISO()
    
    Do
        $Uge = $Uge + 1
        $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 = 4
    Exit

;Funktionen udvælg retter
Func _Retter()
    $i = 0
    $NumberOfLines = _FileCountLines(@ScriptDir & "\Retter.txt")
    
    $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 = FileReadLine("Retter.txt", $Retter)
         Until $Read <> $prev_meal

;Hvs det er retter der passer til 2 dage så skal der kun være "6" dage på en uge
        If $Read = "Johnnys chilisuppe" or $Read = "Johnnys tomatsuppe" Or $Read = "Pizza" Then
        $i = $i +1
    EndIf
    
    If StringInStr($prev_meal, "suppe") Then
        $i = $i -1
        Else
    FileWrite("Menu.txt", $Read & @CRLF)
    EndIf
  
  ;record the meal to check for same meal in next loop iteration
     $prev_meal = $Read

Until $i = 7
EndFunc

Can any one help me

Link to comment
Share on other sites

As you generate your meals, store them in the array of meals for the next 4 weeks.

;this is the array of meals for the next 4 weeks
$meals[28]

$new = 1
$curr_meal = The Meal You are Currently Trying To Generate


while $new = 1
       ;generate a new meal
        $next_meal = RANDOM_MEAL
        $new = 0

       ;this loop will check the current meal against other meals from that week
        for $iter = Int( $curr_meal / 7 ) * 7 To $curr_meal
             if meals[$curr_meal] = meals[$iter] then
                  $new = 1
             endif
        Next 
wend

meals[$curr_meal] = $next_meal

This code should work, it will generate new meals continuously uintil it finds a meal that is not already scheduled for the week. It will only check against other meals from that week, not the whole 4 week period.

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

Link to comment
Share on other sites

As you generate your meals, store them in the array of meals for the next 4 weeks.

;this is the array of meals for the next 4 weeks
$meals[28]

$new = 1
$curr_meal = The Meal You are Currently Trying To Generate
while $new = 1
      ;generate a new meal
        $next_meal = RANDOM_MEAL
        $new = 0

      ;this loop will check the current meal against other meals from that week
        for $iter = Int( $curr_meal / 7 ) * 7 To $curr_meal
             if meals[$curr_meal] = meals[$iter] then
                  $new = 1
             endif
        Next 
wend

meals[$curr_meal] = $next_meal

This code should work, it will generate new meals continuously uintil it finds a meal that is not already scheduled for the week. It will only check against other meals from that week, not the whole 4 week period.

Wow that i never could have don on my own.

Don't even know where to put in my code ? But thanks now im suer that i dont have to eat the same meal twice a week :)

Link to comment
Share on other sites

But thanks now im suer that i dont have to eat the same meal twice a week

lol, Glad to see you'll be branching out :)

Lemme know if u need nemore help getting that code workin...

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

Link to comment
Share on other sites

lol, Glad to see you'll be branching out :)

Lemme know if u need nemore help getting that code workin...

Well if you wan't to :(

My wife want me to make sure that we dont get the same meal for 3 weeks.. Can your code be convertet into that ?

And please show me where to put it in my existing code, course all i have tryed has ben giving my errors

/Rex

Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...