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) index
You can run the program at https://ideone.com/38BHgj.
I presume that should be: “counts 10 on her index finger, 11 on her middle finger, and so on”
Correct. Fixed. Thank you.
Here is my take on Julia: https://pastebin.com/NLWPwL5C
Cool drill for getting acquainted with modulo arithmetic. Cheers!
My thorouhly documented solution implemented in SML can be found at <ahref=”https://pastebin.com/HQ5WkqKx”>. It takes a different approach from modular arithmetic.
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);
}
System.out.println(solution.getCounter_iterations());
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”);
}
}
Using Spanish abbreviations for finger names (Haskell):
finger n = ['i', 'p', 'i', 'm', 'a', 'c', 'a', 'm'] !! (n
mod8)
Here’s Clojure solution with infinity lazy sequence of fingers :)
Here’s a solution in C.
Usage:
I took a very different approach from you all– my original thought was to just use x%8, but I decided to instead use the absolute value of a triangle wave. At least I thought it was neat.
Here’s a Python solution inspired by @Antonio’s solution, adapted to use integers in place of floating point.
Output:
In my approach, I took advantage of array pointers in PHP. Every time the pointer reaches an outer finger (thumb/pinky), the array elements are reversed in order. You simply scroll down to see the finger that is declared at count number 1000.