During the process of code development, intermittent problems commonly appear. These problems usually might not have much in common with actual main problem to be solved. These side-quests are part of the journey. This is a collection of things I accomplished.
While taking a test regarding my C++ skills, a specific subset of a set of elements had to be found.
The target subset was defined by a list of criteria.
The number of subsets of a specific size is given by the formula of combinations:
nCr = n! / ( r! * (n - r)!) where n=set_size and r=subset_size
The goal is to iterate all combinations of all sizes while keeping in mind the cardinality.
I knew this was more of a academic problem, because the set can only have a relatively small cardinality
e.g.: the set of all subsets (including itself and the null set) of a set of size 20 has a size of more then a million.
The number of all subsets of a set (size=n) is giving by 2n. The way this works is: every independent element of the set is either active or not → base_twoset_size. This then allows to iterate subsets by converting the iterant integer to a binary number and pad it from the front with zeros and use it as an activation vector.
Programmed in C++ using classes: <vector>, <algorithm>, and my own class "Wandel".
input: testSet = {"Butter", "Egg" , "Flour", "Sugar", "Salt"};
We can say that we need at least three ingredients to search for a recipe.
Giving what we have as inventory, we can walk combinations in such a way that we make the most of what is in the fridge.
This is an approach of optimization.
Given: A list of finite points, size=c, in a (cartesian) R2 space. The points provided are sequential, and form a single (possible concave) polygon: {P0,P1, … , Pc-1}. The goal was to find all, finite non-zero length, line segments from any two points of the polygon such that they are completely within the polygon.
Given m,n,t ∈ W (the set of whole numbers: {0,1,2,...}), such that Pm, Pn, Pt ∈ P (points of perimeter of polygon). Then the line from Pm to Pn, denoted by L(Pm, Pn) lies completely within the polygon area, A, if and only if all intersections of L(Pm, Pn) and all polygon line segments do not intersect (within segment range). Coded in C++.
The goal here was to visualize all possible routs (lines) within the large concave polygon from one node to another.
The fat line problem consists of the following lemma algorithm:
You have two points in the standard xy-plain or more formally known as cartesian R2.
You want to join these points with a line and are able to calculate which pixels to color in with a given line-radius of r.
But what do you do when three sequential points have an angle and you have to compute fast?
Below you can see the problem in a HTML Canvas element:
I wrote a more formatted proof later, but this was my pen and paper initial draft.
This is the formula shown in action in MS Excel.