Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8734521
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T09:51:22+00:00 2026-06-13T09:51:22+00:00

I have a file LIST that has a sequence of characters per line. Each

  • 0

I have a file LIST that has a sequence of characters per line. Each line is labeled with a category, i.e. “C”. Example:

C: w r t y i o p s d f g h j k l z b n m
V: a e i o u
E: n m ng

I want to print every combination of C, V and E (or maybe just C and V, C and E, etc.) using doseq, but generically as I won’t know the nested collections at compile time.

I.e.

"CV" [x y] (str x y ) 
"CVE" [x y z] (str x y z) 
"CVCV" [x y z a] (str x y z a)

My code word-generator.clj

(ns word-generator )
(use 'clojure.string)
(import 'java.io.File)
(use 'clojure.java.io)

(defn get-lines [fname]
  (with-open [r (reader fname)]
    (doall (line-seq r))))

(defn get-list [x lines]
  (first (remove nil?
  (for [num  (range (count lines)) ]
   (if (= (first(split (nth lines num) #"\s+")) x)
     (rest(split (nth lines num) #"\s+")))))))

(def sounds(get-lines "LIST")) ;; get the list


(def C (get-list "C:" sounds)) ;; map consonants 
(def V (get-list "V:" sounds)) ;; map vowels
(def E (get-list "E:" sounds)) ;; map end consonants
(def LI "CVE") ;; word structure 


(defn word-runner[carry args depth]
  (doseq [x C y V z E] (println (str x y z)))) ;; iterate and make the words

(defn runner[]
  ( (print "enter arg list: ")
    (def INPUT (read-line))
    (word-runner "" INPUT 0)))

How can I implement word-runner so that doseq does a nested loop over all sequences of characters found in the file – but without knowing the number of lines in the file at compile-time?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-13T09:51:23+00:00Added an answer on June 13, 2026 at 9:51 am

    This is actually a problem of combinatorics, not so much looping. Use the cartesian-product function from the math.combinatorics library to solve your problem.

    ;; alternative implementation of "word-runner"
    (defn print-cartesian-products [& seqs] 
        (doseq [combs (apply cartesian-product seqs)] 
            (println (apply str combs))))
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I currently have a list of genes in a file. Each line has a
I have a large list of file names that are illegal, I want to
I have a file that has > 10 rows. I want to create 9
I have a text file that has a very long list of items. So
I have a file that has a list of commit ids in it and
I have a file folders.txt one two three four ... that has a list
I have a 60mb XML file that has a list of products, approx 8k
I have a text file that is around 1.7MB that has a list of
I have a file that contain list of numbers that looks like this: 10^-92
I have a file that essentially a list of XPaths like so: /Options/File[1]/Settings[1]/Type[1] /Options/File[1]/Settings[1]/Path[1]

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.