Click here to Skip to main content
15,885,244 members
Home / Discussions / C#
   

C#

 
GeneralRe: HTTPListener with AuthenticationSchemes.IntegratedWindowsAuthentication Pin
Dave Kreskowiak13-Apr-16 12:21
mveDave Kreskowiak13-Apr-16 12:21 
GeneralRe: HTTPListener with AuthenticationSchemes.IntegratedWindowsAuthentication Pin
Mycroft Holmes13-Apr-16 12:52
professionalMycroft Holmes13-Apr-16 12:52 
GeneralRe: HTTPListener with AuthenticationSchemes.IntegratedWindowsAuthentication Pin
Richard MacCutchan13-Apr-16 20:45
mveRichard MacCutchan13-Apr-16 20:45 
GeneralRe: HTTPListener with AuthenticationSchemes.IntegratedWindowsAuthentication Pin
Richard MacCutchan13-Apr-16 20:44
mveRichard MacCutchan13-Apr-16 20:44 
Questioncsharp creating algorithm Pin
Member 1245597512-Apr-16 21:24
Member 1245597512-Apr-16 21:24 
AnswerRe: csharp creating algorithm Pin
Peter_in_278012-Apr-16 22:13
professionalPeter_in_278012-Apr-16 22:13 
AnswerRe: csharp creating algorithm Pin
OriginalGriff12-Apr-16 22:19
mveOriginalGriff12-Apr-16 22:19 
AnswerRe: csharp creating algorithm PinPopular
BillWoodruff12-Apr-16 23:47
professionalBillWoodruff12-Apr-16 23:47 
Assuming this is not really your homework, then: how is it you so clearly remember the details of this question, and why are you concerned with coding it up now, rather than concerned with how you can increase your understanding of how to think about algorithms, and how to render them into a series of discrete operations that can be expressed in code ?

Note: I do not mean to imply you will not learn something "algorithmic" from coding up this specific task ! The question is: how to approach the coding in the way that will result in your extracting the maximum "algorithmic" learning from the task.

If you get started, and share some code, and ask specific questions accompanied by relevant code quotes, and error messages ... I, and, I am sure, many others here, will be happy to help.

Keep the phrase "divide and conquer" in mind !

Here's a "seed" idea to get you started:

1. since only every other digit starting from the final digit will need to be manipulated: step one is to isolate, and process as a group, the set of alternate digits; you can decompose that into:

a. how take your instance of an integer datatype, and transform it into a list of usable digits.

b. how to sort those digits into two groups, one of which contains every other digit starting from the end, the other which contains the other alternating digits.

c. how to take the alternating starts-at-end group of digits and call a function that transforms the values as required

d. how to create a new integer datatype instance that "integrates" the two lists.

Examining the requirements, it's clear you need a function that takes an integer and transforms it into the sum of its individual digits. You need to use that function repeatedly in your transform function, and, again, at the end.

Finally, you will need to make some strategic decisions about how you will implement the steps based on the context, and requirements. Decisions like:

2. in C#, based on estimated magnitude of values to be dealt with: choose from Int32, or Long, or even BigInteger data types ?

3. if high-performance, high volume, processing is required:

a. you are going to need to write code that decomposes your integer datatype into bytes, and parses those bytes to get at the digits they store. You are going to need to avoid expensive transformations like casting into Type 'String.

4. if high performance is not required:

a. you can "get away" with converting your integer datatype to strings, and then dealing with strings as arrays of type Char which you can easily decompose into arrays of integer digits.

By careful initial design, you can prototype using the less "expensive" techniques ... but, techniques that allow you to work more rapidly, and, then, later, as you refine more powerful, faster, techniques: simply "plug those in," replacing the slower ones.

Think of it as like prototyping a car by using a "socket" where the motor will, eventually, go. You can learn a lot about the design using a simple motor that uses a lot of gasoline, and is under-powered, but allows you to fully test. Later, when the powerful final motor is ready, and tested, you can just plug it in.

So, on a practical level this means I might write/organize code where certain functions were separated out into different classes with very specific methods:
C#
public static class TransformationUtilities
{
    public static long GetCheckInteger(long longValue)
    {
        // decompose longValue into two lists of digits

        // do the right thing
        // using 'TransformDigit, and 'SumOfDigits
    }

    // note: auto-conversion from digit to long here
    // low priority: examine how efficient that is
    public static long TransformDigit(int digit)
    {
        if(digit < 5 ) return digit;
        return SumOfDigits(digit * 2);
    }

    public static long SumOfDigits(long value)
    {
        // conversion to 'string expensive
        // find a better way
        return (value.ToString()).Sum(ch => ch - 48);
    }
}
Keep in mind the above code is just a "sketch."
«The truth is a snare: you cannot have it, without being caught. You cannot have the truth in such a way that you catch it, but only in such a way that it catches you.» Soren Kierkegaard


modified 13-Apr-16 8:06am.

GeneralRe: csharp creating algorithm Pin
OriginalGriff13-Apr-16 0:10
mveOriginalGriff13-Apr-16 0:10 
GeneralRe: csharp creating algorithm Pin
Richard MacCutchan13-Apr-16 0:44
mveRichard MacCutchan13-Apr-16 0:44 
GeneralRe: csharp creating algorithm Pin
BillWoodruff13-Apr-16 3:02
professionalBillWoodruff13-Apr-16 3:02 
GeneralRe: csharp creating algorithm Pin
Sascha Lefèvre13-Apr-16 3:51
professionalSascha Lefèvre13-Apr-16 3:51 
GeneralRe: csharp creating algorithm Pin
BillWoodruff13-Apr-16 5:02
professionalBillWoodruff13-Apr-16 5:02 
AnswerRe: csharp creating algorithm Pin
Patrice T13-Apr-16 9:14
mvePatrice T13-Apr-16 9:14 
Questionpuzzle, sub string not working Pin
Member 1016760412-Apr-16 21:20
Member 1016760412-Apr-16 21:20 
AnswerRe: puzzle, sub string not working Pin
Richard MacCutchan12-Apr-16 21:25
mveRichard MacCutchan12-Apr-16 21:25 
QuestionCould not load file or assembly Pin
RAFish040412-Apr-16 8:26
RAFish040412-Apr-16 8:26 
AnswerRe: Could not load file or assembly Pin
Richard MacCutchan12-Apr-16 10:01
mveRichard MacCutchan12-Apr-16 10:01 
QuestionHow add a custom menu to Windows Explorer's tool bar Pin
srikrishnathanthri11-Apr-16 21:50
srikrishnathanthri11-Apr-16 21:50 
AnswerRe: How add a custom menu to Windows Explorer's tool bar Pin
Pete O'Hanlon11-Apr-16 22:22
mvePete O'Hanlon11-Apr-16 22:22 
GeneralRe: How add a custom menu to Windows Explorer's tool bar Pin
srikrishnathanthri12-Apr-16 3:51
srikrishnathanthri12-Apr-16 3:51 
QuestionRe: How add a custom menu to Windows Explorer's tool bar Pin
CHill6012-Apr-16 5:52
mveCHill6012-Apr-16 5:52 
GeneralRe: How add a custom menu to Windows Explorer's tool bar Pin
Eddy Vluggen12-Apr-16 5:59
professionalEddy Vluggen12-Apr-16 5:59 
GeneralRe: How add a custom menu to Windows Explorer's tool bar Pin
srikrishnathanthri12-Apr-16 23:40
srikrishnathanthri12-Apr-16 23:40 
GeneralRe: How add a custom menu to Windows Explorer's tool bar Pin
Eddy Vluggen13-Apr-16 0:05
professionalEddy Vluggen13-Apr-16 0:05 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.