The goal of this challenge is to complete a list of consecutive nested header numbers when given a start and an end. When given 1.1.1 and 1.1.5 you should generate 1.1.1, 1.1.2, 1.1.3, 1.1.4, 1.1.5

Specific Rules

  1. Your entry must take in a start, end, and multiple optional range parameters. Parameters can be taken form STDIN (or nearest equivalent) or a file.
  2. Your entry may assume valid input
  3. Input will be of the following format:
    1. start and end will be strings of . delimited integers of the same length
    2. start and end will have three segments; (1) set values, (2) iterator, (3) trailing values.
      • The iterator is the first value which differs between start and end.
      • The set values are the values before the iterator. These values never change
      • The trailing values are the values after the iterator. These values iterate up as determined by the range parameter(s). All trailing values in start and end will be 1.
    3. range will be a list of integers or strings (depending on which you prefer) with a length corresponding to the number of trailing values. When there are no trailing values, range is not specified. The value of range corresponding to each trailing value determines the inclusive upper bound which that entry iterates to.
  4. Output will be to STDOUT (or closest alternative) and will show each value separated by at least one delimiter. Delimiter can by any character or string of characters, but it must be consistent. Output must be sorted correctly


start = '', end = '', range = [5]
                                                  previous value is iterated
                                                  only when iterating value
                                                  limit set by range

start = '', end = '', range = [5]

start = '', end = '', range = [5,2]

This is code golf so shortest code by bytes wins. Standard loopholes apply.


  1. Allow trailing values to be values other than 1 in end parameter - 12.5% off
  2. Handle incorrect number of values in range parameter - 12.5% off
  3. Handle end less than start by producing list in reverse - 50% off

Bonuses are calculated off of the original byte count; a 100 byte answer which receives all bonuses will have a final score of 100 bytes - 100*(0.125+0.125+0.5) = 25 bytes

  • \$\begingroup\$ @nimi, edited to answer both questions in your second comment. \$\endgroup\$
    – wnnmaw
    Jan 14, 2016 at 21:21
  • \$\begingroup\$ @nimi, For bonus 3, yes that is the correct understanding \$\endgroup\$
    – wnnmaw
    Jan 14, 2016 at 21:22
  • \$\begingroup\$ why does the second test case repeat \$\endgroup\$
    – Maltysen
    Jan 14, 2016 at 23:15
  • 1
    \$\begingroup\$ You say the set values never change - are they always 1's? Are all the numbers in start and end single digits, or could to happen? \$\endgroup\$ Jan 15, 2016 at 7:17
  • \$\begingroup\$ @Maltysen, because I missed that, its just a typo, disregard \$\endgroup\$
    – wnnmaw
    Jan 15, 2016 at 14:33

2 Answers 2


Haskell, 201 194 188*0.25 = 47 bytes

import Data.Lists
p x=read<$>splitOn"."x
(s#e)r=intercalate".".map show<$>(fst$span(<=e)$sequence$zipWith enumFromTo s$take(l e-l r)e++r)

I'm going for all bonuses.

"Normal" use:

*Main> ((.p).(!).p) "" "" [5,2]

Bonus 1:

*Main> ((.p).(!).p) "" "" [5,2]

Bonus 2:

*Main> ((.p).(!).p) "" "" [3]

Bonus 3:

*Main> ((.p).(!).p) "" "" [5,2] 

How it works:

Split start and end into lists of numbers, e.g. "" -> [1,5,1,1]. Prepend elements from end to range so that the resulting list has the same length as end, e.g. [5,2] and "" -> [1,6,5,2]. Zip this list and start with the list building function enumFromTo, e.g. [1,5,1,1] and [1,6,5,2]-> [[1],[5,6],[1,2,3,4,5],[1,2]]. sequence builds all combinations thereof, where numbers at position i are drawn from sublist i, -> [[1,5,1,1],[1,5,1,2],[1,5,2,1],[1,5,2,2],...]. Re-insert the dots and take elements as long as the they are less or equal than end.


PowerShell, 214 bytes, no bonuses :(

$f={param($v,$w)if($w){$w[0]|%{&$f "$v.$_" $w[1..$w.Count]}}else{$v;if($v-eq$e){break}}}
$x,$y=($s-split'\.'|diff $e.split('.')).inputobject
&$f ($s-split".$x")[0] $q


PS C:\Scripts> .\nestedh.ps1 '' '' @(5,2)


  • Uses -split '\.' feeding to diff/Compare-Object to find the two differing numbers, (this approach blocks the bonus where the tail values can change, because it changes the diff output).
  • Builds an array of the ranges it will need for each header position, taking from the range parameters.This leaves something like "$q=[[5,6], [1,2,3,4,5], [1,2]]"
  • Those get fed into the recursive function $f which takes the set values prefix and a list of sublists, adds the prefix to each number, and calls itself with that as the new prefix, and the remaining sublists
  • quits when it hits the $end string

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.