{"id":13821448,"url":"https://github.com/Pjiwm/Advent-of-code-java","last_synced_at":"2025-05-16T12:33:24.926Z","repository":{"id":102992693,"uuid":"435686959","full_name":"Pjiwm/Advent-of-code-java","owner":"Pjiwm","description":"Simple skeleton for an advent of code project in java. It contains a couple utility methods and a file reader you can use.","archived":false,"fork":false,"pushed_at":"2021-12-07T00:52:04.000Z","size":9,"stargazers_count":2,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-03-02T20:27:38.639Z","etag":null,"topics":["advent-of-code","advent-of-code-2021","aoc","aoc-2021","filereader","java","jvm"],"latest_commit_sha":null,"homepage":null,"language":"Java","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/Pjiwm.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null}},"created_at":"2021-12-07T00:03:02.000Z","updated_at":"2023-09-05T16:32:40.000Z","dependencies_parsed_at":"2023-03-13T15:10:04.732Z","dependency_job_id":null,"html_url":"https://github.com/Pjiwm/Advent-of-code-java","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Pjiwm%2FAdvent-of-code-java","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Pjiwm%2FAdvent-of-code-java/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Pjiwm%2FAdvent-of-code-java/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Pjiwm%2FAdvent-of-code-java/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Pjiwm","download_url":"https://codeload.github.com/Pjiwm/Advent-of-code-java/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":254530675,"owners_count":22086660,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["advent-of-code","advent-of-code-2021","aoc","aoc-2021","filereader","java","jvm"],"created_at":"2024-08-04T08:01:22.103Z","updated_at":"2025-05-16T12:33:23.208Z","avatar_url":"https://github.com/Pjiwm.png","language":"Java","readme":"# Advent of code Java\nSimple skeleton for an advent of code project in java. It contains a couple utility methods and a file reader you can use.\n\n## Creating a new solution\nCopy the input from advent of code\nand go in the `inputs` folder.\nCreate a new file and name it day\u003cnumber\u003e.txt\n(e.g) day1.txt, day2.txt\n\nNow create a new class in the `src/solutions` package\nA good rule of thumb would be to name them based on the day: `Day1.java` `Day2.java` `Day3.java`\nMake sure to extend the class with the abstract class Day.\n  \nIn the constructor write as super parameter the number of the day corresponding to the day number in your text file.\n```Java\npublic class SampleDay extends Day {\n\n    public SampleDay() {\n        super(1);\n    }\n```\nIn the solution method that was generated when we extended the class on the abstract Day we can get retrieve the input from the file.\nThe super class has a method that returns the input as a Collection of Strings\n`super.readInput()`\nWe can now use any datastructure from the collection framework!\n\n### Java collections framework:\n\u003cimg src=\"https://3.bp.blogspot.com/-C1o1u8il4J8/XGGvQJlvA1I/AAAAAAAACs8/MCU7ydkwW0oF63BNiVA62OkWtHwIGk0SACLcBGAs/s1600/Screenshot%2B%2528286%2529.png\"\u003e\n  \n### Example:\n```Java\n      @Override\n  public void solution() throws IOException {\n      // We retrieve the input from the file and put it in a datastructure of our choice\n      ArrayList\u003cString\u003e arrList = new ArrayList\u003c\u003e();\n      Stack\u003cString\u003e stack = new Stack\u003c\u003e();\n      Set\u003cString\u003e set = new HashSet\u003c\u003e();\n      set.addAll(super.readInput());\n      stack.addAll(super.readInput());\n      arrList.addAll(super.readInput());\n  \n      // looping over each...\n      for(String s : set) {\n          System.out.println(s);\n      }\n      for(String s : stack) {\n          System.out.println(s);\n      }\n      for(String s : arrList) {\n          System.out.println(s);\n      }\n  }\n```\nTo run the code go to your App.java and add a new object for your solution:\n```Java\npublic class App {\n    public static void main(String[] args) throws Exception {\n        System.out.println(\"Solutions:\");\n        new Day1();\n        // add day2, 3...\n    }\n}\n```\n\n## Utilities\nThere's a Utils class with a couple methods that can come in handy.\n \n### line\nline prints a line with dashes, makes it easier to seperate stuff that's printed in the console:\n```Java\n Utils.line();\n```\nOutput:\n```\nSome text\n-----------------------------------------------------\nSome text below a line of dashes...\n```\n\n### print2DArray\nprint2DArray prints out an entire 2D array of any type in the console:\n```Java\n Utils.print2DArray(my2DArray);\n```\nThis is useful because if you normally loop over a 2d array and print it, it'll only show the memory adresses of each array.\nWith print2DArray method:\n```\n[a, b, c]\n[d, e, f]\n[g, h, i]\n```\nwithout:\n```\n[Ljava.lang.String;@5d22bbb7]\n[Ljava.lang.String;@41a4555e]\n[Ljava.lang.String;@3830f1c0]\n```\n### Collection data type converters\nIt's possible to get the input of a file as numbers instead of strings.\nThis is possible for the following datatyped: int, long, double\nFor example we can get the input as a collection of integers:\n```Java\nStack\u003cInteger\u003e stack = new Stack\u003c\u003e();\nstack.addAll(\n  Utils.inputAsInteger(super.readInput())\n);\n```\nThe following methods are available:\n```Java\n  Utils.inputAsInteger(myCollection);\n  Utils.inputAsDouble(myCollection);\n  Utils.inputAsLong(myCollection);\n```\n","funding_links":[],"categories":["Java"],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FPjiwm%2FAdvent-of-code-java","html_url":"https://awesome.ecosyste.ms/projects/github.com%2FPjiwm%2FAdvent-of-code-java","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FPjiwm%2FAdvent-of-code-java/lists"}