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
11
votes
4 answers

Display and count qualifying data from a 2d array

I'm trying to count the number of times a certain value appears in my multidimensional array based on a condition. Here's an example array; $fruit = [ "oranges" => [ "name" => "Orange", "color" => "orange", "taste" …
user1221488
  • 175
  • 1
  • 2
  • 7
11
votes
16 answers

Code Golf 4th of July Edition: Counting Top Ten Occurring Words

Given the following list of presidents do a top ten word count in the smallest program possible: INPUT FILE Washington Washington Adams Jefferson Jefferson Madison Madison Monroe Monroe John Quincy Adams …
ojblass
  • 21,146
  • 22
  • 83
  • 132
10
votes
5 answers

Grouping and counting to get a closerate

I want to count per country the number of times the status is open and the number of times the status is closed. Then calculate the closerate per country. Data: customer <- c(1,2,3,4,5,6,7,8,9) country <- c('BE', 'NL',…
Rhulsb
  • 303
  • 2
  • 5
10
votes
3 answers

Use jq to count on multiple levels

We've discovered some domain names tied to infections. Now we have a list of DNS names in a .json file, and I'd like to produce a summarized output showing: a list of users, the unique domains they visited, the total count. Bonus points if I can…
JustChill
  • 103
  • 1
  • 1
  • 5
10
votes
3 answers

Efficiently count the number of occurrences of unique subarrays in NumPy?

I have an array of shape (128, 36, 8) and I'd like to find the number of occurrences of the unique subarrays of length 8 in the last dimension. I'm aware of np.unique and np.bincount, but those seem to be for elements rather than subarrays. I've…
Will
  • 4,241
  • 4
  • 39
  • 48
10
votes
1 answer

Count, Sort and Group-By in Powershell

Are there any cool cmdlets that will help me do the following? I want something in Powershell that is as simple as doing the same in SQL: select RootElementName , count(*) from Table group by RootElementName order by RootElementName I'm all XML…
NealWalters
  • 17,197
  • 42
  • 141
  • 251
10
votes
6 answers

Counting Values in Multidimensional Array

I currently have the following array: Array( [0] => Array ( [user] => Name 1 [group] => 1 ) [1] => Array ( [user] => Name 2 [group]…
lethalMango
  • 4,433
  • 13
  • 54
  • 92
9
votes
6 answers

Do While Loops Versus For Loops in Java for Counting

When it comes to counting, should a do-while loop be used, or a for loop? Because this: class Main { public static void main(String[] args) { int times = 1; do { System.out.println("I have printed " + times + " times."); …
Domani Tomlindo
  • 239
  • 1
  • 5
  • 12
9
votes
7 answers

How do I get the number of lists with a particular element?

I have a list of lists, which looks like listOfLists = [ ['a','b','c','d'], ['a','b'], ['a','c'], ['c','c','c','c'] ] I want to count the number of lists which have a particular element. For Example, my output should be…
N_B
  • 301
  • 2
  • 15
9
votes
5 answers

Java: Convert int[] to smallest representation as ranges

Given an array of int values, how could one parse the series into counting sequence notation? Examples: {1, 2, 3, 4, 5, 9, 13, 14, 15} -> "1-5,9,13-15" {4, 6, 8, 10, 11, 12, 15, 17} -> "4,6,8,10-12,15,17" I'm looking for a method that would…
user4996976
9
votes
5 answers

Counting coprimes in a sequence

Having a sequence of n <= 10^6 integers, all not exceeding m <= 3*10^6, I'd like to count how many coprime pairs are in it. Two numbers are coprime if their greatest common divisor is 1. It can be done trivially in O(n^2 log n), but this is…
Cris
  • 162
  • 1
  • 8
9
votes
2 answers

Difference between irange and counting_range in Boost

What's the difference between irange and counting_range? I needed irange to quickly generate a range of integers like this: auto example = boost::irange(0, 5); /// result is {0, 1, 2, 3, 4} But noticed an example somewhere (lost the link) that…
Alan Turing
  • 12,223
  • 16
  • 74
  • 116
8
votes
3 answers

How can I find and count number of files matching a given string?

I want to find and count all the files on my system that begin with some string, say "foo", using only one line in bash. I'm new to bash so I'd like to avoid scripting if possible - how can I do this using only simple bash commands and maybe piping…
Katherine Rix
  • 672
  • 2
  • 8
  • 18
8
votes
5 answers

Count repeating integers in an array

If I have this vector: x = [1 1 1 1 1 2 2 2 3 4 4 6 6 6 6] I would like to get the position of each unique number according to itself. y = [1 2 3 4 5 1 2 3 1 1 2 1 2 3 4] At the moment I'm using: y = sum(triu(x==x.')) % MATLAB 2016b and…
obchardon
  • 10,614
  • 1
  • 17
  • 33
8
votes
3 answers

Assign unique id to list of lists in python where duplicates get the same id

I have a list of lists (which can contain up to 90k elements) [[1,2,3], [1,2,4], [1,2,3], [1,2,4], [1,2,5]] I would like to assign an id to each elements, where the id is unique, except when the item is duplicated. So for the list above, I'd need…
jamborta
  • 5,130
  • 6
  • 35
  • 55