canton7
canton7
CC#
Created by JoelQ on 5/30/2025 in #help
Is the task using reference of the outer enumerable ?
If it helps, there's no built-in way to copy in IEnumerable, and there's no way to implicitly copy any reference type
4 replies
CC#
Created by I dont know on 5/29/2025 in #help
✅ Need help implementing support for quoting with single quotes
Good to hear!
15 replies
CC#
Created by I dont know on 5/29/2025 in #help
✅ Need help implementing support for quoting with single quotes
Cool! I didn't mean to pressure you to close it. Feel free to open a new thread if you need
15 replies
CC#
Created by I dont know on 5/29/2025 in #help
✅ Need help implementing support for quoting with single quotes
$close
15 replies
CC#
Created by I dont know on 5/29/2025 in #help
✅ Need help implementing support for quoting with single quotes
(There are times when regexes are great, and there are times when breaking out a manual loop is an awful lot easier. This problem in particular is a lot easier with a manual loop)
15 replies
CC#
Created by I dont know on 5/29/2025 in #help
✅ Need help implementing support for quoting with single quotes
Cool, good luck!
15 replies
CC#
Created by I dont know on 5/29/2025 in #help
✅ Need help implementing support for quoting with single quotes
Inside the else in the loop you could add the chars to an array sure, but it would be easier to use a StringBuilder. (Or you could track the starting index of the current arg and then use Substring, but that falls down when you come to escape quotes). Inside the else if (ch == ' ' && !inQuotes), that's when you find a space that isn't in quotes, i.e. the end of one argument and the start of another. So that's where you turn the current in-progress argument into a string, probably add it to a list of string args, and clear the StringBuilder. Outside of the loop you need to check whether you're in the middle of processing an arg, and finish it if so. The if (inQuotes) means that you finished processing with mis-matched quotes, so maybe you need to raise an error
15 replies
CC#
Created by I dont know on 5/29/2025 in #help
✅ Need help implementing support for quoting with single quotes
(That will really come in handy when you come to having to escape quotes, which is something that is really painful with regex, if you can make it work at all. Since quote escapes don't form a regular language IIRC)
15 replies
CC#
Created by I dont know on 5/29/2025 in #help
✅ Need help implementing support for quoting with single quotes
Something like:
string input = "'/tmp/file name' '/tmp/file name with spaces'";

bool inQuotes = false;
foreach (var ch in input)
{
if (ch == '\'')
{
inQuotes = !inQuotes;
}
else if (ch == ' ' && !inQuotes)
{
// ...
}
else
{
// ...
}
}

if (inQuotes)
{
// ...
}
string input = "'/tmp/file name' '/tmp/file name with spaces'";

bool inQuotes = false;
foreach (var ch in input)
{
if (ch == '\'')
{
inQuotes = !inQuotes;
}
else if (ch == ' ' && !inQuotes)
{
// ...
}
else
{
// ...
}
}

if (inQuotes)
{
// ...
}
15 replies
CC#
Created by I dont know on 5/29/2025 in #help
✅ Need help implementing support for quoting with single quotes
I wouldn't use regex for this. It's a lot easier to just loop through the characters. Have a bool to say whether you're inside quotes
15 replies
CC#
Created by Cykotech on 5/27/2025 in #help
Prefix sum with Hashmaps
There's an equal number of 1's and 0's since every subsequent time you saw that count too, but since you're after the longest subarray, you're just interested in the first time
9 replies
CC#
Created by Cykotech on 5/27/2025 in #help
Prefix sum with Hashmaps
Every time you arrive at a particular count, there must be an equal number of 1's and 0's since the first time you saw that count
9 replies
CC#
Created by Cykotech on 5/27/2025 in #help
Prefix sum with Hashmaps
The image in the link above shows it quite well I think
9 replies
CC#
Created by Sakpot on 5/28/2025 in #help
✅ UI.dll added to references but not in toolbox
$details
4 replies
CC#
Created by Cykotech on 5/27/2025 in #help
Prefix sum with Hashmaps
Actually "Approach #2" here explains it well: https://leetcode.com/problems/contiguous-array/editorial/
9 replies
CC#
Created by Cykotech on 5/27/2025 in #help
Prefix sum with Hashmaps
So, image walking through the array, element by element. If we see a 0 we subtract 1 from count, and if we see a 1 we add 1 to count. Let's take the Example 3 from the leetcode page (0,1,1,1,1,1,0,0,0), and we'll record count against each element:
Index | Value | count
0 | 0 | -1
1 | 1 | 0
2 | 1 | 1
3 | 1 | 2
4 | 1 | 3
5 | 1 | 4
6 | 0 | 3
7 | 0 | 2
8 | 0 | 1
Index | Value | count
0 | 0 | -1
1 | 1 | 0
2 | 1 | 1
3 | 1 | 2
4 | 1 | 3
5 | 1 | 4
6 | 0 | 3
7 | 0 | 2
8 | 0 | 1
If we calculate a count value which is equal to a count value that we calculated for a previous index (for example, at index 6 we calculate a count value of 3, which is the same as the count for index 4), then we know there must be an equal number of 1's and 0's between those two indexes. Because we had to sum an equal number of 1's and 0's to get back to where we started. So, we keep track of the first position at which we first found each count. And when we calculate a count which we've seen before, we look at the number of elements between that first position and the current position: that's the length of the sub-array between those two positions. Then we keep track of the max length of such sub-arrays, and that's our answer.
9 replies
CC#
Created by Xan on 5/26/2025 in #help
✅ What are some more ways I can asynchronously wait on callbacks
👍
12 replies
CC#
Created by Xan on 5/26/2025 in #help
✅ What are some more ways I can asynchronously wait on callbacks
It's a thing that creates a Task object, and gives you set of methods to complete that task (with a result, exception, etc)
12 replies
CC#
Created by Xan on 5/26/2025 in #help
✅ What are some more ways I can asynchronously wait on callbacks
12 replies
CC#
Created by Xan on 5/26/2025 in #help
✅ What are some more ways I can asynchronously wait on callbacks
Maybe I'm missing something, but couldn't you have a queue of (caster, taskcompletionsource), which is processed by the main thread every physics frame?
12 replies