Language phenotypes: Python, C#

Doing a bucketing exercise on coderpad.io which supports 30+ languages, but in actuality a language is only as good as its tools and libraries and in that respect coderpad.io is sorely lacking on many of the languages it supports.  In truth coderpad.io is built for Python, Javascript, and Ruby other languages are in second tier support.

Unfortunately I chose to use a second tier language (C#) to complete an assignment during an interview and while I got it working I could feel the environment working against me.

Here is the problem

/*

Quantities exist for a set of line-items on an order: `curr_quantities`
Member of the Ops team uses a bulk-edit operation to ensure all order-quantities are above a certain minimum value: `min_input`
This set of line-items all have a batch size, such that all the quantities must be in multiples of that batch size: `batch_size`

Quantities should always round upwards to the nearest batch-size multiple

Example:

curr_quantities = [10, 16, 0]
min_input = 14
batch_size = 8

bulk_adjust_min([10, 16, 0, 17], 14, 8) = [16, 16, 16, 17]

*/

In C# this is

class Solution
{
    private static int[] bulk_adjust_min(int[] current_quantities, int min_size, int initial_batch_size)
    {
        var batch_size = initial_batch_size;
        while (batch_size < min_size)
        {
            batch_size += initial_bath_size;
        }        
        Console.WriteLine($"New Batch Size = {batch_size}");
        
        for (var index = 0; index < current_quantities.Length; index++)
        {
            if (current_quantities[index] < batch_size)
            {
                current_quantities[index] = batch_size;
            }            
        }
        return current_quantities;
    }
    
    
    static void Main(string[] args)
    {
        var expectedResults = new int[] { 24, 24, 24, 24};        
        var inputs = new int[] { 10, 16, 0, 17};
        
        var currentResults = bulk_adjust_min(inputs, 20, 8);
        var matches = 0;
        for (var index = 0; index < expectedResults.Length; index++)
        {
            var currentResult = currentResults[index];
            var expectedResult = expectedResults[index];
            matches += (currentResult == expectedResult) ? 1 : 0;               
        }
        Console.WriteLine($"Expected results {matches == expectedResults.Length}");        
        foreach (var result in currentResults)
        {
            Console.WriteLine($"Batch = {result}");
        }
    }
}

and in python this

def bulk_adjust_min(min_orders: list, min_bucket_size: int, batch_increment: int) -> list:
    current_batch_size = batch_increment
    while current_batch_size < min_bucket_size:
        current_batch_size += batch_increment
    return [current_batch_size if order < current_batch_size else order for order in min_orders]


if __name__ == '__main__':
    curr_quantities = [10, 16, 0]
    min_input = 14
    batch_size = 8
    order_submission = bulk_adjust_min([10, 16, 0, 17], 14, 8)
    print(f'List are equal: {sorted(order_submission) == sorted([16, 16, 16, 17])}')

And here is a better approach that uses bucketing modulos logic in python to round up buckets

def find_order_batch(order_size: int, min_order: int, batch_increment: int) -> int:
    count, rem = divmod(order_size, batch_increment)
    if rem > 0:
        count += 1
    if count < min_order:
        count = min_order
    return batch_increment * count


def bulk_adjust_min(min_orders: list, min_order_size: int, batch_increment: int) -> list:
    min_order, over = divmod(min_order_size, batch_increment)
    if min_order == 0 and over >= 0:
        min_order = batch_increment
    if min_order > 0 and over > 0:
        min_order += 1
    return [find_order_batch(order, min_order, batch_increment) for order in min_orders]


if __name__ == '__main__':
    curr_quantities = [10, 16, 0]
    min_input = 14
    batch_size = 8
    order_submission = bulk_adjust_min([10, 16, 0, 17], 14, 8)
    print(f'List are equal: {sorted(order_submission) == sorted([16, 16, 16, 24])}')

So even without using any libraries the variable initialization and list handling of python is superior for this type of problem.

Guess I should have used python first, but I disqualified myself on that because there was a time limit and python syntax I have to look up quite often for implementation details even if I know exactly what I want to achieve.