Remove punctuation from string with Regex

First, please read here for information on regular expressions. It’s worth learning. You can use this: Regex.Replace(“This is a test string, with lots of: punctuations; in it?!.”, @”[^\w\s]”, “”); Which means: [ #Character block start. ^ #Not these characters (letters, numbers). \w #Word characters. \s #Space characters. ] #Character block end. In the end it … Read more

Determine non-convex hull of collection of line segments

Pick a safe starting point. Can be e.g. the endpoint with maximum x. March along the line segment. Upon encountering any intersection, always turn left and march along this new segment. Upon encountering an endpoint, record it. Goto 2. Stop when you have returned to your starting point. Your list of recorded endpoints now makes … Read more

Position N circles of different radii inside a larger circle without overlapping

Not a solution, just a brainstorming idea: IIRC one common way to get approximate solutions to the TSP is to start with a random configuration, and then applying local operations (e.g. “swapping” two edges in the path) to try and get shorter and shorter paths. (Wikipedia link) I think something similar would be possible here: … Read more

What does “Pure” mean, in the context of programming languages and paradigms?

The word pure has different meanings in different contexts. Functional Programming When people talk about Haskell being a pure language, they mean that it has referential transparency. That is, you can replace any expression with its value without changing the meaning of the program. For example, in Haskell: square :: Int -> Int square x … Read more

Why do trigonometric functions give a seemingly incorrect result? [duplicate]

Why is this happening? Trigonometric functions generally expect units in radians, while 90 is in degrees. This also applies for other functions such as cosine and tangent, not just the sine function. Most programming languages require trigonometric functions to provide their arguments in radians. This simplifies many things, especially on the implementation side as code … Read more