Skip to main content
Log in

Enriching Students’ Combinatorial Reasoning through the Use of Loops and Conditional Statements in Python

  • Published:
International Journal of Research in Undergraduate Mathematics Education Aims and scope Submit manuscript

Abstract

When solving counting problems, students often struggle with determining what they are trying to count (and thus what problem type they are trying to solve and, ultimately, what formula appropriately applies). There is a need to explore potential interventions to deepen students’ understanding of key distinctions between problem types and to differentiate meaningfully between such problems. In this paper, we investigate undergraduate students’ understanding of sets of outcomes in the context of elementary Python computer programming. We show that four straightforward program conditional statements seemed to reinforce important conceptual understandings of four canonical combinatorial problem types. We also suggest that the findings in this paper represent one example of a way in which a computational setting may facilitate mathematical learning.

This is a preview of subscription content, log in via an institution to check access.

Access this article

Price excludes VAT (USA)
Tax calculation will be finalised during checkout.

Instant access to the full article PDF.

Fig. 1
Fig. 2
Fig. 3
Fig. 4
Fig. 5
Fig. 6
Fig. 7
Fig. 8
Fig. 9
Fig. 10
Fig. 11
Fig. 12
Fig. 13
Fig. 14
Fig. 15
Fig. 16
Fig. 17
Fig. 18
Fig. 19
Fig. 20
Fig. 21
Fig. 22
Fig. 23

Similar content being viewed by others

Notes

  1. The students categorized them according to the problem types reflected in the first three quadrants of the two-by-two table – they were not given any selection with repetition problems.

  2. This reflects the multiplication principle, which is a guiding principle that describes when it is appropriate to multiply in counting problems. See Tucker (2002), Lockwood et al. (2017), and Lockwood and Purdy (2019) for more details about the multiplication principle.

  3. There are connections to the students’ activity to other parts of the taxonomy, including using computational models to understand a concept and constructing computational models, but we do not have space to detail how the students’ Python programming relates to these other practices.

  4. We make a brief note about n!. Typically students recognize n! as the product of the positive integers from 1 to n, and they are exposed to this in calculus (especially Taylor series expansions). However, such exposure typically does not imply that they have a combinatorial interpretation of n factorial as the number of arrangements of n distinct elements (further insight about students’ reasoning about factorials can be found in Lockwood and Erickson 2017).

  5. Specifically, Pair 1 met over 11 sessions that were each 60–90 min long over the course of 7 weeks. They met on TR of Weeks 1, 2, and 3, T of Week 4, TR of Week 5, and T of Weeks 6 and 7. Pair 2 meet over 9 sessions that were each 60–90 min long over the course of 4 weeks. They met MWF of Week 1, M of Week 2, MWF of Week 3, and WF of Week 4.

  6. This change was made to reduce the number of outcomes, as PyCharm did not easily display all the outcomes in the original problem.

  7. There is another useful interpretation of the quotient n!/(n-r)!, in which we consider arranging all n objects of the set. But, since we only care about the first r positions, for each arrangement of the first r positions, the arrangements of the remaining n-r positions all actually constitute equivalent outcomes (hence the division by (n-r)!). However, this interpretation is not relevant to this paper and we do not elaborate on it further.

  8. Observe that another common counting formula, n!, is a special case of these r-permutations. P(n,n) = n! which is the number of arrangements of an entire set of n distinct objects.

  9. Including j > i also subsumes the case in which j might be equal to i. Thus, we do not need to include both j != i and j > i, as the j > i includes these cases. Further including k > j this also accounts for k being greater than i, so it is not necessary to also include a command in which k > i as well. Including additional constraints like k > i or j != i would not be incorrect, but they are not necessary.

  10. In addition, the mathematical solution they developed was not generated completely independently of any computational work. It emerged in a setting in which they had been working with the computer for multiple hours, and even if they did not directly draw on the computer in deriving this solution, we contend that both computational and noncomputational ideas and representations all contributed to a particular milieu in which the students were working.

  11. As we have noted, there have been no studies that examine students’ reasoning about selection with repetition problems. We did not include such problems in our study because we were limited in scope of topics we could cover, and we made this mathematical connection to code after we had gathered our data.

  12. In Python, the = sign is used to define a value rather than the familiar usage in mathematics, so Counter = Counter +1 is defining the new value of counter as one greater than the previous value of Counter.

References

  • Annin, S. A., & Lai, K. S. (2010). Common errors in counting problems. Mathematics Teacher, 103(6), 402–409.

    Google Scholar 

  • Auerbach, C., & Silverstein, L. B. (2003). Qualitative data: An introduction to coding and analysis. New York: New York University Press.

    Google Scholar 

  • Batanero, C., Navarro-Pelayo, V., & Godino, J. (1997). Effect of the implicit combinatorial model on combinatorial reasoning in secondary school pupils. Educational Studies in Mathematics, 32(2), 181–199.

  • Buteau, C., & Muller, E. (2017). Assessment in undergraduate programming-based mathematics courses. Digital Experiences in Mathematics Education, 3, 97–114. https://doi.org/10.1007/s40751-016-0026-4.

    Article  Google Scholar 

  • CadwalladerOlsker, T., Engelke, N., Annin, S., & Henning, A. (2012). Does a statement of whether order matters in counting problems affect students’ strategies? In the Electronic Proceedings of the 15th Annual Meeting of the Research on Undergraduate Mathematics Education. Portland, OR: Portland State University.

  • DeJarnette, A. F. (2019). Students’ challenges with symbols and diagrams when using a programming environment in mathematics. Digital Experiences in Mathematics Education, 5, 36–58. https://doi.org/10.1007/s40751-018-0044-5.

    Article  Google Scholar 

  • DiSessa, A. A. (2018). Computational literacy and “the big picture” concerning computers in mathematics education. Mathematical Thinking and Learning, 20(1), 3–31. https://doi.org/10.1080/10986065.2018.1403544.

    Article  Google Scholar 

  • English, L. D. (1991). Young children's combinatoric strategies. Educational Studies in Mathematics, 22(5), 451–474.

  • Fenton, W., & Dubinsky, E. (1996). Introduction to discrete mathematics with ISETL. New York: Springer-Verlag.

    Google Scholar 

  • Fischbein, E. (1975). The intuitive sources of probabilistic thinking in children. Dordrecht: Reidel.

    Google Scholar 

  • Fischbein, E., & Gazit, A. (1988). The combinatorial solving capacity in children and adolescents. ZDM, 5, 193–198.

    Google Scholar 

  • Fischbein, E., Pampu, I., & Manzat, I. (1970). Effects of age and instruction on combinatory ability in children. British Journal of Educational Psychology, 40, 261–270.

    Google Scholar 

  • Gadanidis, G., Clements, E., & Yiu, C. (2018). Group theory, computational thinking, and young mathematicians. Mathematical Thinking and Learning, 20(1), 32–53. https://doi.org/10.1080/10986065.2018.1403542.

    Article  Google Scholar 

  • Harel, I., & Papert, S. (Eds.). (1991). Constructionism. Westport: Ablex Publishing.

    Google Scholar 

  • Hickmott, D., Prieto-Rodriguez, E., & Holmes, K. (2018). A scoping review of studies on computational thinking in K-12 mathematics classrooms. Digital Experiences in Mathematics Education, 4(1), 48–69. https://doi.org/10.1007/s4075-017-0038-8.

  • JetBrains (2017). PyCharm. [online] JetBrains. Available at: https://www.jetbrains.com/pycharm. Accessed 24 Sept 2019

  • Joint Task Force for Computing Curricula (2005). Computing Curricula 2005: The overview report. Retrieved from https://www.acm.org/binaries/content/assets/education/curricula-recommendations/cc2005-march06final.pdf. Accessed 24 Sept 2019

  • Kotsopoulos, D., Floyd, L., Khan, S., Kizito Namukasa, I., Somanath, S., Weber, J., & Yiu, C. (2017). A pedagogical framework for computational thinking. Digital Experiences in Mathematics Education, 3(2), 154–171. https://doi.org/10.1007/s40751-017-0031-2.

  • Lockwood, E. (2013). A model of students’ combinatorial thinking. Journal of Mathematical Behavior, 32(2), 251–265. https://doi.org/10.1016/j.jmathb.2013.02.008.

  • Lockwood, E. (2014a). A set-oriented perspective on solving counting problems. For the Learning of Mathematics, 34(2), 31–37.

    Google Scholar 

  • Lockwood, E. (2014b). Both answers make sense! Using the set of outcomes to reconcile differing answers in counting problems. Mathematics Teacher, 108(4), 296–301.

    Google Scholar 

  • Lockwood, E., & Erickson, S. (2017). Undergraduate students’ initial conceptions of factorials. International Journal of Mathematical Education in Science and Technology, 48(4), 499–519. https://doi.org/10.1080/0020739X.2016.1259517.

    Article  Google Scholar 

  • Lockwood, E., & Purdy, B. (2019). Two undergraduate students’ reinvention of the multiplication principle. Journal for Research in Mathematics Education, 50(3), 225–267.

    Google Scholar 

  • Lockwood, E., Swinyard, C. A., & Caughman, J. S. (2015). Patterns, sets of outcomes, and combinatorial justification: Two students’ reinvention of counting formulas. International Journal of Research in Undergraduate Mathematics Education, 1(1), 27–62. https://doi.org/10.1007/s40753-015-0001-2.

    Article  Google Scholar 

  • Lockwood, E., Reed, Z., & Caughman, J. S. (2017). An analysis of statements of the multiplication principle in combinatorics, discrete, and finite mathematics textbooks. International Journal of Research in Undergraduate Mathematics Education, 3(3), 381–416. https://doi.org/10.1007/s40753-016-0045-y.

    Article  Google Scholar 

  • Lockwood, E., Wasserman, N. H., & McGuffey, W. (2018). Classifying combinations: Do students distinguish between different categories of combination problems? International Journal of Research in Undergraduate Mathematics Education, 4(2), 305-322. https://doi.org/10.1007/s40753-018-0073-x.

  • Lockwood, E., DeJarnette, A. F., & Thomas, M. (2019). Computing as a mathematical disciplinary practice. Online first in Journal of Mathematical Behavior, 54. https://doi.org/10.1016/j.jmathb.2019.01.004.

  • Martin, G. E. (2001). The art of enumerative Combinatorics. New York: Springer.

    Google Scholar 

  • Mazur, D. R. (2010). Combinatorics: A guided tour. Washington, DC: MAA.

    Google Scholar 

  • Papert, S. (1980). Mindstorms: Children, computers, and powerful ideas. New York: Basic Books.

    Google Scholar 

  • Papert, S. (1993). The Children’s machine. New York: Basic Books.

    Google Scholar 

  • Piaget, J., & Inhelder, B. (1975). The origin of the idea of chance in children. New York: W. W. Norton & Company, Inc..

    Google Scholar 

  • Reed, Z., & Lockwood, E. (2018). Generalizing in combinatorics through categorization. In A. Weinberg, C. Rasmussen, J. Rabin, M. Wawro, & S. Brown (Eds.), Proceedings of the 21st annual conference on research in undergraduate mathematics education (pp. 311–325). San Diego: San Diego State University.

    Google Scholar 

  • Sinclair, N., & Patterson, M. (2018). The dynamic geometrisation of computer programming. Mathematical Thinking and Learning, 20(1), 54–74. https://doi.org/10.1080/10986065.2018.1403541.

    Article  Google Scholar 

  • Steffe, L. P., & Thompson, P. W. (2000). Teaching experiment methodology: Underlying principles and essential elements. In R. Lesh & A. E. Kelly (Eds.), Research design in mathematics and science education (pp. 267–307). Mahwah: Lawrence Erlbaum Associates.

    Google Scholar 

  • Tucker, A. (2002). Applied combinatorics (4th ed.). New York: Wiley.

    Google Scholar 

  • VERBI Software. (2017). MAXQDA 2018 [computer software]. Berlin: VERBI Software Available from https://www.maxqda.com. Accessed 24 Sept 2019

  • Weintrop, D., Beheshti, E., Horn, M., Orton, K., Jona, K., Trouille, L., & Wilensky, U. (2016). Defining computational thinking for mathematics and science classrooms. Journal of Science and Education Technology, 25, 127–147. https://doi.org/10.1007/s10956-015-0581-5.

    Article  Google Scholar 

Download references

Acknowledgements

This material is based upon work supported by the National Science Foundation under Grant No. 1650943.

Author information

Authors and Affiliations

Authors

Corresponding author

Correspondence to Elise Lockwood.

Ethics declarations

Conflict of Interest

On behalf of all authors, the corresponding author states that there is no conflict of interest.

Additional information

Publisher’s Note

Springer Nature remains neutral with regard to jurisdictional claims in published maps and institutional affiliations.

Appendices

Appendix 1

Here we provide a more detailed discussion of selection with repetition problems, which is a standard approach (e.g., Mazur 2010; Tucker 2002). The following question is an example of this type of problem (adapted from Tucker 2002, p. 195): “Suppose I have 6 types of hot dogs, and I want to buy three hot dogs for lunch. In how many ways could I do this?” One way to solve such a problem highlights a clever way to encode outcomes and make sense of the more general formula. If we consider an actual menu with 6 types of hot dogs and then consider placing xs on the menu to indicate which hot dogs we want to buy, we can end up with a menu like the one in Table 6. We listed out a few different possibilities in the first 6 rows of the menu.

Table 6 Representation of several outcomes of the Hot Dog problem

Notice that for each of the six rows in the menu, we could encode the outcomes as strings of three xs and five |s. For example, the entry in the first row, which represents three regular dogs, could be encoded as the string xxx | | | | |. The entry in the second row, which represents two regular dogs and a super dog, could be encoded as xx | x | | | |. The entry in the fifth row, which represents one super, one footlong, and one Dodger dog, is encoded as | x | x | | x |. In this way, counting the total number of outcomes is a matter of counting strings of length 8 that contain 3 xs and 5 bars. To count this, we can simply choose 3 of the 8 positions in which to place xs, and then the remaining positions must be bars (see Lockwood et al. 2018 for an extended discussion of interpreting such a situation as a combination problem). Thus, there are C(8,3) ways to buy 3 hot dogs from 6 types of hot dogs, where repetition is allowed. Note that more generally, if there are n types of objects, and we want to select r with repetition, there will be r xs and n – 1 bars (one fewer than the number of types). Thus the general formula to solve this kind of problem is C(n + r – 1,r).

An equivalent way to frame this question is to ask, “How many strictly non-decreasing sequences of length three are there from a set of 6 distinct elements?” Notice that these outcomes would be 111, 112, 113, 114, 115, 116, 122, 123, 124, 125, 126, 133, 134, 135, 136, 144, 145, 146, 155, 156, 166, 222, 223, 224, 225, 226, 233, 234, 235, 236, 244, 245, 246, 255, 256, 266, 333, 334, 335, 336, 344, 345, 346, 355, 356, 366, 444, 445, 446, 455, 456, 466, 555, 556, 566, 666. For any of these outcomes, though, they correspond to an arrangement of three xs and five bars, where the numbers in the 3-element sets represent in which categories the xs go. For example, 111 corresponds to xxx | | | | |, 223 corresponds to | x x | x | | |, and 366 corresponds to | | x | | | x x. This perspective of encoding outcomes offers another way to count these problems. If we think about code like that in Table 2, then, we can see how the greater than or equal to symbols in the conditional if statements exactly correspond to this question of counting strictly non-decreasing sequences. This code generates exactly the set of outcomes we listed above (in the same order).

Fig. 24
figure 24

Code that counts selection with repetition problems

Appendix 2

Here, we provide a more thorough discussion of the code presented in the lower left corner of the two-by-two table (Tucker 2002), and in particular in Table 2 of the body of the paper. That is, we will explain why the code in Fig. 25 counts arrangements with no repetition. This is intended to provide clarity for readers who are unfamiliar with programming or who are unfamiliar with Python syntax. The other programs used in this paper rely on the same concepts, although there may be more for loops and different additional conditional statements. In explaining the code, we will introduce for loops and conditional statements, which are important in framing the students’ work. For clarity, we have labeled the line numbers in the code.

Fig. 25
figure 25

Code that counts arrangements with unrestricted repetition

The code begins by defining an ordered list, “Numbers = [1,2,3,4,5].” The list contains the integers 1, 2, 3, 4, and 5, and is ordered as written. The command in line (2), “Counter = 0,” creates a new integer variable, called Counter, that we will use to count the number of outcomes our code produces. Each time we produce a new outcome, we will increase the value of Counter by 1 (this occurs in Line (7)). Line (3) begins a for loop. The command “for i in Numbers:” will do a series of commands for each element in the set Numbers. In Python, indentation is an important element of specifying commands, and it helps to determine whether commands are nested. The series of commands is relayed in the instructions nested within the for loop, where instructions are considered nested within a loop while they are indented further (to the right) than the loop. The nesting ends when the program reaches a line that is not indented further to the right. In this case, lines (4) through (7) are nested within the for loop, and will be carried out for each i in Numbers, whereas line (8) is not nested within the for loops. Hence, the command “for i in Numbers:” will carry out the nested commands five times, once per element in Numbers in the order in which they appear (in this case, the numerical order 1, 2, 3, 4, and 5).

For each i in Numbers, the nested instructions will be carried out with i designated as a given value. For example, the first time lines (4) through (7) are carried out will be when the value of i is 1. Similarly, the command “for j in Numbers:” will carry out the instructions nested within it (lines (5) through (7)) for each value of j in Numbers. That is, lines (5) through (7) are carried out a total of 25 times (one time for each ordered pair (i,j), where both i and j are elements of Numbers).

For each value of i in Numbers and j in Numbers, the program will follow the command “if j != i:,” which we refer to as a conditional statement. That is, as long as the condition j != i is met, the program will follow the instructions nested within the conditional statement (lines (6) and (7)). If the condition is not met, then the program will skip over these instructions (in this case, as the remaining instructions are nested inside, the program will do nothing). Lines (6) and (7) accomplish two things: first, the ordered pair (i, j) is printed; and second, the value of Counter is increased by 1.Footnote 12 Hence, the program will follow the instructions to print (i,j) and to increment the counter for only those pairs (i, j) where j is not equal to i.

In sum, for each value in Numbers, the program will iterate through every value in Numbers, printing each pair of distinct numbers as well as keeping track of the total number of pairs that has been printed. Due to the conditional statement, these pairs are precisely those without repetition, showing we are counting and listing the desired outcomes. Line (8), “print(Counter),” prints the value of Counter after all previous instructions have been followed, giving the total number of arrangements of the numbers 1 through 5, where repetition is not allowed.

Rights and permissions

Reprints and permissions

About this article

Check for updates. Verify currency and authenticity via CrossMark

Cite this article

Lockwood, E., De Chenne, A. Enriching Students’ Combinatorial Reasoning through the Use of Loops and Conditional Statements in Python. Int. J. Res. Undergrad. Math. Ed. 6, 303–346 (2020). https://doi.org/10.1007/s40753-019-00108-2

Download citation

  • Published:

  • Issue Date:

  • DOI: https://doi.org/10.1007/s40753-019-00108-2

Keywords

Navigation