admin


Recent Questions
Recent Answers
  • Is there a way to write an UPDATE statement to fix multiple rows with bad data?

    9 hours ago

    The problem here is that you have multiple records with factoryId = 100. You can "fix" this with a TOP 1 as below, but you must be certain that the partID is the same on all records with the subquery's factoryId:

    UPDATE machineParts SET partID = (SELECT TOP(1) partID FROM  partsCatalog WHERE factoryId = 100)
    WHERE partID IN(123, 124);
    

    This says "just give me the partID on the first record with factoryId 100". You can also tweak the subquery to give you the most recent one, assuming there's a createdOn field as an example:

    UPDATE machineParts SET partID = (SELECT TOP(1) partID FROM  partsCatalog WHERE factoryId = 100 ORDER BY createdOn DESC)
    WHERE partID IN(123, 124);
    

  • Is there a way make a character to be part of two matches not only one

    13 hours ago

    Here is a way to do this in C#. We can find all matches on the regex pattern 10+(?=1). This uses a lookahead at the end of the pattern to assert a trailing 1, but note that the trailing 1 does not actually get consumed in each match. It gets consumed in the start of the following match. Then, to build the actual output match, we need to append a 1 to the end of each match.

    string input = "1010010001";
    Regex regex = new Regex(@"10+(?=1)");
    MatchCollection matches = regex.Matches(input);
    foreach(Match match in matches)
    {
        Console.WriteLine("Found a match: {0}1", match.Value);
    }
    

    This prints:

    Found a match: 101
    Found a match: 1001
    Found a match: 10001
    

  • Trying to only print specific numbers in this Array Method

    1 day ago

    This can be easily solved by working out the correct size of the new array first before you create it. Then simply loop the array and only store the odd numbers. Otherwise, remove/trim the array size before returning it.

    Here is a solution by modifying your removeEvens method:

    public int[] removeEvens(int[] nums)
    {  //start of method
    
        int count = 0;
    
        // start of array conversion
        // Count the odd numbers to work out the array length
        for (int i = 0; i < nums.length; i++)
        {
            if (nums[i] % 2 == 1)
            {
                count++;
            }
        }
    
        // Now create a new array of the correct length
        int[] newArray = new int[count];
    
        // Now loop through the original array and only store the odd numbers in the new array
        int counter = 0;
        for (int i = 0; i < nums.length; i++)
        {
            if (nums[i] % 2 == 1)
            {
                newArray[counter] = nums[I];
                counter ++;
            }
        }
    
        // Return the result
        return newArray;
    }
    

    Result:

    [1, 3, 5, 7, 9]
    

  • Trying to only print specific numbers in this Array Method

    1 day ago

    change it to return Arrays.copyOfRange(newArray, 0, counter); when you make in array of ints in java with a specified size, it sets every value in the array to 0. Doing this will remove all of the extraneous 0s at the end.

  • How do i print a list of float values without the list brackets?

    1 day ago

    Simply unpack the list using *:

    print(*mylist)
    

  • How do i print a list of float values without the list brackets?

    1 day ago

    Use str.join:

    mylist = [0.005, 0.354, 0.645]
    stringified = " ".join(map(str, mylist))
    print(stringified)
    

  • How do i print a list of float values without the list brackets?

    1 day ago

    try it:

    >>> mylist = [0.005, 0.354, 0.645]
    >>> list2 = [str(i) for i in mylist]  # ['0.005', ...]
    >>> ' '.join(list2):
    0.005 0.354 0.645
    >>> 
    

  • Can anyone please explain how this &quot;else if&quot; C# code end in 720?

    1 day ago

    its very simple... you need to understand the code only. And you could put the effort to learn how to code... its a recursive function. Simpler than what my prof gave me at university :D The function Fact is run with 6 as parameter. The function checks if the number is 1. if its not, what is initially the case, you multiply the 6 with 6-1 and repeat this till you reach 1 and then you stop. So basically you are calculating 6x5x4x3x2x1= 720

  • Haskell make a List of own defined type

    1 day ago

    Yes, you can construct a list with:

    [Tag 'A' 1, Tag 'A' 2, Tag 'A' 3, Tag 'B' 1, Tag 'B' 2, Tag 'B' 3, Tag 'C' 1, Tag 'C' 2, Tag 'C' 3, Tag 'D' 1, Tag 'D' 2, Tag 'D' 3]
    

    If you want to use values from two lists, you can work with:

    Tag <$> "ABCD" <*> [1,2,3]
    

    This makes use of the instance of a Functor and Applicative of the list instance. This means that Tag <$> "ABCD" will return a list of functions like [Tag 'A', Tag 'B', Tag 'C', Tag 'D'], next it will make use of the (<*>) :: Applicative f => f (a -> b) -> f a -> f b which will take a list of functions and a list of values, and will return a list that contains any combination of a function from the first list, and a value from the second list.