## c # – Counting direct and indirect orbits and counting the distance of the orbits

I recently resolved Advent of Code 2019 Day 6 in C #.

Part 1:

You have landed at the Universal Orbit Map facility in Mercury. Why
Space navigation often involves transfer between orbits, the
The orbit maps here are useful for finding efficient routes between
example, you and Santa. Download a map of the local orbits (your
puzzle entry).

Except the Universal Mass Center (COM), each object in space
It is in orbit around another object exactly. An orbit looks more or less
I like this:

``````

|
|
AAA--> o            o <--BBB
|
|
/
/
``````

In this diagram, the BBB object is in orbit around AAA. The path that
BBB takes around AAA (drawn with lines) only shown in part. At
map data, this orbital relationship is written AAA) BBB, which means
"BBB is in orbit around AAA."

Before using the map data to plot a course, you must ensure
The orbit map installation uses orbit count checksums: the total number
direct orbits (like the one shown above) and indirect orbits.

Whenever A orbits B and B orbits C, then A indirectly orbits C. This
the string can have any number of objects: if A orbits B, B orbits C,
and C orbits D, then A indirectly orbits D.

For example, suppose you have the following map:

``````COM)B
B)C
C)D
D)E
E)F
B)G
G)H
D)I
E)J
J)K
K)L
``````

Visually, the previous map of orbits looks like this:

``````        G - H       J - K - L
/           /
COM - B - C - D - E - F

I
``````

In this visual representation, when two objects are connected by a
line, the one on the right orbits directly to the one on the left.

Here, we can count the total number of orbits as follows:

D directly orbits C and indirectly orbits B and COM, a total of 3
L orbits directly orbits K and indirectly orbits J, E, D, C, B and
COM, a total of 7 orbits. COM doesn't orbit anything. The total number of
The direct and indirect orbits in this example are 42.

What is the total number of direct and indirect orbits on your map?
data?

Part 2:

Now, you just need to find out how many orbital transfers you (YOU)
You need to take to get to Santa (SAN).

You start at the object YOU are orbiting; your destiny is the
The SAN object is in orbit. An orbital transfer allows you to move from any
object to an object in orbit or orbited by that object.

For example, suppose you have the following map:

``````COM)B
B)C
C)D
D)E
E)F
B)G
G)H
D)I
E)J
J)K
K)L
K)YOU
I)SAN
``````

Visually, the previous map of orbits looks like this:

``````                          YOU
/
G - H       J - K - L
/           /
COM - B - C - D - E - F

I - SAN
``````

In this example, YOU are in orbit around K and SAN is in orbit around
I. To pass from K to I, a minimum of 4 orbital transfers is required:

``````K to J
J to E
E to D
D to I
``````

Then, the map of orbits looks like this:

``````        G - H       J - K - L
/           /
COM - B - C - D - E - F

I - SAN

YOU
``````

What is the minimum number of orbital transfers necessary to move from
the object that YOU are orbiting the object that SAN is orbiting? (Between
the objects that orbit, not between YOU and SAN)

I am quite new to C # and I come from a C ++ fund and I would like to learn how to improve writing more idiomatic and readable code. My approach to the problem is as follows:

First, I've been pasting the entry to a text file every day and reading the entry of `File`. In this case, I tokenize the entries in a `List>` what can I do next `OrbitalMapCalculator`. My `OrbitalMapCalculator` Then create a list of each body that already has a count of how many direct and indirect orbits it has. Because each body maintains its own orbit count, an orbiting body can simply increase the number of orbits in the orbiting body.

For the first part, I simply add the total orbits of all the bodies.

For the second part, I find the distance of "YOU" to the center and "SAN" to the center. Then I find the first common orbit. From there I find the two distances and sumo.

Here is the tokenizer:

``````using System;
using System.IO;
using System.Collections.Generic;

{
class ProcessInput
{
internal List> GenerateOrbitalPairs(string textFile)
{
List> orbitalTokens = new List>();

if (File.Exists(textFile))
{
foreach (string pair in tokenPairs)
{
string() splitPair = pair.Split(')');
}
}

return orbitalTokens;
}
}
}
``````

Most of the work is done in the `OrbitalMapCalculator`:

``````using System;
using System.Collections.Generic;

{
internal class OrbitalMapCalculator
{
private class Node
{
public Node orbitingNode;
public int numberOfOrbits;
public string ID;

public Node(string id)
{
orbitingNode = null;
numberOfOrbits = 0;
ID = id;
}

public Node(Node orbiting, string id)
{
orbitingNode = orbiting;
numberOfOrbits = orbiting.numberOfOrbits + 1;
ID = id;
}
}

private List orbitalMap = new List();

{
string centerOfMass = "COM";
Node centerNode = new Node(centerOfMass);
Queue centerNames = new Queue();
centerNames.Enqueue(centerOfMass);

while (centerNames.Count > 0)
{
centerOfMass = centerNames.Dequeue();

foreach (Node node in orbitalMap)
{
if (node.ID == centerOfMass)
{
centerNode = node;
break;
}
}

foreach (Tuple pair in orbitalPairs)
{
if (centerOfMass == pair.Item1)
{
centerNames.Enqueue(pair.Item2);
}
}
}
}

public int CountOrbits()
{
int orbits = 0;
foreach (Node node in orbitalMap)
{
orbits += node.numberOfOrbits;
}
return orbits;
}

public int DistanceToSanta()
{
string yourID = "YOU";
string santasID = "SAN";
Node you = null;
Node santa = null;

foreach (Node node in orbitalMap)
{
if (node.ID == yourID)
{
you = node;
}
if (node.ID == santasID)
{
santa = node;
}
}

List youToCenter = new List();
List santaToCenter = new List();
Node pivotNode = FindPivotNode(youToCenter, santaToCenter);

int youToPivot = you.numberOfOrbits - pivotNode.numberOfOrbits - 1;
int santaToPivot = santa.numberOfOrbits - pivotNode.numberOfOrbits - 1;

return youToPivot + santaToPivot;
}

private void AddNodesTilCenter(Node sentinal, List nodes)
{
while (sentinal.orbitingNode != null)
{
sentinal = sentinal.orbitingNode;
}
}

private Node FindPivotNode(List lhs, List rhs)
{
foreach (Node leftNode in lhs)
{
foreach (Node rightNode in rhs)
{
if (leftNode.ID == rightNode.ID)
{
return leftNode;
}
}
}
return null;
}
}
}
``````

And finally the `Program.cs`:

``````using System;
using System.Collections.Generic;

{
class Program
{
static void Main(string() args)
{
string inputFile =
ProcessInput processor = new ProcessInput();
OrbitalMapCalculator calculator = new OrbitalMapCalculator();
List> orbitalPairs = processor.GenerateOrbitalPairs(inputFile);

// Part One only

// Part Two Only

}
}
}
``````

## layered navigation: the category toolbar shows that incorrect counting and paging do not work

I have a problem with a live site where the toolbar shows the wrong product count, does not change the sorting address or the filter, nor does it change the product in the paging change.

You can see it here – Tuckers Butchers Poultry

Sample 1-33 of 33 products where the filter count is set to 20

If you click on page 2 at the bottom of the page, it changes to "21-53 of 33" but the products shown remain the same.

If you choose the "descending" price, again, the page is updated but the products remain the same.

I have a development site that runs the same code base that works well, both run Magento 2.3.3

The only difference is that the live site has docroot set up in / pub / and I was wondering if anyone else has seen this happen.

Interestingly, the toolbar works well in search results.

I would really appreciate your help.

## java – Counting tree nodes

The program is about binary trees (insertion, paths, etc.), and for the moment I try to implement a method that can read the amount of leaves found in my tree.
These are the problems that I have tried to solve without any success.
1. That in the NodeArbol class, the Nodes account class works as a method, since it was a recommendation that they made me so as not to separate it into two.
2. I would also like to know how I can send it to call from my main.

Thank you in advance for reading the publication and any help is welcome.

Tree Node Class

`````` public class NodoArbol {
int dato;
String nombre;
NodoArbol hijoIzquierdo, hijoDerecho;
//constructor
public NodoArbol(int d,String nom){
this.dato=d;
this.nombre=nom;
this.hijoDerecho=null;
this.hijoIzquierdo=null;
}
public String toString(){
return nombre + " Su dato es " + dato;
}

public class cuentaNodos {
//Raíz del arbol
NodoArbol raiz;

/* Funcion para que cuente las hojas del arbol binario*/
int cuentaHojas()
{
return cuentaHojas(raiz);
}

int cuentaHojas(NodoArbol nodo)
{
if (raiz == null)
return 0;
if (raiz.hijoIzquierdo == null && nodo.hijoDerecho == null)
return 1;
else
return cuentaHojas(raiz.hijoIzquierdo) + cuentaHojas(raiz.hijoDerecho);
}
}

}
``````

A fragment of my TreeBinary class

``````public class ArbolBinario {

NodoArbol raiz;

public ArbolBinario() {
raiz = null;
}
``````

How to print in main

``````case 2:
if (!arbol.estaVacio()) {
System.out.println();
arbol.inOrder(arbol.raiz);
} else {
JOptionPane.showMessageDialog(null, "Arbol Vacio",
}
break;
``````

## java – Counting tree nodes

What I am trying to do is that my NodeArbol class works with the Nodes class, since it is a solution that I found on the Internet but I have no idea how to relate it.

``````public class NodoArbol {
int dato;
String nombre;
NodoArbol hijoIzquierdo, hijoDerecho;
//constructor
public NodoArbol(int d,String nom){
this.dato=d;
this.nombre=nom;
this.hijoDerecho=null;
this.hijoIzquierdo=null;
}
public String toString(){
return nombre + " Su dato es " + dato;
}
``````

}

``````public class cuentaNodos {
//Raíz del arbol
NodoArbol raiz;

/* Funcion para que cuente las hojas del arbol binario*/
int cuentaHojas()
{
return cuentaHojas(raiz);
}

int cuentaHojas(NodoArbol nodo)
{
if (raiz == null)
return 0;
if (raiz.hijoIzquierdo == null && nodo.hijoDerecho == null)
return 1;
else
return cuentaHojas(raiz.hijoIzquierdo) + cuentaHojas(raiz.hijoDerecho);
}
``````

}

## graphics – Counting nodes within the distance K of the set of nodes given in a tree

https://www.geeksforgeeks.org/count-nodes-within-k-distance-from-all-nodes-in-a-set/

The question says: given a non-directed tree with some marked nodes and a positive number K. We need to print the count of all those nodes that have a distance from all the marked nodes less than K, which means that each node whose distance from all The marked nodes is less than K, must be counted in the result.

The mentioned solution says that we find two marked nodes that are at a maximum distance between all the pairs of marked nodes, and any node that is within the distance k of both nodes will be within the distance k of all the marked nodes, and for that is what bfs do from "random node" to obtain the first node marked distant and then the second bfs of this node found to obtain the second distant node.
I understood how the second bfs of the first distant node finds another distant node, but I cannot visualize how a bfs of the "random node" in the tree helps to find one of the distant nodes.

## Mining theory: how the miner starts counting the timestamp to insert into the block

I have a doubt, how the miner starts counting the timestamp to insert into the block.

An example of a time stamp insertion into the genesis block is 1/3/2009, 7:15:05 PM GMT + 1. If the genesis block had been removed, is it the time when the miner has started to Solve the proof of work or is the time when the miner wins the proof of work?

## python 3.x – Counting frequencies in a list

I have the following code that works to count frequencies in a list. However, the output of this code is NoneType, so I cannot use methods such as .sort, for example, to organize the output to be displayed in descending order of frequency.

Could someone help me solve? I would like the result to be presented as a table or dictionary, but not NoneType.

``````def frequency(my_list):

# Creating an empty dictionary
freq = {}
for item in my_list:
if (item in freq):
freq(item) += 1
else:
freq(item) = 1

for key, value in freq.items():
print (" % d : % d"%(key, value))
``````

my_list = (1, 1, 1, 5, 5, 3, 1, 3, 3, 1, 4, 4, 4, 2, 2, 2, 2)

end_list = frequency (my_list)

## co.combinatorics – Counting the number of grids with certain dominoes not allowed

I'm curious to know if there is a general strategy to solve the following type of counting problem.

Fix a positive integer $$n$$, and let $$(n) = {1, points, n }$$.

Preliminaries

Definition A $$n$$-size grid $$i times j$$ it's a function $$(i) times (j) to (n)$$. Equivalently, this is a $$i times j$$ matrix with entries in $$(n)$$.

Definition A $$n$$-domino is a $$n$$-size grid $$1 for 2$$ or $$2 for 1$$.

Definition Yes $$G_1$$ Y $$G_2$$ They are $$n$$-grids, we say that $$G_1 preceq G_2$$ Yes $$G_1$$ occurs as a contiguous subframe of $$G_2$$.

More precisely, yes $$G_1: (i_1) times (j_1) to (n)$$ Y $$G_2: (i_2) times (j_2) to (n)$$ so $$G_1 preceq G_2$$ yes and only if there are non-negative integers $$s, t$$ such that $$i_1 + s leq i_2$$, $$j_1 + t leq j_2$$Y $$G_2 (x + s, y + t) = G_1 (x, y)$$ for all $$(x, y) in (i_1) times (j_1)$$.

$$preceq$$ it's actually a partial order in $$n$$-grids, so this notation is not bad.

Leave $$mathcal {G} i, j}$$ be the set of $$n$$-size grilles $$i times j$$. Leave $$mathcal {D} = mathcal {G} _ {1,2} cup mathcal {G} _ {2,1}$$ be the set of $$n$$-domain.

issue Dice $$mathcal {S} subseteq mathcal {D}$$, Can we find a recurrence relationship (or something) for the two-dimensional sequence
$$a_ {i, j} = lvert {G in mathcal {G} _ {i, j}: forall D in mathcal {S} (D not preceq G) } rvert ?$$

In other words, I wonder if there is a strategy to count the number of $$i times j$$ $$n$$-Grids that do not contain certain dominoes not allowed.

## Counting term arithmetic progressions k

If I am looking at the family of arithmetic progressions with a fixed space of 2 m, how do I count the number of arithmetic progressions of k terms of [1, n] to apply the probabilistic method?