<?php</li>/** * Description of algorithm: * The algorithm prints the number of pages, based on three constants: * 1. The number of items(total) * 2. The desired number of elements on the page * 3. The maximum number of additions(the situation when on the last page 1-2 item) */define('RESULTS_COUNT', 12349);define('RESULTS_PER_PAGE', 17);define('MAX_ADDITIONS', 7); $results_per_page = RESULTS_PER_PAGE>0?RESULTS_PER_PAGE:1; // additional check for division by zero if(RESULTS_COUNT<$results_per_page || RESULTS_COUNT==$results_per_page){ exit('page 1 for '.RESULTS_COUNT.' results.');} $exact_pages_count = RESULTS_COUNT / $results_per_page;if (is_int($exact_pages_count)) { exit($exact_pages_count.' pages for '.RESULTS_COUNT.' results.');}else { $rough_estimate_pages = intval($exact_pages_count); $number_of_surplus=RESULTS_COUNT-($results_per_page*$rough_estimate_pages); $pages_of_surplus=$number_of_surplus<=MAX_ADDITIONS?$rough_estimate_pages:$rough_estimate_pages++; exit($rough_estimate_pages.' pages for '.RESULTS_COUNT.' results.');}?>* This source code was highlighted with Source Code Highlighter.

if(RESULTS_COUNT<$results_per_page || RESULTS_COUNT==$results_per_page)

public static IDictionary DivideItems(IEnumerable sourceItems, int itemsAtPage){var result = new Dictionary();var array = sourceItems.ToArray();var j = 0;var pageNumber = 1;while (j < array.Length){var ar = new T[Math.Min(itemsAtPage, array.Length - j)];for (var i = 0; i < ar.Length; i++)ar[i] = array[j + i];j += ar.Length;result.Add(pageNumber, ar);pageNumber++;}return result;}\r\rThis is a Generic method, T is any type. The function takes a collection of objects and maximum number of objects on the page. Returns a pair <[page number] : [collection of page objects]>\rLike, not exactly shows generalized types, so just in case the screenshot:\r

not exactly shows generalized types, so just in case the screenshot:\r