day14_2020

package
v0.0.0-...-359cf57 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Dec 15, 2022 License: MIT Imports: 4 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ApplyMaskToAddr

func ApplyMaskToAddr(addr uint64, mask string) string

ApplyMaskToAddr applies a mask to an address and returns the string mask. For each bit of the mask / address, the following rules apply:

  • If the bitmask bit is 0, the corresponding memory address bit is unchanged.
  • If the bitmask bit is 1, the corresponding memory address bit is overwritten with 1.
  • If the bitmask bit is X, the corresponding memory address bit is floating and will be marked as 'X' in the resulting string.

func MaskCombs

func MaskCombs(mask string) []string

MaskCombs takes a mask with 1's, 0's and X's and generates all the possible combinations of masks possible by replacing the X's for 1's and 0's.

Types

type Instruction

type Instruction struct {
	Type    InstructionType
	Mask    Mask
	Address int
	Value   uint64
}

type InstructionType

type InstructionType int8
const (
	MEMSET InstructionType = iota
	MASKSET
)

type Mask

type Mask struct {
	OriginalStr string
	OrMask      uint64
	AndMask     uint64
}

type Solver

type Solver struct {
	Instructions []Instruction
}

func NewSolver

func NewSolver() *Solver

func (*Solver) Part1

func (s *Solver) Part1() (string, error)

func (*Solver) Part2

func (s *Solver) Part2() (string, error)

func (*Solver) ProcessInput

func (s *Solver) ProcessInput(input string) error

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL