Skip to content

imdany/AdventOfCode2021

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

44 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Advent of Code 2021

Solutions using Java. This code doesn't pretend to be perfect or efficient.

I haven't used Java in years, so I just want to re-learn it, practice it a little bit, try some design parterns and have fun! :)

CI / CD

Using Github actions for running the code. Check the logs of the "Run" step.

workflow

Lessons Learnt

  • Day 10

Use of Stack:

Stack<Character> stack = new Stack<Character>();

stack.push(x); // Adds new element to top of stack

stack.pop(); // Removes top element from stack

stack.peek(); // Checks top element without removing it

Lambda expressions:

// Filtering values of an array
Arrays.stream(cost).filter(x -> x !=0 ).toArray(Long[]::new);
  • Day 14 Use of IntStream
    IntStream.range(0, String.valueOf(this.currentSequence).length() - 1)
        .mapToObj(i -> String.valueOf(this.currentSequence).substring(i, i + 2))

    // Creates a range from 0 to X... and then you can map each of those elements to an object

Use of Compute in HashMap

    map.compute(key, (key, v) -> v == null ? count : v + count);
    // Allows you to add or update a key on a map

About

Advent Of Code 2021

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages