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 8752869
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T13:18:59+00:00 2026-06-13T13:18:59+00:00

I am trying to set up a system that will print a certain amount

  • 0

I am trying to set up a system that will print a certain amount of pages depending on the amount of items supplied and how many lines that have.

I basically have a list of maps with a couple of fields, including a name field that could be quite long and span over a number of lines on the printer. I have a function that can discern how many lines it will take up, so that’s no issue.

The main problem is that I want to split (well, partition, if you use clojure’s terminology) the collection of products when it gets to 30 lines, so I can start another page. Is there a way to run over the collection working out the total lines up to 30 (less if there is a multi-line product that would otherwise go over 30 lines) and then split it?

I’d like to turn this

[{:qty 2 :size "M" :product "Testing 1 2 3"}
 {:qty 1 :size "S" :product "Hello there world"}
 {:qty 12 :size "XS" :product "Some really long product name just to test"}
 {:qty 932 :size "L" :product "More longer names to play with"}
 {:qty 1 :size "M" :product "Another product name"}
 {:qty 1242 :size "XS" :product "This is just an obscenely long product name that I am hoping will spill over on to the next lines"}
 {:qty 2 :size "M" :product "Testing 1 2 3"}
 {:qty 1 :size "S" :product "Hello there world"}
 {:qty 12 :size "XS" :product "Some really long product name just to test"}
 {:qty 932 :size "L" :product "More longer names to play with"}
 {:qty 1 :size "M" :product "Another product name"}
 {:qty 1242 :size "XS" :product "This is just an obscenely long product name that I am hoping will spill over on to the next lines"}
 {:qty 2 :size "M" :product "Testing 1 2 3"}
 {:qty 1 :size "S" :product "Hello there world"}
 {:qty 12 :size "XS" :product "Some really long product name just to test"}
 {:qty 932 :size "L" :product "More longer names to play with"}
 {:qty 1 :size "M" :product "Another product name"}
 {:qty 1242 :size "XS" :product "This is just an obscenely long product name that I am hoping will spill over on to the next lines"}]

into this

[[{:qty 2 :size "M" :product "Testing 1 2 3"}
  {:qty 1 :size "S" :product "Hello there world"}
  {:qty 12 :size "XS" :product "Some really long product name just to test"}
  {:qty 932 :size "L" :product "More longer names to play with"}
  {:qty 1 :size "M" :product "Another product name"}
  {:qty 1242 :size "XS" :product "This is just an obscenely long product name that I am hoping will spill over on to the next lines"}
  {:qty 2 :size "M" :product "Testing 1 2 3"}
  {:qty 1 :size "S" :product "Hello there world"}
  {:qty 12 :size "XS" :product "Some really long product name just to test"}
  {:qty 932 :size "L" :product "More longer names to play with"}
  {:qty 1 :size "M" :product "Another product name"}]
 [{:qty 1242 :size "XS" :product "This is just an obscenely long product name that I am hoping will spill over on to the next lines"}
  {:qty 2 :size "M" :product "Testing 1 2 3"}
  {:qty 1 :size "S" :product "Hello there world"}
  {:qty 12 :size "XS" :product "Some really long product name just to test"}
  {:qty 932 :size "L" :product "More longer names to play with"}
  {:qty 1 :size "M" :product "Another product name"}
  {:qty 1242 :size "XS" :product "This is just an obscenely long product name that I am hoping will spill over on to the next lines"}]]

The max line-length for the product name is 25 characters

Thanks heaps in advance!

  • 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-13T13:19:00+00:00Added an answer on June 13, 2026 at 1:19 pm

    I’m going to give you an answer to a similar problem, and you should be able to extrapolate from there to get the answer to your problem.


    Question:

    How do I group a sequence of strings into subgroups of adjacent strings with a total of at most n characters in each subgroup?

    Solution:

    ;; Data
    (def input
      ["asdjasjdklasj" "dkjfsj" "dfkjsj" "kfjskd" "skdjfsjkdjdfs"
       "dfjskd" "wiuennsdw" "dskjdfsdjwed" "wiuf" "mncxnejs" "fjsjd"
       "dkjsf" "djsk" "djf" "erjfdkjcxzasd" "sjkja"])
    
    ;; Counting function
    (def char-count count)
    
    ;; Partition function
    (defn group-to-size [size coll]
      (lazy-seq
        (loop [[x & xs' :as xs] coll, n 0, acc []]
          (if (nil? x) (cons acc nil)
            (let [n' (+ n (char-count x))]
              (if (<= n' size)
                (recur xs' n' (conj acc x))
                (cons acc (group-to-size size xs))))))))
    
    ;; Sample grouping by 15 characters
    (group-to-size 15 input)
    
    ; => (["asdjasjdklasj"]
    ;     ["dkjfsj" "dfkjsj"]
    ;     ["kfjskd"]
    ;     ["skdjfsjkdjdfs"]
    ;     ["dfjskd" "wiuennsdw"]
    ;     ["dskjdfsdjwed"]
    ;     ["wiuf" "mncxnejs"]
    ;     ["fjsjd" "dkjsf" "djsk"]
    ;     ["djf"]
    ;     ["erjfdkjcxzasd"]
    ;     ["sjkja"])
    
    ;; Resulting character counts per group for the above sample
    (->> (group-to-size 15 input)
         (map (comp count (partial apply concat))))
    
    ; => (13 12 6 13 15 12 12 14 3 13 5)
    

    Instead of counting characters in a string you want to count lines in a product description. Your function for counting the number of lines per product is the equivalent of char-count in my code above. I think you should be able to figure it out from here.

    Note: This solution has the added benefit of being lazy. That means it doesn’t bother partitioning the entire set of strings if you end up only wanting to use the first partition. In your case, it would translating into not partitioning the entire inventory if the user decides to only view the first couple pages.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Is it possible to set how many lines the console will print before it
I'm trying to formulate an SQL query for a messaging system that will return
I'll try my best to explain how I'm trying to set up this system.
Im trying to set up a PayPal IPN system on my site, but I
I'm trying to set up a simple chat system with jQuery / Ajax ,
I am trying to set up an automated build system on Windows using Cygwin.
I am trying to set my columns default date time to system datetime. It
I am trying to set up a pretty basic messaging system with ActiveMQ. I
I am currently playing with Qt trying to set up a small particle system.
Trying to set it so if a certain condition is met then one of

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.