Ad

Help Suzuki purchase his Tofu!

Suzuki has sent a lay steward to market who will purchase some items not produced in the monastary gardens for the monks. The stewart has with him a large box full of change from donations earlier in the day mixed in with some personal items. You will be given a string of items representing the box.

Sort through the items in the box finding the coins and putting aside anything else.

You will be given a data structure similar to the one below.

box = "mon mon mon mon mon apple mon mon mon mon mon mon mon monme mon mon monme mon mon mon mon cloth monme mon mon mon mon mon mon mon mon cloth mon mon monme mon mon mon mon monme mon mon mon mon mon mon mon mon mon mon mon mon mon";

Return the following in your solution.

[count of mon coins in box, count of monme coins in box,sum of all coins value in box, minimum number of coins needed for Tofu]

100 ≤ cost ≤ 1000

cost = 124

returns

[45, 5, 345, 6]
The coins have the following values:

monme = 60

mon = 1

Determine the minimum number of coins to pay for tofu. You must pay with exact change and if you do not have the correct change return “leaving the market”.

NOTE !!!!! for c# solution Just return -> int[] {0};

If the cost of tofu is higher than your total amount of money also return “leaving the market”

using System;
using System.Linq;  

public class Kata
    {
        public static int[] PurchaseTofu(int cost, string box)
        {
              var monCount = box.Split(' ').Count(x => x == "mon");
            Console.WriteLine(monCount);
            var monmeCount = box.Split(' ').Count(x => x == "monme");
            var TotalValue = monCount + (monmeCount * 60);
            int NumberOfMonmeUsed = 0;
            int NumberOfMonUsed = 0;
            int NeverChangeCost = cost;

            var monCounter = monCount;
            var monmeCounter = monmeCount;

            while(cost >= 60 && monmeCounter > 0)
            {
                NumberOfMonmeUsed = NumberOfMonmeUsed + 1;
                cost = cost - 60;
                monmeCounter--;
            }

            while (cost >= 1 && monCounter > 0)
            {
                NumberOfMonUsed = NumberOfMonUsed + 1;
                cost = cost - 1;
                monCounter--;
            }

            var TotalCoinsUsed = NumberOfMonmeUsed + NumberOfMonUsed;

            var test = (NumberOfMonmeUsed * 60) + NumberOfMonUsed;

            if (test != NeverChangeCost)
            {
                Console.WriteLine("Leaving the market");
                return new int[] {0};
            }

            Console.WriteLine($"[{monCount}, {monmeCount}, {TotalValue}, {TotalCoinsUsed}]");
            return new int[] { monCount, monmeCount, TotalValue, TotalCoinsUsed };
        }
    }

Suzuki needs help lining up his students!

Today Suzuki will be interviewing his students to ensure they are progressing in their training. He decided to schedule the interviews based on the length of the students name in descending order. The students will line up and wait for their turn.

You will be given a string of student names. Sort them and return a list of names in descending order.

Here is an example input:

string = 'Tadashi Takahiro Takao Takashi Takayuki Takehiko Takeo Takeshi Takeshi'
Here is an example return from your function:

lst = ['Takehiko',
'Takayuki',
'Takahiro',
'Takeshi',
'Takeshi',
'Takashi',
'Tadashi',
'Takeo',
'Takao']
Names of equal length will be returned in reverse alphabetical order (Z->A) such that:

string = "xxa xxb xxc xxd xa xb xc xd"
Returns

['xxd', 'xxc', 'xxb', 'xxa', 'xd', 'xc', 'xb', 'xa']

using System;
using System.Linq;   

 public class Kata
    {
        public static string[] LiningUpHisStudents(string s)
        {
            var query = s.Split(' ').OrderByDescending(x => x.Length).ThenByDescending(x => x).ToArray();
            return query;
        }
    }