Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Code Challenge - Created by Ace
#1
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
Reply
#2
Not a reply yet? Nobody? Huh
Reply
#3
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.
Reply
#4
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.
Reply
#5
Ha. I failed completely. xD

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


Possibly Related Threads…
Thread Author Replies Views Last Post
  Get Country Code In 1 Line Of Code. wchar_t 13 4,011 11-28-2012, 06:49 AM
Last Post: Cubs
  Disc Dash Bot - Created by AceInfinity AceInfinity 2 1,035 07-13-2012, 08:23 PM
Last Post: AceInfinity
  FBytes - Binary Merge Tool - Created by AceInfinity AceInfinity 2 1,014 01-07-2012, 04:47 PM
Last Post: AceInfinity
  File Profiler Demo - Preview - Developed by Ace AceInfinity 4 1,226 12-30-2011, 08:17 PM
Last Post: AceInfinity
  New System Diagnostic Tool - Created by Ace AceInfinity 28 7,583 11-21-2011, 09:55 AM
Last Post: UrbanByte

Forum Jump:


Users browsing this thread: 1 Guest(s)