I have a task to create a function which gives powerset of a list.
Output of the list (1 2 3) should be this:
1
2
3
1 2
1 3
2 3
1 2 3
I tried this helper function
(defn print-powerset-helper [lst] (if(not(empty? lst)) (do (println(first lst)) (print-lst (rest lst)))))
which gives me
1
2
3
nil
this output.
I also tired this fucntion:
(defn print-powerset [lst] (if (not (empty? lst)) (do (apply println lst (print-lst lst)))))
output:
1
2
3
(1 2 3)
nil
I want to get rid of parenthesis and also don't understand how to print the middle part of the output. 1 2 1 3 2 3 , this part.
Please any kind of help will be good. Thank you!