aboutsummaryrefslogtreecommitdiff
path: root/challenge-289/jtimothyking/csharp/ch-2.cs
blob: 4d78fcb891be2c72997aa895f0bc20f916e5e1cb (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
using System.Text.RegularExpressions;

namespace ch_2;

public static class Ch2
{
    public static void Main()
    {
        while (Console.ReadLine() is { } line)
            foreach (var outputWord in Regex.Split($"{line}\n", @"\b").Select(Jumble))
                Console.Write(outputWord);
    }

    private static string Jumble(string word) =>
        word.Length < 4 || !Regex.IsMatch(word, @"\w")
            ? word
            : word[0] + word[1..^1].Shuffle() + word[^1];

    private static string Shuffle(this string str)
    {
        var chars = str.ToCharArray();
        Random.Shared.Shuffle(chars);
        return new string(chars);
    }
}