A Thimble, Fourteen Stitches, and Division
The first fitting of my sashiko palm thimble left me with a small circle of layered fabric and a question: how many stitches would keep the layers together without leaving a gap wider than 10 mm? My stitching line measured 137 mm around.
Fourteen, it turns out. Thirteen equal gaps would each be more than 10 mm; fourteen bring them down to about 9.8 mm. On a closed loop, fourteen stitches make fourteen gaps, including the one between the last stitch and the first.
That little calculation is ceiling division: divide, then round up if there is a remainder. Integer division has been part of programming since the early days of stored-program computers, when getting useful answers from whole-number arithmetic was an everyday concern.
fun ceilDiv(n: Int, d: Int): Int {
val quotient = n / d
return quotient + if (n % d == 0) 0 else 1
}
fun main() = println(ceilDiv(137, 10))
Kotlin gives the quotient and remainder separate expressions. Forth’s /mod supplies both at once, leaving the quotient on top of the remainder. The remaining words turn a non-zero remainder into one extra stitch.
: ceil/ ( n d -- quotient )
/mod swap
0<> negate +
;
137 10 ceil/ . cr
Both programs print 14. They assume a non-negative length and a positive maximum spacing. Keeping the quotient and remainder separate also avoids the common shortcut of adding the divisor before dividing, which can overflow for large integers.
The number is a guide, not a substitute for handling the fabric. I would mark the positions, check that the thimble still fits comfortably across my palm, and adjust for the thickness at the overlap. Once it is stitched, the padded face gives the needle somewhere firm to rest as my palm pushes it through a longer run of cloth.