6
\$\begingroup\$

A set of whole numbers (0-) will be given separated by a space. Some numbers will be missing between certain numbers in the set. Your job is to find the missing odd numbers between them.

Conditions

  1. The input will be a one line string.
  2. Your code must left out a variable for inserting the input case string.
  3. The output should be a string containing all the missing odd numbers in the set of numbers given as input.
  4. The numbers of the output must be separated by a comma - ,.
  5. No extra characters should be included in the output.
  6. If there are no odd numbers missing, the code should print out null or a blank line.

Here are some sample inputs and outputs according to its order :

Input

4 6 8 10
5 15 18 21 26
2 15 6
1 20
1 3 5 7 9

Output

5,7,9
7,9,11,13,17,19,23,25
3,5,7,9,11,13
3,5,7,9,11,13,15,17,19
null

The winner will be decided by the Code length.

The calculation of code length won't include the variable that is left for the test case.

\$\endgroup\$
  • 7
    \$\begingroup\$ Seems awfully unfair to state that you'll be awarding the win to PHP, even if it's longer than the shortest not-PHP solution. \$\endgroup\$ – Kyle Kanos May 30 '14 at 14:31
  • 3
    \$\begingroup\$ Removed arbitrary language requirement; challenges here are generally language-agnostic unless a very good reason exists to limit or otherwise suppress other languages. \$\endgroup\$ – Doorknob May 30 '14 at 14:35
  • 7
    \$\begingroup\$ Again, why must your answer be in PHP? This is beginning to sound like a homework problem.... \$\endgroup\$ – Kyle Kanos May 30 '14 at 14:37
  • 3
    \$\begingroup\$ "Your code must left out a variable for inserting the input case string." — I don't understand what this means. \$\endgroup\$ – squeamish ossifrage May 30 '14 at 14:45
  • 3
    \$\begingroup\$ @James Even if the numbers in the set are out of order like 5 9 3, the code should find the missing odd numbers. The conditions never said that the numbers given will be in order. \$\endgroup\$ – Subin May 31 '14 at 4:32

33 Answers 33

3
\$\begingroup\$

GolfScript (20 chars)

~]$),\(),+-{1&},','*

Online demo

Dissection:

~]$   # Eval the string, wrap the resulting integers in an array, sort
),    # Extract the max and make an array A of 0 to max-1 inclusive
\(),  # Extract the min and make an array B of 0 to min inclusive
+-    # Combine B with the remaining numbers from the input and remove them from A
{1&}, # Filter A to odd numbers
','*  # Comma-separate
\$\endgroup\$
10
\$\begingroup\$

Ruby, 74

s="insert your numbers here" # this line not counted per the rules
n=s.split.map &:to_i
puts (n.min..n.max).select{|x|x%2==1&&!n.index(x)}*?,

Output is identical to examples in question except that it outputs a blank line for no numbers found.

\$\endgroup\$
  • \$\begingroup\$ The output must be a string (not array) of missing odd numbers separated by comma ,. No extra chars like [ are allowed. \$\endgroup\$ – Subin May 30 '14 at 15:00
  • 3
    \$\begingroup\$ @Subin Ok, fixed. (You can't really output anything that's not a string, though; I'm having trouble understanding what that rule means.) \$\endgroup\$ – Doorknob May 30 '14 at 15:01
3
\$\begingroup\$

Python, 82 chars

N=map(int,I.split())
R=','.join(`x`for x in range(min(N)|1,max(N),2)if x not in N)

Set I to your input string, R is the output string.

\$\endgroup\$
  • \$\begingroup\$ +1 for min(N)|1 finding first odd number in range \$\endgroup\$ – avall May 30 '14 at 21:52
  • \$\begingroup\$ You can still improve the character count. As the question doesn't require the arguments to be in order you could do ','.join(`x`for x in set(range(min(N)|1,max(N),2))-set(N)) \$\endgroup\$ – WorldSEnder Jun 4 '14 at 17:39
3
\$\begingroup\$

Groovy, 92 79 72 chars

x=args; //Input does not count
x=x*.toInteger();print((x.min()..x.max()).minus(x).grep{it%2}.join(","))
\$\endgroup\$
2
\$\begingroup\$

C#, 205 characters: 222 (total count) - 17 (total length of variable)

namespace System.Linq{class A{static void Main(){var a="4 6 8 10";var b=a.Split(' ').Select(int.Parse);Console.WriteLine(String.Join<int>(",",Enumerable.Range(b.Min(),b.Max()-b.Min()).Where(x=>x%2==1&&!b.Contains(x))));}}}

Ungolfed code:

namespace System.Linq
{
    class A
    {
        static void Main()
        {
            var a = "4 6 8 10";
            var b = a.Split(' ').Select(int.Parse);
            Console.WriteLine(String.Join<int>(",", Enumerable.Range(b.Min(), b.Max() - b.Min()).Where(x => x % 2 == 1 && !b.Contains(x))));
        }
    }
}

How it works: first, it splits the input string and parses each number into an integer. Then, it creates a range from the minimum occuring integer to the maximum and it takes all odd integers which do not occur in the input string.

\$\endgroup\$
  • \$\begingroup\$ I wrote the C# solution to this and was about to post it until I realized we came up with the exact same solution.... \$\endgroup\$ – Brandon Oct 9 '14 at 17:10
2
\$\begingroup\$

ised, 23 characters (16 code + 7 flags)

This is what ised is best at!

ised --d, --l input.dat 'O[min$1max$1]\$1'

Not counting the name of the file (which could be replaced by - for standard input), this clocks in at 23 characters plus program name plus punctuation needed for spacing the command line arguments. The actual code is just O[min$1max$1]\$1.

Explanation: --d, sets the output delimiter. --l <file> signifies that the following code is applied to each line. $1 represents the current line. The min and max elements are used to initialize the sequence constructor []. O selects the odd numbers. \$1 is the set-wise without operator, which removes the already given numbers from the generated sequence.

Please clarify how the characters should be counted. Does the name ised of the command count or not?

\$\endgroup\$
  • \$\begingroup\$ Input is not sorted (look at the examples) \$\endgroup\$ – edc65 May 30 '14 at 16:01
  • \$\begingroup\$ Got it. Fixed... \$\endgroup\$ – orion May 30 '14 at 16:06
  • 1
    \$\begingroup\$ I think the standard scoring for this would be 23: 16 for the program and 7 for the flags --d, --l \$\endgroup\$ – Peter Taylor May 30 '14 at 21:27
2
\$\begingroup\$

PHP, 110 chars

$a=split(' ',$i);echo join(',',array_filter(array_diff(range(min($a),max($a)),$a),function($n){return$n&1;}));

More readable version:

$a = split(' ', $i);
echo join(',',
    array_filter(
        array_diff(
            range(min($a), max($a)),
            $a
        ),
        function($n) {
            return $n & 1;
        }
    )
);

This basically creates an array of all the numbers within the range and uses a bitwise $n & 1 to check if the number is even or odd.

Demo

\$\endgroup\$
  • \$\begingroup\$ You can save 2 characters by replacing min($a) with $a[0], as the first number has to be the smallest. \$\endgroup\$ – MrLore May 31 '14 at 22:11
  • \$\begingroup\$ @MrLore Order of the input is not guaranteed. \$\endgroup\$ – nderscore Jun 1 '14 at 2:57
  • \$\begingroup\$ @nderscore: Oh, I hadn't noticed that. Thanks for the heads-up! \$\endgroup\$ – Amal Murali Jun 1 '14 at 3:04
2
\$\begingroup\$

PHP 106

<?
$a = '4 6 8 10';
$a=split(' ',$a);foreach(range(min($a),max($a))as$i)if($i%2&&!in_array($i,$a))$d[]=$i;echo join(',',$d);

i'm not sure about what to discount from the char count, so i just discounted the line with the declaration

\$\endgroup\$
  • \$\begingroup\$ If set of numbers that doesn't have missing odd numbers, the code produces a warning : eval.in/157049 which according to the conditions are not allowed. \$\endgroup\$ – Subin May 30 '14 at 15:13
  • \$\begingroup\$ that condition is new... \$\endgroup\$ – Einacio May 30 '14 at 15:15
  • \$\begingroup\$ @Subin fixed the warnings \$\endgroup\$ – Einacio May 30 '14 at 15:17
  • \$\begingroup\$ Nice. I made it more complicated than necessary, as usual. :) \$\endgroup\$ – keyboardSmasher May 30 '14 at 22:50
2
\$\begingroup\$

Pyth, 20

JSrz7j\,-f%T2rhJeJJ

J is the list of integers, sorted. rhJeJ gives all of the possible integers between the min and max of the input. f%T2 filters out the even numbers. -_J filters out the original elements of J. j\, joins the resultant list on commas, and the string is automatically printed.

\$\endgroup\$
1
\$\begingroup\$

J - 42 char

}.;(',',":)&.>n-.~l#~2|l=.(<./n)}.i.1+>./n=:4 6 8 10

I exclude from the character count the =:4 6 8 10 portion, but I include the n because that's part of the rest of the code—assignments can have return values in J.

Explained by explosion:

}.;(',',":)&.>n-.~l#~2|l=.(<./n)}.i.1+>./n=:4 6 8 10  NB. missing odd numbers
                                         n=:4 6 8 10  NB. input assigned to n
                                      >./n            NB. maximum of n
                                  i.1+                NB. integers from 0 to max(n) incl.
                          (<./n)                      NB. minimum of n
                                }.                    NB. drop first min(n) values
                       l=.                            NB. assign this to l
                     2|                               NB. modulo 2: 0 for evens, 1 for odds
                  l#~                                 NB. keep the odd numbers from l
              n-.~                                    NB. discard numbers already in n
   (      )&.>                                        NB. for each number:
        ":                                            NB.   convert to string
    ',',                                              NB.   and prepend a comma
  ;                                                   NB. run together all results
}.                                                    NB. remove leading comma

Example usage:

   }.;(',',":)&.>n-.~l#~2|l=.(<./n)}.i.1+>./n=:4 6 8 10
5,7,9
   }.;(',',":)&.>n-.~l#~2|l=.(<./n)}.i.1+>./n=:5 15 18 21 26
7,9,11,13,17,19,23,25
   }.;(',',":)&.>n-.~l#~2|l=.(<./n)}.i.1+>./n=:2 15 6
3,5,7,9,11,13
   }.;(',',":)&.>n-.~l#~2|l=.(<./n)}.i.1+>./n=:1 20
3,5,7,9,11,13,15,17,19
   }.;(',',":)&.>n-.~l#~2|l=.(<./n)}.i.1+>./n=:1 3 5 7 9    NB. blank line

   # }.;(',',":)&.>n-.~l#~2|l=.(<./n)}.i.1+>./n=:1 3 5 7 9  NB. see? length is 0
0
\$\endgroup\$
1
\$\begingroup\$

Javascript (E6) 100 110

Edit: join in output is unnecessary (stolen from nderscore but too obvious)
Edit2: see comments
Edit3: fixed bug, skip min if odd
Edit4: teamwork ... (loop for every number, then inside loop skip even ones)

t='13 15 20 2'; /* Not counted */
l=t.split(' ').sort((a,b)=>b-a);for(n=l.pop(o=[]);++n<l[0];)n%2&!l.some(x=>x==n)&&o.push(n);alert(o)
\$\endgroup\$
  • \$\begingroup\$ Our answers have ended up being the same, so I removed mine. You beat me by a few minutes haha. \$\endgroup\$ – nderscore May 30 '14 at 16:00
  • \$\begingroup\$ -1 byte: move o=[] inside of pop() \$\endgroup\$ – nderscore May 30 '14 at 16:01
  • \$\begingroup\$ Why do you have to skip the min value? You're already checking if the value isn't in l before adding it to your output array. \$\endgroup\$ – nderscore May 30 '14 at 19:20
  • \$\begingroup\$ I check all the numbers using 'l', but I get the min with pop(), so it's not there anymore. The relation between min and initial n is 2-->3, 3-->5, 4-->5 and so on \$\endgroup\$ – edc65 May 30 '14 at 19:26
  • \$\begingroup\$ Makes sense now. Bring it back to 100: l=t.split(' ').sort((a,b)=>b-a);for(n=l.pop(o=[]);++n<l[0];)n%2&!l.some(x=>x==n)&&o.push(n);alert(o) \$\endgroup\$ – nderscore May 30 '14 at 19:35
1
\$\begingroup\$

GolfScript, 51 40 characters

' '/{~}/]$:a),\(,\;-{.2%\a?-1=&},{','}/;

Input should be on STDIN. Test online

If input on STDIN is not allowed, then changing it so it allows variables only adds 1 character.

Ungolfed code with explanation:

' '/ # split input string
{~}/ # convert all strings into integers
]$   # put integers into an array and sort it
:a   # put array into variable a
)    # take last element from array
,    # create an array from 0 to the integer obtained from previous command
\    # swap new array and first array, first array is now on top
(    # take first element from first array
,    # create an array from 0 to the integer obtained from previous command
\;   # swap newest array and first array, and remove first array
-    # remove elements from second array if they also occur in third (newest) array
{    # this block will be used to process elements in the array
  .   # duplicate current item twice
  2%   # obtain the remainder when dividing it by 2
  \    # swap remainder and one of the duplicates
  a?   # obtain the index of the current item in the first array which is stored in variable a
  -1=  # check if index is -1 (the item is not found)
  &  # returns 1 if it is a missing odd number
},   # filter contents of array, only keep missing odd numbers
{','}/;  # separate results with commas
\$\endgroup\$
  • \$\begingroup\$ array block , as filter is very useful here. \$\endgroup\$ – Peter Taylor May 30 '14 at 21:29
  • \$\begingroup\$ Next you'll be posting pages full of 1's and 0's. lol :) +1 \$\endgroup\$ – keyboardSmasher Jun 1 '14 at 1:25
1
\$\begingroup\$

PHP, 118 chars

// $n='4 6 8 11 14';
$o=[];$a=explode(' ',$n);foreach(range(min($a),max($a))as$b)if($b%2!=0&&!in_array($b,$a))$o[]=$b;echo implode(',',$o);

Expanded...

// Empty array to hold the output
$o = [];

// Put each number in a zero indexed array
$a = explode(' ', $n);

// Iterate through each number between the smallest number and the largest number, inclusive
foreach(range(min($a), max($a)) as $b) {

    // If the number is not even and it's not one of the numbers in the input,
    // then add it to the output array
    if ($b % 2 != 0 && !in_array($b, $a)) {
        $o[] = $b;
    }
}

// Glue the numbers in the output array together with a comma
echo implode(',', $o);
\$\endgroup\$
  • \$\begingroup\$ Could you explain how this works exactly? \$\endgroup\$ – ɐɔıʇǝɥʇuʎs May 31 '14 at 22:38
  • \$\begingroup\$ @Synthetica How's that? \$\endgroup\$ – keyboardSmasher May 31 '14 at 23:10
  • \$\begingroup\$ Better. Much better. (It was showing up in my review cue as a low quality answer) \$\endgroup\$ – ɐɔıʇǝɥʇuʎs Jun 1 '14 at 0:11
1
\$\begingroup\$

Javascript (ES6) - 85

Edit: Undeleted, as I found a solution that's different enough from edc65's to justify it's own answer.

i='13 15 20 2' // input is not part of byte count
o=[];i.split(' ').sort((a,b)=>a-b).sort((a,b)=>{for(;++a<b;)a%2&&o.push(a)});alert(o)

Ungolfed / Commented:

o=[];               // array for output
i.split(' ').       // split input by spaces
  sort((a,b)=>a-b). // sort by numeric order
  sort((a,b)=>{     // abuse sort as a way to run a function on every pair of neighboring 
                    // values the array in order
    for(;++a<b;)    // loop from a+1 to b-1 
      if(a%2)       // if odd
        o.push(a)   // push to array
  });               // the sort function returns nothing, so the order of the array is 
                    // unchanged and no pair is compared twice
alert(o)            // the array is cast to a string, which is comma separated by default
\$\endgroup\$
1
\$\begingroup\$

Java: 173

public class R{
    public static void main(String[]a){
        int i=0,p=0;
        for(String s:a){
            int j=new Integer(s);
            i=i==0?j:i;
            while(++i<j)
            if(i%2==1)
                System.out.print((p++==0?"":",")+i);
        }
    }
}

//Compressed:
public class R{public static void main(String[]a){
int i=0,p=0;for(String s:a){int j=new Integer(s);i=i==0?j:i;
while(++i<j)if(i%2==1)System.out.print((p++==0?"":",")+i);}}}

To run:

java R 5 15 18 21 26

Produces:

7,9,11,13,17,19,23,25
\$\endgroup\$
1
\$\begingroup\$

PowerShell - 59

This creates an array of integers bounded by the max and min values in the array of arguments and sends it through the pipeline. It then passes through the numbers that are odd and not in the array of arguments.

$x=$args|sort;($x[0]..$x[-1]|?{$_%2-and$_-notin$x})-join','
\$\endgroup\$
1
\$\begingroup\$

PowerShell, 101 99 95 91 78 58 chars

$a=$args #input doesn't count
$a=$a|sort;($a[0]..$a[-1]|?{$_%2-and!($a-like$_)})-join','

It outputs the same results as the example, and new line if there are no odd numbers missing.

Ungolfed code:

#input doesn't count
$a=$args 
# Sort input array
$a=$a | sort;
# Loop from numbers starting at first (min) and ending at last (max) elements of array
($a[0] .. $a[-1] | ?{
    # Ouptup if element is even and is not contained in original input array
    $_ % 2 -and !($a -like $_
# Print output elements joined by ","
})-join','
\$\endgroup\$
1
\$\begingroup\$

Haskell, 137 chars and almost no spaces

import Data.List
main=let n=(map read(words$s)::[Int])in putStr$intercalate","$map show$(filter(\x->x`mod`2==1)[minimum n..maximum n])\\n

I love how Haskell doesn't give one crap about spaces.

Put the string in a function s

\$\endgroup\$
1
\$\begingroup\$

Perl 6, 60 50 bytes (55 47 chars)

HT to JoKing for shrinking it down a substantial number of bytes (mainly via the odd number generation and rearranging to kill some parentheses)

{join ',',keys (.min..^.max X+|1)∖$_}o+«*.words

Try it online!

Original answer:

(+«*.words).&{(.min+|1,*+2…*>.max-2)∖$_}.keys.join(',')

Try it online!

Here's the explanation for it:

(+«*.words)                                             # numberize each word in input (*) 
           .&{                         }                # pass them to an inline method to
                                    ∖                   #   find the set difference of
              (       ,*+2…        )                    #     all odd numbers from
               .min+|1                                  #       1st (bitwise OR 1) to
                           *>.max-2                     #       last (first odd > max-2) 
                                     $_                 #     and the original number set
                                        .keys.join(',') # print final values (.keys is
                                                        #     needed for quirk with Set)

If the output were just spaces, could use .Strinstead of .keys.join(','), but directly using .join on Set grabs the internal Bool values. I'm legitimately surprised there wasn't anything much smaller, but the input/output requirements really killed options

\$\endgroup\$
  • \$\begingroup\$ @JoKing bravo, I really need to get better about using o \$\endgroup\$ – user0721090601 Jun 28 at 6:47
0
\$\begingroup\$

Ruby, 73

a=$*.map &:to_i;$><<(a.min..a.max).select{|n|n%2>0&&!a.index(n)}.join(?,)
\$\endgroup\$
0
\$\begingroup\$

Perl, 88 76 74 68 63 60 chars

@x=@ARGV; # Input doesn't count
sort{$a<=>$b}$x;say join",",grep{$_%2&"@x"!~$_}$x[0]..$x[-1]

This can be tested on console as:

perl -E '@x=@ARGV;sort{$a<=>$b}$x;say join",",grep{$_%2&"@x"!~$_}$x[0]..$x[-1]' 1 20

It outputs the same results as the example, and new line if there are no odd numbers missing.

\$\endgroup\$
  • \$\begingroup\$ This is not correct. First with parameters 1 13 3 will not be printed (because it matches parameters). Second I don't know such sort in place idiom, at least it doesn't work for on my perl version. \$\endgroup\$ – nutki Nov 3 '14 at 13:12
0
\$\begingroup\$

R, 59 chars:

b=range(a<-scan());d=b[1]:b[2];cat(d[!d%in%a&d%%2],sep=",")

Expanded a little:

a=scan() #Takes serie of integers as input
b=range(a) #Takes min and max
d=b[1]:b[2] #Creates sequence from min to max
cat(d[!d%in%a & d%%2], #Keep only those that are not in input and are odd
    sep=",") #Print them comma-separated

Usage:

> b=range(a<-scan());d=b[1]:b[2];cat(d[!d%in%a&d%%2],sep=",")
1: 2 15 6
4: 
Read 3 items
3,5,7,9,11,13
> b=range(a<-scan());d=b[1]:b[2];cat(d[!d%in%a&d%%2],sep=",")
1: 5 15 18 21 26
6: 
Read 5 items
7,9,11,13,17,19,23,25
> b=range(a<-scan());d=b[1]:b[2];cat(d[!d%in%a&d%%2],sep=",")
1: 1 3 5 7 9
6: 
Read 5 items
> 
\$\endgroup\$
0
\$\begingroup\$

VB.net (154c)

Dim a = From w In i.Split(" "c) Select Int32.Parse(w)
Console.WriteLine(String.Join(",",(From n In Range(a.Min,a.Max-a.Min)
                                   Where n Mod 2 = 1).Except(a))
\$\endgroup\$
0
\$\begingroup\$

Haskell, 105 (168 with variable+comment)

This code splits the string into 'words', reads the words as integers, and takes all of the odd numbers in the list-difference between the range of the numbers (all integers between the smallest and the largest values) and the list of numbers itself. I then convert it to a string, remove the brackets from the conversion of a list to a string, and print the line.

import Data.List
s="1 4 9 12 8 20" -- not counted, in accordance with the rules
main=putStrLn$show[y|let x=(map read).words$s,y<-[minimum x..maximum x]\\x,odd y]\\"[]"
\$\endgroup\$
0
\$\begingroup\$

TinyMUSH, 129

&_ me=ifelse(or(eq(words(%0),1),eq(strlen(setr(0,istrue(ldiff(lnum(lmin(%0),lmax(%0)),%0,),mod(##,2),,\\\,))),0)),%r,%q0)
\u(_,X)

Replace the "X" in the u() function with the list of whole numbers. The output is just a carriage return when there is one list item or a lack of odds to output. Otherwise, the code constructs a list of integers starting from the lowest to the highest in the input. The code then uses ldiff() to remove from that new list anything that appeared in the input. Then evens are filtered out with mod(), and the list gets "," as the new delimiter.

\$\endgroup\$
0
\$\begingroup\$

Perl 5 - 66

66 characters including 3 for command line options

#!perl -lpa
%F=@F=sort{$a<=>$b}@F,@F;$_=join',',grep$_&!$F{$_},"@F"..pop@F

Takes multiple lines of data on the standard input.

\$\endgroup\$
0
\$\begingroup\$

Burlesque, 41

ln{wdrie!r@{2.%}f[}]m{{Jrij',==$$}f[}m[uN

The bloated length is mostly due to mostly formatting the output.

\$\endgroup\$
0
\$\begingroup\$

JavaScript 89

Five less characters and better typing thanks to WallyWest.

s='5 15 18 21 26' // not counted
s=s.split(" ");o="";for(i=0;j=+s[i++];)for(;++j<+s[i];)o+=0!=j%2?(o?",":"")+j:"";alert(o)

Originally 94 chars.

s='5 15 18 21 26' // not counted
s=s.split(' '),o='',i=0;while(j=s[i++])for(j*=1;++j<s[i]*1;)o+=j%2!=0?(o?',':'')+j:'';alert(o)
\$\endgroup\$
  • 1
    \$\begingroup\$ You could bring it down to 89 by changing the while loop to a for loop, as well as tidying up the logic and typing of j: s=s.split(" ");o="";for(i=0;j=+s[i++];)for(;++j<+s[i];)o+=0!=j%2?(o?",":"")+j:"";alert(o) \$\endgroup\$ – WallyWest Nov 5 '14 at 1:29
0
\$\begingroup\$

Haskell 104 96 Bytes

import Data.List
l=sort.map read.words
f k=putStr$show[x|x<-[l k!!0..last$l k]\\l k,odd x]\\"[]"

A 136 byte version using only predule

l=map read.words
c x=foldl1 x.l        
f k=putStr$[z|z<-show[x|x<-[c min k..c max k],x`notElem`l k,odd x], z`notElem`"[]"]

Details

    --words              |Take a string and break into list (implicit application since f=words is the same as f x = words x)
    --map read           |Convert all the words to a number (the type is inferred at run time based on input)

    l=sort.map read.words

    --[l k!!0..last$l k] |Generate sequence of all numbers from lowest to highest, 
    --\\l k              |Remove any numbers in list l
    --odd x              |Only return odd. 
    --show               |Convert to a string
    --\\"[]"             |Remove the [] characters from the string 
    --putSTr             |Finally, put the string to the terminal. 

    f k=putStr$[z|z<-show[x|x<-[l k!!0..last$l k]\\l k,odd x]]\\"[]"
\$\endgroup\$
0
\$\begingroup\$

Wolfram Language (Mathematica), 89 bytes

Complement[Range[Min@#~Floor~2+1,Max@#,2],#]~StringRiffle~","&@*ToExpression@*StringSplit

Try it online!

This script is a Composition of three functions, acting from right to left on the input string:

  1. StringSplit splits the input string into a list of substrings separated by whitespace.

  2. ToExpression then converts this list of substrings into a list of numbers.

  3. The actual work is done in the function

    StringRiffle[Complement[Range[Floor[Min[#], 2] + 1, Max[#], 2], #], ","] &
    
    • Range[Floor[Min[#], 2] + 1, Max[#], 2] is the list of odd numbers spanning from the smallest to the largest in the supplied list of numbers.

    • With Complement we eliminate those odd numbers that are already present in the supplied list of numbers.

    • What is left is then recomposed into a comma-separated string with StringRiffle.

A more flexible I/O format would reduce this solution to 44 bytes.

\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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