libgollatz

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

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

Go to latest
Published: Jul 17, 2019 License: MIT Imports: 1 Imported by: 1

README

libgollatz

libgollatz is a library for running the Collatz conjecture algorithm. That's literally it. I'm using this to cement my understanding of packaging libraries in Go. I'm only putting it on GitHub because I'm creating another project that uses this as a dependancy.

FAQ

Q. Why are you using the Result struct instead of mapping an input to an array or list of outputs?

A. Because we might eventually want to store more information than just the number of steps and the outputs.

Documentation

Overview

Package libgollatz will take a n integer, perform the collatz algorithm on it, and then put each value it hits into a linked list, which will then be put into an array. Then it will return a Result consisting of the original value and the array of values.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Result

type Result struct {
	Value uint64
	Steps []uint64
}

Result is made up of the initial value and an array containing all of the steps to get to 1 using the Collatz algorithm.

func Collatz

func Collatz(start uint64) Result

Collatz will take in a number, and then run it through the Collatz algorithm (3n+1). It returns a Result which stores the initial value and the steps it took to get to 1.

Jump to

Keyboard shortcuts

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