solutions

package module
v0.0.0-...-056d6c7 Latest Latest
Warning

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

Go to latest
Published: Sep 6, 2025 License: MIT Imports: 13 Imported by: 0

Documentation

Overview

This package contains all of the "Project Euler 100" problem solutions. Assertion tests for these can be found in `main_test.go` where test inputs are from the smaller scale (non-solution) typically provided in the question itself, in order to avoid explicitly spoiling the solution in source control.

Index

Constants

View Source
const ExampleN = 10

Variables

View Source
var COMMA = []byte{','}
View Source
var NthFibonacciExceedingDigits = NthFibonacciExceedingDigitsStrlen

Problem 001 - Multiples of 3 or 5 see `/blog/001` for full commentary.

This one is pretty simple so let's see some variants.

Functions

func CollatzNext

func CollatzNext(x int) int

Compute the next number in the sequence, where

  if x is even, x' = x/2
	if x is odd,  x' = 3*x + 1

This is famously known as the Collatz Sequence.

func CommaSeparatedQuotedStrings

func CommaSeparatedQuotedStrings(data []byte, atEOF bool) (
	advance int, token []byte, err error)

func CountAmicableUnder

func CountAmicableUnder(limit int) int

func CountLatticePaths

func CountLatticePaths(width, height int64) *big.Int

func CountSetsOfPowers

func CountSetsOfPowers(start, until int) int64

func CountSquareLatticePaths

func CountSquareLatticePaths(d int) int64

func CountingSundaysUsingTime

func CountingSundaysUsingTime(
	start_year, start_month, start_day,
	last_year, last_month, last_day int) int64

func DigitFifthPowers

func DigitFifthPowers(power, digits int) int64

func DigitSeriesFile

func DigitSeriesFile(filename string) digit_series

func FactorialDigitSum

func FactorialDigitSum(n int) int64

func FindLargestPalindromeProduct

func FindLargestPalindromeProduct(limit int) int64

func FirstTriangleExceedingFactorCount

func FirstTriangleExceedingFactorCount(count_limit int) int64

func GeneratePrimesUntil

func GeneratePrimesUntil(limit uint64) <-chan uint64

func IsPalindromicInt

func IsPalindromicInt(number int) bool

func LargestPrimeFactor

func LargestPrimeFactor(n int) int64

func LexicographicPermutations

func LexicographicPermutations(digits []int, goal int) int64

func LongestCollatzChainStartingBelow

func LongestCollatzChainStartingBelow(limit int) int64

Returns the start of the longest sequence, for any start value below `limit`.

func LongestQuadraticPrimeRun

func LongestQuadraticPrimeRun(min, max int) int64

func LongestReciprocalCycleLength

func LongestReciprocalCycleLength(limit int) int

func LongestReciprocalCycleLengthViaPatternSearch

func LongestReciprocalCycleLengthViaPatternSearch(limit int) int

func NamesListFile

func NamesListFile(filename string) names_list

func NonAbundantSumsUnder

func NonAbundantSumsUnder(limit int) int64

func NthFibonacciExceedingDigitsCompareBigInt

func NthFibonacciExceedingDigitsCompareBigInt(num_digits int) int64

func NthFibonacciExceedingDigitsStrlen

func NthFibonacciExceedingDigitsStrlen(num_digits int) int64

func NthPrime

func NthPrime(limit int) int64

func NumberGridFile

func NumberGridFile(filename string) number_grid

func NumberLetterCount

func NumberLetterCount(value int) int64

func NumberListFile

func NumberListFile(digits_file string) bignum_list

func NumberRangeLetterCount

func NumberRangeLetterCount(last int) int64

func NumberSpiralDiagonals

func NumberSpiralDiagonals(size int) int64

func NumberTriangleFile

func NumberTriangleFile(filename string) number_triangle

func QuadraticPrimeRun

func QuadraticPrimeRun(a, b int) int64

func SmallestCommonMultiple

func SmallestCommonMultiple(last int) int64

func SpecialPythagoreanTriplet

func SpecialPythagoreanTriplet(triplet_sum int) int64

func SqSumDifference

func SqSumDifference(n int) int64

func SumEvenFibonacciUntil

func SumEvenFibonacciUntil(n int) int64

func SumOf3or5_Constant

func SumOf3or5_Constant(n int) int64

An even more efficient solution doesn't look at the numbers at all (except for the remainder at the end, which has a known bound).

func SumOf3or5_Naïve

func SumOf3or5_Naïve(n int) int64

The most naive solution looks at every number in the range [1, n).

func SumOf3or5_Selective

func SumOf3or5_Selective(n int) int64

A more selective approach only looks at the numbers we know to be multiples.

func SumOfDigitsOfPowersOfTwo

func SumOfDigitsOfPowersOfTwo(power int) int64

func SummationOfPrimesBelow

func SummationOfPrimesBelow(n int) int64

Types

type Factors

type Factors map[uint64]int

func (*Factors) Merge

func (factors *Factors) Merge(other Factors)

func (*Factors) With

func (factors *Factors) With(factor uint64)

type SieveOfEratosthenes

type SieveOfEratosthenes interface {
	IsPrime(uint64) bool
}

func NewSieve

func NewSieve(limit uint64) SieveOfEratosthenes

Jump to

Keyboard shortcuts

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