Questions tagged [counting]

Counting is the action of finding the number of elements of a finite set of objects.

Counting is the action of finding the number of elements of a finite set of objects. The traditional way of counting consists of continually increasing a (mental or spoken) counter by a unit for every element of the set, in some order, while marking (or displacing) those elements to avoid visiting the same element more than once, until no unmarked elements are left; if the counter was set to one after the first object, the value after visiting the final object gives the desired number of elements. The related term enumeration refers to uniquely identifying the elements of a finite (combinatorial) set or infinite set by assigning a number to each element.

Counting using tally marks at Hanakapiai Beach Counting sometimes involves numbers other than one; for example, when counting money, counting out change, "counting by twos" (2, 4, 6, 8, 10, 12, ...), or "counting by fives" (5, 10, 15, 20, 25, ...). There is archeological evidence suggesting that humans have been counting for at least 50,000 years. Counting was primarily used by ancient cultures to keep track of social and economic data such as number of group members, prey animals, property, or debts (i.e., accountancy). The development of counting led to the development of mathematical notation, numeral systems, and writing.

1837 questions
5
votes
2 answers

Combinatorics or another approach?

I've recently read this problem, first, I thought of a combinatorial approach, but it seems nobody - along the contestants - has submitted such a solution. Is a solution using combinatorics possible? If not, what's the solution? The problem briefly…
Chris
  • 26,544
  • 5
  • 58
  • 71
5
votes
1 answer

How would I go about counting the amount of each alphanumerical in an array? (APL)

I can't figure out how to take a matrix and count the amount of the alphanumerical values for each row. I will only be taking in matrices with the values I'm counting. For example, if I got: ABA455 7L9O36G …
JTP
  • 85
  • 4
5
votes
2 answers

Inconsistency of na.action between xtabs and aggregate in R

I have the following data.frame: x <- data.frame(A = c("Y", "Y", "Z", NA), B = c(NA, TRUE, FALSE, TRUE), C = c(TRUE, TRUE, NA, FALSE)) And I need to compute the following table with xtabs: A B C Y 1 2 Z …
Thomas
  • 457
  • 2
  • 12
5
votes
2 answers

Counting the number

I have got a code that generates all possible correct strings of balanced brackets. So if the input is n = 4 there should be 4 brackets in the string and thus the answers the code will give are: {}{} and {{}}. Now, what I would like to do is print…
checkmate_
  • 51
  • 3
5
votes
5 answers

Java stream collect counting to field

Is it possible use Collectors.groupingBy() with Collectors.counting() to count to the field of a custom object instead of creating a map and transforming it afterwards. I have a list of users, like this: public class User { private String…
Samuel Philipp
  • 10,631
  • 12
  • 36
  • 56
5
votes
3 answers

How to count groups of integers within arrays, without sorting the array?

My goal is to be able to count groups of the same integer within an array. For example, in an array like so, {1, 1, 1, 2, 2, 3, 1, 1}, there are 4 groups: of at least size 1: 3 groups of at least size 2: 1 group of at least size 3 I'm having…
5
votes
4 answers

Grouping and pivoting DataFrame with additional column for ratio of counts

I have a dataframe that looks like this: id status year 1 yes 2014 3 no 2013 2 yes 2014 4 no 2014 The actual dataframe is very large with multiple ids and years. I am trying…
Priya
  • 217
  • 2
  • 9
5
votes
3 answers

Count how many times a column contains a certain value in Pandas

Let's say my dataframe looks like this: column_name 1 book 2 fish 3 icecream|book 4 fish 5 campfire|book Now, if I use df['column_name'].value_counts() it will tell me fish is the most frequent value. However, I want book to be returned,…
Boomer
  • 383
  • 2
  • 4
  • 15
5
votes
6 answers

Check if specific characters are in a string

I need to find and count how many characters can be found in a string. I have divided the characters into chars1[a:m] and chars2[n:z], and have two counters. The output should be 0/14, but it is 0/1 instead. I think it only checks to see if one and…
5
votes
3 answers

Count number of non-NA values by group

For example, I have this data frame (df): Color X1 X2 X3 X4 Red 1 1 0 2 Blue 0 NA 4 1 Red 3 4 3 1 Green 2 2 1 0 I would like to create a function that counts up…
Ashley
  • 413
  • 3
  • 8
  • 17
5
votes
1 answer

pandas aggregate count in dataframe

I have a DataFrame and I am using .aggregate({'col1': np.sum}), this will perform a summation of the values in col1 and aggregate them together. Is it possible to perform a count, something like .aggregate({'col1': some count function here})?
Mike El Jackson
  • 771
  • 3
  • 14
  • 23
5
votes
2 answers

Python: Recursive call counting ways of walking grid yield incorrect answer when grid size is too large

Problem: Imagine you start at the corner of an X by Y grid. You can only move in two directions: right and down. How many possible paths are there for you to go from (0, 0) to (X, Y) I have two approaches for this, first is to use a recursive…
Kesong Xie
  • 1,316
  • 3
  • 15
  • 35
5
votes
2 answers

Output iterator adapter to count but not copy

There are various STL algorithms that rely on an output iterator to store the result of the algorithm. For example, std::set_intersection will store all the common elements between two sorted ranges in an Output iterator that is then post…
T33C
  • 4,341
  • 2
  • 20
  • 42
5
votes
5 answers

Reference Counting in C++

I'm implementing a math library in C++. The library will be compiled to a DLL so those who use it will only need the header files the classes' definitions. The users of my classes will be people who are new to the language. However, there are some…
Eduardo León
5
votes
1 answer

Number of trees that can be formed by deleting nodes in a graph

0 | 0__1__0 | | | 1__1__0 | 1 Let's say I have a undirected graph. We have these conditions: You are only allowed to delete nodes labeled as '1'. Deletion of any node must not make the graph a forest We are allowed to delete multiple…
Prajwal K R
  • 682
  • 5
  • 14