Skip to main content
removed thanks; edited tags
Source Link
t3chb0t
  • 44.7k
  • 9
  • 85
  • 191

Thanks in advance.


Thanks in advance.

added 81 characters in body
Source Link
newbie
  • 889
  • 8
  • 23

I've been learning C# for a few months now, and I've done some basic things in java last year. I made a solution for the problem the title states, this is the task description.

I've been learning C# for a few months now, and I've done some basic things in java last year.

I've been learning C# for a few months now, and I've done some basic things in java last year. I made a solution for the problem the title states, this is the task description.

Changed a way too large name function
Source Link
newbie
  • 889
  • 8
  • 23
/// <summary>
/// Find the minimum impact factor for every query in a given chain
/// </summary>
/// <returns>
/// An array of ints, every int represents the minimum impact factor found 
/// within ranges in a given chain
/// </returns>
public int[] GetMinimumImpactFactorWithinRangesInAGivenChainGetMinimumImpactFactors(string S, int[] P, int[] Q)
{
    //nuc(s) is short for nucleotide(s)
    Dictionary<char, int> nucsDict = new Dictionary<char, int>(){{'A',1},{'C',2},{'G',3},{'T',4}};
    int[] result = new int[P.Length];
    int[] nucsInOrder= new int[S.Length];
    int nucsIndex = 0;
    //iterate through dictionary, looking for A's, then C's, and so on...
    foreach ( var searchedImpactPair in nucsDict )
    {
        //Appearances of <searchedImpactPair.Key> have a given position in <S> chain, those positions are saved
        for (int currNucPos=0; currNucPos < S.Length; currNucPos++ )
        {
            if( S[currNucPos] == searchedImpactPair.Key )
            {
                nucsInOrder[nucsIndex++] = currNucPos ;
            }
        }
    }
    int start, end, minImpactValueFound, minNucFound;
    char nucleotide;
    for(int positionWithinRange = 0; positionWithinRange < P.Length; positionWithinRange++)
    {
        
        start = P[positionWithinRange];
        end = Q[positionWithinRange];
        for ( int nucInOrder = 0; nucInOrder < nucsInOrder.Length; nucInOrder++ )
        {
            minNucFound = nucsInOrder[nucInOrder];
            if ( minNucFound >= start && nucsInOrder[nucInOrder] <= end)
            {
                nucleotide = S[minNucFound];
                minImpactValueFound = nucsDict[nucleotide];
                result[positionWithinRange] = minImpactValueFound;
                break;
            }
        }
    }
    return result;
}
/// <summary>
/// Find the minimum impact factor for every query in a given chain
/// </summary>
/// <returns>
/// An array of ints, every int represents the minimum impact factor found 
/// within ranges in a given chain
/// </returns>
public int[] GetMinimumImpactFactorWithinRangesInAGivenChain(string S, int[] P, int[] Q)
{
    //nuc(s) is short for nucleotide(s)
    Dictionary<char, int> nucsDict = new Dictionary<char, int>(){{'A',1},{'C',2},{'G',3},{'T',4}};
    int[] result = new int[P.Length];
    int[] nucsInOrder= new int[S.Length];
    int nucsIndex = 0;
    //iterate through dictionary, looking for A's, then C's, and so on...
    foreach ( var searchedImpactPair in nucsDict )
    {
        //Appearances of <searchedImpactPair.Key> have a given position in <S> chain, those positions are saved
        for (int currNucPos=0; currNucPos < S.Length; currNucPos++ )
        {
            if( S[currNucPos] == searchedImpactPair.Key )
            {
                nucsInOrder[nucsIndex++] = currNucPos ;
            }
        }
    }
    int start, end, minImpactValueFound, minNucFound;
    char nucleotide;
    for(int positionWithinRange = 0; positionWithinRange < P.Length; positionWithinRange++)
    {
        
        start = P[positionWithinRange];
        end = Q[positionWithinRange];
        for ( int nucInOrder = 0; nucInOrder < nucsInOrder.Length; nucInOrder++ )
        {
            minNucFound = nucsInOrder[nucInOrder];
            if ( minNucFound >= start && nucsInOrder[nucInOrder] <= end)
            {
                nucleotide = S[minNucFound];
                minImpactValueFound = nucsDict[nucleotide];
                result[positionWithinRange] = minImpactValueFound;
                break;
            }
        }
    }
    return result;
}
/// <summary>
/// Find the minimum impact factor for every query in a given chain
/// </summary>
/// <returns>
/// An array of ints, every int represents the minimum impact factor found 
/// within ranges in a given chain
/// </returns>
public int[] GetMinimumImpactFactors(string S, int[] P, int[] Q)
{
    //nuc(s) is short for nucleotide(s)
    Dictionary<char, int> nucsDict = new Dictionary<char, int>(){{'A',1},{'C',2},{'G',3},{'T',4}};
    int[] result = new int[P.Length];
    int[] nucsInOrder= new int[S.Length];
    int nucsIndex = 0;
    //iterate through dictionary, looking for A's, then C's, and so on...
    foreach ( var searchedImpactPair in nucsDict )
    {
        //Appearances of <searchedImpactPair.Key> have a given position in <S> chain, those positions are saved
        for (int currNucPos=0; currNucPos < S.Length; currNucPos++ )
        {
            if( S[currNucPos] == searchedImpactPair.Key )
            {
                nucsInOrder[nucsIndex++] = currNucPos ;
            }
        }
    }
    int start, end, minImpactValueFound, minNucFound;
    char nucleotide;
    for(int positionWithinRange = 0; positionWithinRange < P.Length; positionWithinRange++)
    {
        
        start = P[positionWithinRange];
        end = Q[positionWithinRange];
        for ( int nucInOrder = 0; nucInOrder < nucsInOrder.Length; nucInOrder++ )
        {
            minNucFound = nucsInOrder[nucInOrder];
            if ( minNucFound >= start && nucsInOrder[nucInOrder] <= end)
            {
                nucleotide = S[minNucFound];
                minImpactValueFound = nucsDict[nucleotide];
                result[positionWithinRange] = minImpactValueFound;
                break;
            }
        }
    }
    return result;
}
Source Link
newbie
  • 889
  • 8
  • 23
Loading