श्रेणियों में coalescing / तिथियों की सूची गिर के लिए पुनरावर्ती एल्गोरिदम

वोट
1

तिथियों की सूची को देखते हुए

12/07/2010
13/07/2010
14/07/2010
15/07/2010
12/08/2010
13/08/2010
14/08/2010
15/08/2010
19/08/2010
20/08/2010
21/08/2010

मैं एक पुनरावर्ती स्यूडोकोड एल्गोरिथ्म की ओर संकेत श्रेणियों की सूची तैयार करने के लिए (जो मैं एक FileMaker कस्टम समारोह में अनुवाद कर सकते हैं), अर्थात् के लिए देख रहा हूँ

12/07/2010 to 15/07/2010, 12/08/2010 to 15/08/2010, 19/08/2010 to 20/08/2010

सूची presorted जाता है और डी-डुप्लीकेट। मैं पहली बार मूल्य दोनों और काम आगे, और अंतिम मान से शुरू और पीछे की ओर काम कर की कोशिश की है, लेकिन मैं सिर्फ यह काम करने के लिए प्राप्त करने के लिए नहीं कर पा रहे। उन निराशा दिनों में से एक होने ... यह अच्छा होगा अगर हस्ताक्षर की तरह कुछ था

CollapseDateList( dateList, separator, ellipsis )

:-)

18/05/2010 को 13:58
का स्रोत उपयोगकर्ता
अन्य भाषाओं में...                            


2 जवाब

वोट
1

मुख्य दिनचर्या कुछ इस तरह दिखेगा:

List<String> list  = new ArrayList<String>();

String firstDate   = dateList[0];
String lastDate    = dateList[0];
String currentDate = dateList[0];

for (int i = 1; i < dateList.length(); i++) {
    if (dateDiff(dateList[i], currentDate) == 1) {
        lastDate   = dateList[i];
    } else {
        list.add(firstDate + separator + lastDate);
        firstDate = dateList[i];
        lastDate  = dateList[i];
    }
    currentDate = dateList[i];
}
list.add(firstDate + separator + lastDate);

मैं आपको कुछ समारोह है कि आपको बताता है कि दो तिथियों के लगातार या नहीं हैं यह सोचते हैं रहा हूँ।

18/05/2010 को 15:09
का स्रोत उपयोगकर्ता

वोट
1

यहाँ पुनरावर्ती FileMaker कोड है कि काम करता है। बुनियादी दृष्टिकोण जहां आवश्यक अंतिम तिथि (दाएं सबसे शब्द) एक मूल्य के भीतर से तारीख की गणना, जगह में प्रतिस्थापन करना है। यही कारण है कि जिस तरह से यह करता है, तो अगले मूल्य अभी भी पहले की रेंज का हिस्सा है जब जांच करें, या के रूप में किया पहले सीमा को चिह्नित और शेष मान पर ध्यान केंद्रित करने का फैसला कर सकते हैं। आशा है कि यह किसी और में मदद करता है।

// CollapseDateList( dates, comma, dash)

Let(
  countDates = ValueCount ( dates );

  If (
    countDates < 2 ; dates;  // return the dates we've been given...

    Let(
      [ 
        start_date = GetAsDate( LeftWords( GetValue ( dates ; 1 ); 1 ) );
        date_1 = GetAsDate( RightWords( GetValue ( dates ; 1 ); 1 ) );
        date_2 = GetAsDate( GetValue ( dates ; 2 ) );
        date_3 = GetAsDate( GetValue ( dates ; 3 ) );
        dv_1 = GetAsNumber( date_1 );
        dv_2 = GetAsNumber( date_2 );
        dv_3 = GetAsNumber( date_3 );
        twoFollowsOne = (dv_2 = dv_1 + 1);
        threeFollowsTwo = (dv_3 = dv_2 + 1)
      ];

       // compare dates
      Case(
        // only two dates in list
        countDates = 2;
          if (
            twoFollowsOne;
            start_date & dash & date_2;
            GetValue ( dates ; 1 ) & comma & date_2
          );

        // first three values are sequential
        threeFollowsTwo and twoFollowsOne; 
          CollapseDateList( start_date & dash & date_3 & ¶ & RightValues( dates; countDates - 3 ); comma; dash );

        // first two values are sequential only
        not threeFollowsTwo and twoFollowsOne; 
          start_date & dash & date_2 & comma & CollapseDateList(  RightValues(  dates; countDates - 2 ); comma; dash );

        // first two values are not sequential 
        // default
        GetValue ( dates ; 1 ) & comma & CollapseDateList( RightValues( dates; countDates - 1 ); comma; dash )
      ) 
    )
  )
)
18/05/2010 को 16:26
का स्रोत उपयोगकर्ता

Cookies help us deliver our services. By using our services, you agree to our use of cookies. Learn more