r/adventofcode • • Dec 06 '20

SOLUTION MEGATHREAD -🎄- 2020 Day 06 Solutions -🎄-

NEW AND NOTEWORTHY


Advent of Code 2020: Gettin' Crafty With It

  • UNLOCKED! Go forth and create, you beautiful people!
  • Full details and rules are in the Submissions Megathread
  • Make sure you use one of the two templates!
    • Or in the words of AoC 2016: USING A TEMPLATE IS MANDATORY

--- Day 06: Custom Customs ---


Post your solution in this megathread. Include what language(s) your solution uses! If you need a refresher, the full posting rules are detailed in the wiki under How Do The Daily Megathreads Work?.

Reminder: Top-level posts in Solution Megathreads are for solutions only. If you have questions, please post your own thread and make sure to flair it with Help.


This thread will be unlocked when there are a significant number of people on the global leaderboard with gold stars for today's puzzle.

EDIT: Global leaderboard gold cap reached at 00:04:35, megathread unlocked!

67 Upvotes

1.2k comments sorted by

View all comments

2

u/21ROCKY12 Dec 06 '20 edited Dec 07 '20

just solved both parts using java, got the main idea but needed some debugging to fix the little things, here is my code:) -(works)

part1&2

public static Scanner reader= new Scanner(System.in);
	public static void part1() {/copy paste to main or run function
		int cnt=0;
		String str="";
		for(String s:str.split("(\r?\\n){2}")) {
			char[] check=new char[s.length()];
			int gg=0;
			for(String ss: s.split("\r\n")) {
    			for(int h=0;h<ss.length();h++) {//goes through each line 
    				boolean flag=true;
					for(int f=0;f<check.length;f++) {
						if(check[f]==ss.charAt(h)) {flag=false;}
					}
					if(flag==true) {
            		   check[gg]=ss.charAt(h);
            		   cnt++;
            		   gg++;
					}
    			}	
			}
		}
		System.out.println(cnt);
}
public static part2() {//part2 here
	    int cnt = 0;
	    String str = "";//copy paste input here
	    for (String s : str.split("(\r?\\n){2}")) {
	    	int cntgroups = 0;
	        HashMap<Character, Integer> top = new HashMap<Character, Integer>();
	        for (String ss : s.split("\r\n")) {
	            cntgroups++;
	            for (int h = 0; h < ss.length(); h++) {//goes through each line
	                if (top.containsKey(ss.charAt(h))) {
	                    top.replace(ss.charAt(h), top.get(ss.charAt(h)) + 1);
	                } else {
	                    top.put(ss.charAt(h), 1);
	                }
	            }
	        }
	        for (int value : top.values()) {
	            if (value == cntgroups) {
	                cnt++;
	            }
	        }
	    }
	    System.out.println(cnt);
	}

1

u/daggerdragon Dec 06 '20

Your code is hard to read on old.reddit. Please edit it as per our posting guidelines in the wiki: How do I format code?

2

u/21ROCKY12 Dec 07 '20

should be better now!

1

u/21ROCKY12 Dec 07 '20

when i try to edit it, I indented but it just removes the indents when I save edits