Support Forums

Full Version: Code Challenge - Created by Ace
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
I thought it would be fun to post a little small challenge for others Smile

The challenge here is to explain (as best as possible) how my snippet of code here works:

Code:
Func<string, bool> f_sb = x => x.All(c => char.IsNumber(c));
string[] input = {"abc", "ABC", "sdf", "23b", "3a4", "521", "aaa", "642", "lkj", "243"};
Console.WriteLine(input.Where(x => f_sb.Invoke(x)).ToArray().Aggregate((a, b) => a + b));

Maybe you'll learn something from it also? If so, then that is not a bad thing. It's not too hard to figure out if you don't look at it as one piece, break it up and follow the logic. The better you explain it, the more I can appreciate your reply to this challenge, as anybody can run this and tell me what the result is, but maybe only some people here can explain what it's doing Smile

Victoire
Not a reply yet? Nobody? Huh
Here's how'd I'd try to explain it. Baring in mind that I have no idea how to code C# (I'm just guessing that's what language this is):

First of all you tell the program that it's a string function, with a boolean. Next you set a (variable?) called "f_sb" to the value of "x" (and to take that to "x.All"?), next you have to tell the program that the (character is a number?). Now you have to call a string input, with the values to "abc", "ABC", "sdf", "23b", "3a4", "521", "aaa", "642", "lkj" and "243".

Now, once you have your current code, you need to tell your program to echo out certain characters [with Console.WriteLine]. You lost me here with the rest of it lol.

(Brackets) resemble things I'm unsure of.
Quote:First of all you tell the program that it's a string function, with a boolean

With a boolean what? Smile

Quote:Next you set a (variable?) called "f_sb" to the value of "x"

Nope.

Quote:(and to take that to "x.All"?)

Nope. lol

Quote:next you have to tell the program that the (character is a number?)

Nope, i'm checking for a number type. Not parsing to a number type or telling a variable to be a number with any kind of type casting.

Quote:Now you have to call a string input

This is a string[] input (string array).

Quote:you need to tell your program to echo out certain characters [with Console.WriteLine]. You lost me here with the rest of it lol.

Those certain characters are only from the values in the string array which have all characters which can be evaluated as number types.
Ha. I failed completely. xD

Oh well, at least I tried. Unlike everyone else on the site. Ninja
I explained it on the other thread at TLF Smile