Problem of the Day
A new programming or logic puzzle every Mon-Fri

Line Length

So great to see an awesome turn out for problem 100 yesterday! For today's problem your goal is to write a program that takes in two strings and a line length. The program should then output a string with enough spaces between the words so that the total number of characters matches the line length. If the two strings combined add up to larger than the line length throw an error.

Permalink: http://problemotd.com/problem/line-length/

Comments:

  • Derek - 10 years, 5 months ago

    Ruby

    s1, s2, len = ARGV[0..2]
    len = len.to_i
    spaces = len - (s1.length + s2.length)
    raise "Strings too long" if spaces < 0
    puts s1 + (" " * spaces) + s2
    

    reply permalink

  • Nick Krichevsky - 10 years, 5 months ago

    Python

    def l(string1,string2, length):
        if (len(string1)+len(string2)>length):
            raise ValueError
        print string1+(" "*(length-(len(string1)+len(string2))))+string2
    

    reply permalink

Content curated by @MaxBurstein