Skip to main content
added 1 character in body
Source Link
RedClover
  • 797
  • 7
  • 25

Fountain

A simple bot, picks the lowest number first and if any other bot chooses it too, it will increment the counter - the floor gets filled and the water flows down. When it reaches 11, it restarts to 1 - the water gets pumped back to the top.

class Fountain:

    def __init__(self, index, target=7target=10):

        # Set data
        self.index = index
        self.pick  = 1
        self.target = target+1

    def select(self):

        # Select the number
        return self.pick

    def update(self, choices: list):

        # Remove self from the list
        choices.pop(self.index)  # I hope `choices[:]` is passed, not `choices`.

        # While the selected number is occupied
        while self.pick in choices:

            # Pick next number
            self.pick += 1

            # If target was reached
            if self.pick == self.target:

                # Reset to 1
                self.pick = 1

Fountain

A simple bot, picks the lowest number first and if any other bot chooses it too, it will increment the counter - the floor gets filled and the water flows down. When it reaches 11, it restarts to 1 - the water gets pumped back to the top.

class Fountain:

    def __init__(self, index, target=7):

        # Set data
        self.index = index
        self.pick  = 1
        self.target = target+1

    def select(self):

        # Select the number
        return self.pick

    def update(self, choices: list):

        # Remove self from the list
        choices.pop(self.index)  # I hope `choices[:]` is passed, not `choices`.

        # While the selected number is occupied
        while self.pick in choices:

            # Pick next number
            self.pick += 1

            # If target was reached
            if self.pick == self.target:

                # Reset to 1
                self.pick = 1

Fountain

A simple bot, picks the lowest number first and if any other bot chooses it too, it will increment the counter - the floor gets filled and the water flows down. When it reaches 11, it restarts to 1 - the water gets pumped back to the top.

class Fountain:

    def __init__(self, index, target=10):

        # Set data
        self.index = index
        self.pick  = 1
        self.target = target+1

    def select(self):

        # Select the number
        return self.pick

    def update(self, choices: list):

        # Remove self from the list
        choices.pop(self.index)  # I hope `choices[:]` is passed, not `choices`.

        # While the selected number is occupied
        while self.pick in choices:

            # Pick next number
            self.pick += 1

            # If target was reached
            if self.pick == self.target:

                # Reset to 1
                self.pick = 1
Fix a bug, slightly improve the mechanism
Source Link
RedClover
  • 797
  • 7
  • 25

Fountain

A simple bot, picks the lowest number first and if any other bot chooses it too, it will increment the counter - the floor gets filled and the water flows down. When it reaches 11, it restarts to 1 - the water gets pumped back to the top.

class Fountain:

    def __init__(self, index, target=7):

        # Set data
        self.index = index
        self.pick  = 1
        self.target = target+1

    def select(self):

        # Select the number
        return self.pick

    def update(self, choices: list): 

        # Remove self from the list
        choices.pop(self.index)  # I hope `choices[:]` is passed, not `choices`.

        for choice in choices:

# While the selected number is occupied
      if choice ==while self.pick in choices:

            # Pick next number
            self.pick += 1 

            # If target was reached
            if self.pick == 11self.target: 

                # Reset to 1
                self.pick = 1

Fountain

A simple bot, picks the lowest number first and if any other bot chooses it too, it will increment the counter - the floor gets filled and the water flows down. When it reaches 11, it restarts to 1 - the water gets pumped back to the top.

class Fountain:

    def __init__(self, index):

        self.index = index
        self.pick  = 1

    def select(self):

        return self.pick

    def update(self, choices: list):

        choices.pop(self.index)  # I hope `choices[:]` is passed, not `choices`.

        for choice in choices:

            if choice == self.pick:

                self.pick += 1

            if self.pick == 11:

                self.pick = 1

Fountain

A simple bot, picks the lowest number first and if any other bot chooses it too, it will increment the counter - the floor gets filled and the water flows down. When it reaches 11, it restarts to 1 - the water gets pumped back to the top.

class Fountain:

    def __init__(self, index, target=7):

        # Set data
        self.index = index
        self.pick  = 1
        self.target = target+1

    def select(self):

        # Select the number
        return self.pick

    def update(self, choices: list): 

        # Remove self from the list
        choices.pop(self.index)  # I hope `choices[:]` is passed, not `choices`.

        # While the selected number is occupied
        while self.pick in choices:

            # Pick next number
            self.pick += 1 

            # If target was reached
            if self.pick == self.target: 

                # Reset to 1
                self.pick = 1
Syntax highlighting
Source Link
RedClover
  • 797
  • 7
  • 25

Fountain

A simple bot, picks the lowest number first and if any other bot chooses it too, it will increment the counter - the floor gets filled and the water flows down. When it reaches 11, it restarts to 1 - the water gets pumped back to the top.

class Fountain:

    def __init__(self, index):

        self.index = index
        self.pick  = 1

    def select(self):

        return self.pick

    def update(self, choices: list):

        choices.pop(self.index)  # I hope `choices[:]` is passed, not `choices`.

        for choice in choices:

            if choice == self.pick:

                self.pick += 1

            if self.pick == 11:

                self.pick = 1
class Fountain:

    def __init__(self, index):

        self.index = index
        self.pick  = 1

    def select(self):

        return self.pick

    def update(self, choices: list):

        choices.pop(self.index)  # I hope `choices[:]` is passed, not `choices`.

        for choice in choices:

            if choice == self.pick:

                self.pick += 1

            if self.pick == 11:

                self.pick = 1

Fountain

A simple bot, picks the lowest number first and if any other bot chooses it too, it will increment the counter - the floor gets filled and the water flows down. When it reaches 11, it restarts to 1 - the water gets pumped back to the top.

class Fountain:

    def __init__(self, index):

        self.index = index
        self.pick  = 1

    def select(self):

        return self.pick

    def update(self, choices: list):

        choices.pop(self.index)  # I hope `choices[:]` is passed, not `choices`.

        for choice in choices:

            if choice == self.pick:

                self.pick += 1

            if self.pick == 11:

                self.pick = 1

Fountain

A simple bot, picks the lowest number first and if any other bot chooses it too, it will increment the counter - the floor gets filled and the water flows down. When it reaches 11, it restarts to 1 - the water gets pumped back to the top.

class Fountain:

    def __init__(self, index):

        self.index = index
        self.pick  = 1

    def select(self):

        return self.pick

    def update(self, choices: list):

        choices.pop(self.index)  # I hope `choices[:]` is passed, not `choices`.

        for choice in choices:

            if choice == self.pick:

                self.pick += 1

            if self.pick == 11:

                self.pick = 1
Source Link
RedClover
  • 797
  • 7
  • 25
Loading