Skip to content

Latest commit

 

History

History
62 lines (53 loc) · 1.99 KB

README.md

File metadata and controls

62 lines (53 loc) · 1.99 KB

Java Puzzle Utils

Various utilities, data structures, and algorithms written in Java for solving coding puzzles like Advent of Code.

However, Java is not the best language for coding puzzles. Consider using Kotlin instead. :)

Compatibility: Java 21+

Cheat sheet

This section lists a few notable utilities of the JDK and the Guava library, which can be practical for solving coding puzzles (besides the tools provided in this library).

JDK

  • Language features
    • lambdas
    • var (Java 11+)
    • records (Java 14+)
    • switch expressions (Java 14+)
  • Collections
    • sequenced collections: first/last element and reversed view (Java 21+)
    • List.of, Set.of, Map.of
    • LinkedHashSet, LinkedHashMap
    • NavigableSet (e.g. TreeSet)
    • Collections.rotate(List, int)
  • Streams
    • stream API
    • toList method of Stream (Java 16+)
  • Other
    • Math.clamp, Math.floorDiv, Math.floorMod
    • Arrays.mismatch, Arrays.setAll

Guava

  • Ints, Longs, etc. - utils for (arrays of) primitives
  • Lists
    • partition(List, int)
    • cartesianProduct(List...)
  • Sets
    • intersection(Set, Set), union(Set, Set)
    • difference(Set, Set), symmetricDifference(Set, Set)
    • combinations(Set, int), powerSet(Set)
    • cartesianProduct(Set...)
  • Multisets, multimaps
    • Multiset, HashMultiset, LinkedHashMultiset, TreeMultiset
    • Multimap, MultimapBuilder, e.g.:
      • MultimapBuilder.hashKeys().arrayListValues().build()
      • MultimapBuilder.linkedHashKeys().hashSetValues().build()
    • Multimaps, Multisets - related utils (collectors, filtering, etc.)
  • Other
    • BiMap, HashBiMap
    • Range
    • RangeSet
    • Table, HashedBasedTable, TreeBasedTable
  • LongMath (or IntMath)
    • gcd(long, long) - greatest common divisor
    • binomial(int, int)
    • factorial(int)
    • isPrime(long)
    • isPowerOfTwo(long)