<commit_before>﻿using AdventOfCode.Shared;
using System;
using System.Collections.Generic;
using System.Web.Script.Serialization;


namespace AdventOfCode.Day12
{
    public class Day12 : IAdventDay
    {
        private bool RED_MODE = false;

        public string PuzzleName => "JSAbacusFramework.io";

        public string SolvePartOne()
        {
            var input = FileParser.GetAllText("Day12/Day12Input.txt");
            RED_MODE = false;
            var sum = GetSum(input);
            return sum.ToString();
        }

        public int GetSum(string input)
        {
            JavaScriptSerializer jss = new JavaScriptSerializer();
            var d = jss.Deserialize<dynamic>(input);


            var sum = Sum(d);
            return sum;
        }

        public string SolvePartTwo()
        {
            var input = FileParser.GetAllText("Day12/Day12Input.txt");
            RED_MODE = true;
            var sum = GetSum(input);
            return sum.ToString();
        }


        public int SumupLevel(Dictionary<string, object> level, int sum)
        {
            if (RED_MODE)
            {
                foreach (var member in level)
                {
                    if (member.Value.ToString() == "red")
                        return sum;
                }
            }

            foreach (var member in level)
            {
                sum += Sum(member.Value);
            }

            return sum;
        }

        private int Sum(object member)
        {
            int sum = 0;
            if (member is string)
                return sum;
            else if (member is Dictionary<string, object>)
                sum = SumupLevel((Dictionary<string, object>)member, sum);
            else if (member is object[])
                sum = SumupArray((object[])member, sum);
            else if (member is int)
                sum = (int)member;
            else
                throw new Exception("WTF is this " + member);
            return sum;
        }

        private int SumupArray(object[] array, int sum)
        {
            foreach (var item in array)
            {
                sum += Sum(item);
            }

            return sum;
        }
    }
}
<commit_msg>Trying to solve build problem with array being represented as ArrayList.<commit_after>﻿using AdventOfCode.Shared;
using System;
using System.Collections;
using System.Collections.Generic;
using System.Web.Script.Serialization;


namespace AdventOfCode.Day12
{
    public class Day12 : IAdventDay
    {
        private bool RED_MODE = false;

        public string PuzzleName => "JSAbacusFramework.io";

        public string SolvePartOne()
        {
            var input = FileParser.GetAllText("Day12/Day12Input.txt");
            RED_MODE = false;
            var sum = GetSum(input);
            return sum.ToString();
        }

        public int GetSum(string input)
        {
            JavaScriptSerializer jss = new JavaScriptSerializer();
            var d = jss.Deserialize<dynamic>(input);


            var sum = Sum(d);
            return sum;
        }

        public string SolvePartTwo()
        {
            var input = FileParser.GetAllText("Day12/Day12Input.txt");
            RED_MODE = true;
            var sum = GetSum(input);
            return sum.ToString();
        }


        public int SumupLevel(Dictionary<string, object> level, int sum)
        {
            if (RED_MODE)
            {
                foreach (var member in level)
                {
                    if (member.Value.ToString() == "red")
                        return sum;
                }
            }

            foreach (var member in level)
            {
                sum += Sum(member.Value);
            }

            return sum;
        }

        private int Sum(object member)
        {
            int sum = 0;
            if (member is string)
                return sum;
            else if (member is Dictionary<string, object>)
                sum = SumupLevel((Dictionary<string, object>)member, sum);
            else if (member is object[])
                sum = SumupArray((object[])member, sum);
            else if (member is int)
                sum = (int)member;
            else if (member is ArrayList)
                sum = SumupArray(((ArrayList)member).ToArray(), sum);
            else
                throw new Exception("WTF is this " + member);
            return sum;
        }

        private int SumupArray(object[] array, int sum)
        {
            foreach (var item in array)
            {
                sum += Sum(item);
            }

            return sum;
        }
    }
}

{'fraction_non_alphanumeric': 0.08861840700405722, 'fraction_numerical': 0.005551996583386718, 'mean_word_length': 1.3502257902659307, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 13, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2458551', 'n_tokens_mistral': 1231, 'n_tokens_neox': 1153, 'n_words': 328}