Support Forums
Code Challenge - Created by Ace - Printable Version

+- Support Forums (https://www.supportforums.net)
+-- Forum: Categories (https://www.supportforums.net/forumdisplay.php?fid=87)
+--- Forum: Coding Support Forums (https://www.supportforums.net/forumdisplay.php?fid=18)
+---- Forum: Visual Basic and the .NET Framework (https://www.supportforums.net/forumdisplay.php?fid=19)
+---- Thread: Code Challenge - Created by Ace (/showthread.php?tid=26055)



Code Challenge - Created by Ace - AceInfinity - 04-23-2012

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


RE: Code Challenge - Created by Ace - AceInfinity - 04-23-2012

Not a reply yet? Nobody? Huh


RE: Code Challenge - Created by Ace - BreShiE - 04-23-2012

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.


RE: Code Challenge - Created by Ace - AceInfinity - 04-24-2012

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.


RE: Code Challenge - Created by Ace - BreShiE - 04-24-2012

Ha. I failed completely. xD

Oh well, at least I tried. Unlike everyone else on the site. Ninja


RE: Code Challenge - Created by Ace - AceInfinity - 04-24-2012

I explained it on the other thread at TLF Smile