Sha256: b0848871b022aac56748d3929c0bdcef6180f3d7133ab2ed882015a530a0d541

Contents?: true

Size: 1.36 KB

Versions: 86

Compression:

Stored size: 1.36 KB

Contents

using System;
using System.Collections.Generic;
using System.Linq;
using Generators.Input;
using Generators.Output;
using Newtonsoft.Json.Linq;

namespace Generators.Exercises
{
    public class Dominoes : GeneratorExercise
    {
        protected override void UpdateCanonicalData(CanonicalData canonicalData)
        {
            foreach (var canonicalDataCase in canonicalData.Cases)
            {
                canonicalDataCase.UseVariablesForInput = true;
                canonicalDataCase.Properties["input"] = ConvertInput(canonicalDataCase.Properties["input"]);
            }
        }
        
        protected override HashSet<string> AddAdditionalNamespaces() => new HashSet<string>() { typeof(Tuple).Namespace };

        private UnescapedValue ConvertInput(dynamic input)
        {
            var dominoes = (input as JArray).Children();

            // Manually format array of ints to array of tuples since the ValueFormatter doesn't handle Tuple<int,int>[]
            // Project each jtoken element to an int array, then format to a string that will create a tuple from the 2-element array (via UnescapedValues)
            var tuplesStringLiteral = dominoes.Select(s => s.ToObject<int[]>()).Select(s => $"Tuple.Create({s[0]}, {s[1]})");
            return new UnescapedValue($"new Tuple<int, int>[] {{ {string.Join(", ", tuplesStringLiteral)} }}");
        }
    }
}

Version data entries

86 entries across 86 versions & 1 rubygems

Version Path
trackler-2.2.1.151 tracks/csharp/generators/Exercises/Dominoes.cs
trackler-2.2.1.150 tracks/csharp/generators/Exercises/Dominoes.cs
trackler-2.2.1.149 tracks/csharp/generators/Exercises/Dominoes.cs
trackler-2.2.1.148 tracks/csharp/generators/Exercises/Dominoes.cs
trackler-2.2.1.147 tracks/csharp/generators/Exercises/Dominoes.cs
trackler-2.2.1.146 tracks/csharp/generators/Exercises/Dominoes.cs
trackler-2.2.1.145 tracks/csharp/generators/Exercises/Dominoes.cs
trackler-2.2.1.144 tracks/csharp/generators/Exercises/Dominoes.cs
trackler-2.2.1.143 tracks/csharp/generators/Exercises/Dominoes.cs
trackler-2.2.1.142 tracks/csharp/generators/Exercises/Dominoes.cs
trackler-2.2.1.141 tracks/csharp/generators/Exercises/Dominoes.cs
trackler-2.2.1.140 tracks/csharp/generators/Exercises/Dominoes.cs
trackler-2.2.1.139 tracks/csharp/generators/Exercises/Dominoes.cs
trackler-2.2.1.138 tracks/csharp/generators/Exercises/Dominoes.cs
trackler-2.2.1.137 tracks/csharp/generators/Exercises/Dominoes.cs
trackler-2.2.1.136 tracks/csharp/generators/Exercises/Dominoes.cs
trackler-2.2.1.135 tracks/csharp/generators/Exercises/Dominoes.cs
trackler-2.2.1.134 tracks/csharp/generators/Exercises/Dominoes.cs
trackler-2.2.1.133 tracks/csharp/generators/Exercises/Dominoes.cs
trackler-2.2.1.132 tracks/csharp/generators/Exercises/Dominoes.cs