From: "Cédric Finance" Date: 2007-11-08T06:34:59+09:00 Subject: Re: a problem related string(250 score) ------=_Part_2803_7565678.1194471298662 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit Content-Disposition: inline You may be right. I took it like a quizz and answered very fast. On Nov 7, 2007 4:51 PM, Phrogz wrote: > On Nov 7, 8:12 am, Johnson Wang <99...@163.com> wrote: > > How to solve this problem in Ruby???? > > ============================================== > > You are given a String disk representing the clusters on a disk. An 'X' > > represents a used cluster, and a '.' represents an available cluster. > > You are also given an int size representing the size, in clusters, of a > > file waiting to be written to disk. A file can only be stored in > > clusters not already being used. > > Return the minimum number of groups of consecutive clusters needed to > > store the file on the disk. (The disk does not wrap around at the end.) > > Return -1 if the disk does not have enough space available to store the > > file. > > Definition > > This smells like a homework problem, so roughly: > Scan the string for groups of consecutive clusters. > Sort the clusters by length. > Iterate through the sorted group adding up the sizes and incrementing > a counter until you reach or exceed your goal. > > > ------=_Part_2803_7565678.1194471298662--