Quest 1: Whispers in the Shell

  • Keep top level comments as only solutions, if you want to say something other than a solution put it in a new post. (replies to comments can be whatever)
  • You can send code in code blocks by using three backticks, the code, and then three backticks or use something such as https://topaz.github.io/paste/ if you prefer sending it through a URL

Link to participate: https://everybody.codes/

  • Vulwsztyn@programming.dev
    link
    fedilink
    arrow-up
    3
    ·
    3 days ago

    my boring python solution:

    from pathlib import Path
    
    
    def main():
        input = Path('input.txt').read_text().split('\n')
        names = input[0].split(',')
        instructions = input[-1].split(',')
        print(names,instructions)
        index = 0
        for instruction in instructions:
            dir = instruction[0]
            number = int(instruction[1:])
            if dir == 'L':
                index -= number
                if index < 0:
                    index = 0
            else:
                index += number
                if index > len(names) - 1:
                    index = len(names) - 1
        print(names[index])
        index = 0
        for instruction in instructions:
            dir = instruction[0]
            number = int(instruction[1:])
            if dir == 'L':
                index -= number
            else:
                index += number
        print(names[index%(len(names))])
        indexes = list(range(len(names)))
        for instruction in instructions:
            dir = instruction[0]
            number = (int(instruction[1:]) if dir == 'R' else -int(instruction[1:])) % len(names)
            indexes[0], indexes[number] = indexes[number], indexes[0]
        print(names[indexes[0]])
    
    if __name__ == "__main__":
        main()
    

    I probably should read all 3 files though. I’ll hone it out later.