Help us shape the future of Go! Take the 2026 Go Developer Survey

primes

package module
v0.4.0 Latest Latest
Warning

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

Go to latest
Published: May 17, 2024 License: MIT Imports: 6 Imported by: 30

README

primes

Go GoDoc codecov

  • Find primary numbers
% primes p 20
[2 3 5 7 11 13 17 19]
  • Factorize numbers
% primes f 329
[7 47]
  • Reduce fractions
% primes r 144/360
2/5
  • all can be executed in go code
package main

import (
	"fmt"

	"github.com/otiai10/primes"
)

func main() {
	fmt.Println(
		primes.Until(20).List(),
		primes.Factorize(144).All(),
		primes.Factorize(144).Powers(),
	)
}

// [2 3 5 7 11 13 17 19]
// [2 2 2 2 3 3]
// map[2:4 3:2]

install

go get github.com/otiai10/primes/primes

Documentation

Index

Constants

This section is empty.

Variables

View Source
var Globally = &cache{
	store: map[int64]*Primes{},
	list:  list.New(),
}

Globally ...

Functions

This section is empty.

Types

type Factors

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

Factors represents factors

func Commons

func Commons(a, b *Factors) *Factors

Commons returns common factors of two numbers

func Factorize

func Factorize(num int64) *Factors

Factorize factorizes given number

func (*Factors) All

func (f *Factors) All() []int64

All returns all factors

func (*Factors) HasPowersOf

func (f *Factors) HasPowersOf(factor int64) int

func (*Factors) List

func (f *Factors) List() []int64

List returns distict list of factors

func (*Factors) Powers

func (f *Factors) Powers() map[int64]int

Powers returns dict formatted factors

type Fraction

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

Fraction represents fraction

func Fractionize

func Fractionize(num, den int64) *Fraction

Fractionize ...

func ParseFractionString

func ParseFractionString(fractionLike string) (*Fraction, error)

ParseFractionString parses and initializes Fraction from string

func (*Fraction) Reduce

func (fr *Fraction) Reduce(times int) *Fraction

Reduce recuces this fraction

func (*Fraction) String

func (fr *Fraction) String() string

String ...

type Primes

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

Primes represents prime numbers

func Until

func Until(n int64) *Primes

Until finds prime numbers until specified number.

func (*Primes) List

func (p *Primes) List() []int64

List returns all found primes as a slice.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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