Sizing K-Fold Splits
Halewood Analytics is about to grade a model by cross-validation. The rows are dealt out into k groups, called folds. The model is then fitted k times, each run holding one whole fold back as the unseen part and learning from the rest. Before any of that starts, the planning screen shows how large each fold will be, because row counts rarely divide evenly and the desk wants to see where the leftovers land.
Task: Print the size of every fold.
Input
One line holding two integers separated by a single space: n, the number of rows, then k, the number of folds, with k <= n.
Output
k lines, one per fold, in fold order. Each line reads fold i: size — the word fold, the fold's number counting from 1, a colon, a space, then the size. Every row lands in exactly one fold, no two folds differ in size by more than one row, and any leftover rows go to the earliest folds, one row each.
Example:
Input:
10 3
Output:
fold 1: 4
fold 2: 3
fold 3: 3
Sign in to solve this problem
Reading problems is free for everyone — solving them (Run, Submit, and tracking what you've solved) needs an account.
Sign in