6 kyu

Almost Even

1,705 of 4,021OverZealous

Description:

We need the ability to divide an unknown integer into a given number of even parts - or at least as even as they can be. The sum of the parts should be the original value, but each part should be an integer, and they should be as close as possible.

Complete the function so that it returns an array of integers representing the parts. If the input number is too small to split it into requested amount of parts, the additional parts should have value 0. Ignoring the order of the parts, there is only one valid solution for each input to your function!

Example:

20 split into 6 parts should return [3, 3, 3, 3, 4, 4], in any order.
split_integer(20, 6, *parts)  // fills parts with 3, 3, 3, 3, 4, 4
split_integer(20, 6)  # returns [3, 3, 3, 3, 4, 4]
splitInteger(20, 6)   # returns [3, 3, 3, 3, 4, 4]
splitInteger(20, 6)  // returns [3, 3, 3, 3, 4, 4]
splitInteger 20 6    -- returns [3, 3, 3, 3, 4, 4]
splitInteger(20, 6)  // returns Seq(3, 3, 3, 3, 4, 4)

Inputs

The input to your function will always be valid for this kata.

Arrays
Algorithms

Stats:

CreatedDec 3, 2013
PublishedDec 3, 2013
Warriors Trained7390
Total Skips307
Total Code Submissions14572
Total Times Completed4021
JavaScript Completions1705
CoffeeScript Completions61
Haskell Completions327
Ruby Completions188
Python Completions1455
Scala Completions13
C++ Completions136
PHP Completions53
Crystal Completions10
Julia Completions9
C Completions224
Total Stars103
% of votes with a positive feedback rating92% of 590
Total "Very Satisfied" Votes507
Total "Somewhat Satisfied" Votes76
Total "Not Satisfied" Votes7
Ad
Contributors
  • OverZealous Avatar
  • jhoffner Avatar
  • xcthulhu Avatar
  • Ivan Diachenko Avatar
  • GiacomoSorbi Avatar
  • anter69 Avatar
  • JohanWiltink Avatar
  • rowcased Avatar
  • hobovsky Avatar
  • solitude Avatar
  • WestwardLand968 Avatar
  • XoRMiAS Avatar
  • KayleighWasTaken Avatar
  • saudiGuy Avatar
Ad