Counting Fingers

June 16, 2020

The little girl will be on her thumb on 1, 9, 17, and every 8k+1, whereupon the pattern repeats itself:

(define (finger n)
  (case (modulo n 8)
    ((1  ) 'thumb)
    ((2 0) 'index)
    ((3 7) 'middle)
    ((4 6) 'ring)
    ((5  ) 'pinkie)))

She will be on her index finger when she reaches a thousand:

> (finger 1000)


You can run the program at

Pages: 1 2

10 Responses to “Counting Fingers”

  1. matthew said

    I presume that should be: “counts 10 on her index finger, 11 on her middle finger, and so on”

  2. programmingpraxis said

    Correct. Fixed. Thank you.

  3. Zack said

    Here is my take on Julia:

    Cool drill for getting acquainted with modulo arithmetic. Cheers!

  4. Mark said
  5. Jan Van lent said
    f = lambda n: 4-abs(4-(n-1)%8)
    print("timrp"[f(1000)]) # see Mark's solution
  6. Xero said

    My thorouhly documented solution implemented in SML can be found at <ahref=””>. It takes a different approach from modular arithmetic.

  7. Maksym Fedenko said

    Hi, I’m beginner, can I resolve task in this way?

    public class Exercises1 {
    public static void main(String[] args) {
    Solution solution = new Solution();
    while (solution.getCounter_fingers() < 1006586890){
    solution.setCounter_fingers(solution.getCounter_fingers() + 4);
    solution.setCounter_iterations(solution.getCounter_iterations() + 1);
    solution.setCounter_fingers(solution.getCounter_fingers() – 1);
    if(solution.getCounter_iterations() % 2 == 0){
    System.out.println(“Girl stop count on index finger”);
    }else {
    System.out.println(“Girl stop count on ring finger”);

    public static class Solution {
        private int counter_fingers = 5;
        private int counter_iterations = 1;
        public int getCounter_fingers() {
            return counter_fingers;
        public void setCounter_fingers(int counter_fingers){
            this.counter_fingers = counter_fingers;
        public int getCounter_iterations() {
            return counter_iterations;
        public void setCounter_iterations(int counter_iterations) {
            this.counter_iterations = counter_iterations;
  8. Larry Lee said

    Using Spanish abbreviations for finger names (Haskell): finger n = ['i', 'p', 'i', 'm', 'a', 'c', 'a', 'm'] !! (nmod8)

  9. Here’s Clojure solution with infinity lazy sequence of fingers :)

    (defn counting-fingers [n]
      (let [fingers (cycle [:thumb :index :middle :ring
                            :pinky :ring :middle :index])]
        (first (drop (dec n) fingers))))
  10. (defn counting-fingers [n]
      ([:thumb :index :middle :ring
        :pinky :ring :middle :index] (mod (dec n) 8)))

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: