Period of the decimal representation Write a function which takes a single positive integer n and returns the period of the decimal representation of 1/n.

Test cases:

1 -&gt; 1               # 1/1 = 1.0000...... = 1._0
2 -&gt; 1               # 1/2 = 0.5000...... = 0.5_0
3 -&gt; 1               # 1/3 = 0.3333...... = 0._3
7 -&gt; 6               # 1/7 = 0.14285714.. = 0._142857
13 -&gt; 6
14 -&gt; 6
123 -&gt; 5
345 -&gt; 22
654 -&gt; 108
12345 -&gt; 822
67890 -&gt; 120


This is code-golf. Built-ins or libraries which return the period directly are not permitted. Numbers up to at least 100000 should work within reasonable time (at most several minutes).
APL, 19 chars/bytes*

{(↑⍳⍨1∘↓)⌽⍵|10x*⍳⍵}


Nars2000. The previous version was wrong on some numbers, this should be right. I manually checked it on all numbers up to 50.

Again, credit goes to Ben Reich for the idea of looking at the period of 10^i (mod x)

Exploded view

{                     ⍳⍵}   generate all naturals up to the argument ⍵
                 10x*       raise 10 to each of them, with unlimited precision
              ⍵|            compute the respective remainders mod ⍵
            ⌽               reverse the list
 (  ⍳⍨    )                 (fork) find the position of the first occurrence
  ↑                         of the fist element of the list
       1∘↓                  in the remainder of the list


Examples

      {(↑⍳⍨1∘↓)⌽⍵|10x*⍳⍵}¨1 2 3 7 13 14 123 345 654 12345 67890
1 1 1 6 6 6 5 22 108 822 120


⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯
*: APL can be written in its own (legacy) single-byte charset that maps APL symbols to the upper 128 byte values. Therefore, for the purpose of scoring, a program of N chars that only uses ASCII characters and APL symbols can be considered to be N bytes long.