flipper

package module
v0.0.0-...-c30860a Latest Latest
Warning

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

Go to latest
Published: Nov 14, 2019 License: MIT Imports: 5 Imported by: ? modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

README

flipper

flippin pancakes!

Build Statuscodecov

Take home coding challenge.
The builtin basic version uses os.Stdin and os.Stdout, but you can use whatever io.Reader and io.Writer you choose to pass in. The example directory has a package main you can run, or it's easy to import and make your own. Included is generate.py (attribution) which will generate permutations of n length and output directly in the format flipper accepts for the problem.

Usage: python3 generate.py n

Also included is a simple bash wrapper example/runPermutations.sh wrapping the generator and piping to example binary if you've cloned the repo and built the example.

Usage ./runPermutations.sh n

Godoc

Documentation

Overview

Package flipper contains my personal solution to the 'Revenge of the Pancakes' coding challenge.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func DoEverything

func DoEverything() error

DoEverything is just an exported function that creates a default flipper, reads the input, solves, and outputs.

Types

type Flipper

type Flipper struct {
	// contains filtered or unexported fields
}

Flipper is the solver for the pancake problem. Handles the input and output and solves.

func NewFlipper

func NewFlipper(in io.Reader, out io.Writer) *Flipper

NewFlipper creates a new flipper struct with buffered io using the passed in input and output sinks.

func (*Flipper) Flush

func (f *Flipper) Flush() error

Flush just calls the internal wrtier buffer's Flush method.

func (*Flipper) ReadProblem

func (f *Flipper) ReadProblem() error

ReadProblem reads the problem from the io.Reader input and stores it in the struct members.

func (*Flipper) SolveAll

func (f *Flipper) SolveAll() error

SolveAll just iterates and solves all the problems in the set.

func (*Flipper) SolveNext

func (f *Flipper) SolveNext() error

SolveNext preps and solves a single input line and prints the solution to the io.Writer output buffer.

type Stack

type Stack struct {
	// contains filtered or unexported fields
}

Stack represents a stack of pancakes and has some ease of use methods.

func NewStack

func NewStack(in string) (*Stack, error)

NewStack takes a string of + and - and returns a Stack struct pointer.

func (*Stack) Count

func (s *Stack) Count() int

Count returns the current number of flips undertaken.

func (*Stack) Equals

func (s *Stack) Equals(test []bool) bool

Equals is just a helper method for checking the state of those yummy pancakes to see if their current state is equal to the passed in slice.

func (*Stack) EqualsString

func (s *Stack) EqualsString(test string) (bool, error)

EqualsString accepts a string and passes to Equals.

func (*Stack) Flip

func (s *Stack) Flip(n int) error

Flip flips the first n pancakes in-place in the slice of bools and increments the internal flip counter. n <= 0 is a no-op and does not increment the flip count.

func (*Stack) IsHappy

func (s *Stack) IsHappy() bool

IsHappy checks if all the pancakes are happy side up and we are done.

func (*Stack) LowestFlip

func (s *Stack) LowestFlip() int

LowestFlip finds the first from the bottom that needs to be flipped. Returns how many to flip to fix it for directly passing into Flip

func (*Stack) PrepTop

func (s *Stack) PrepTop() int

PrepTop returns the number to pre-flip on top to make sure at least the top pancake (or more) is -, so that a deep flip actually makes n'th happy. In other words, it returns the number of consecutive +'s from the top to flip. Directly compatible with Flip

func (*Stack) Solve

func (s *Stack) Solve() (int, error)

Solve solves the stack of pancakes represented by this Stack instance and returns the number of flips.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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