Jump to content
View in the app

A better way to browse. Learn more.

Opusmodus

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

Find all combinations that add upto given number

Featured Replies

  • Author

I would actually need ALL possibilities …

(defun comb-to-sum (n)
  (let ((nums (gen-integer 1 n))
        (x 0))
    (find-unique
     (sort-asc
      (flatten-sublist
       (loop repeat n
         for i = (combination2 (incf x) nums)
         collect (loop for c in i
                   if (= (sum c) n)
                   collect c)))))))
                   
(comb-to-sum 3)
=> ((3) (1 2) (1 1 1))

(comb-to-sum 5)
=> ((5) (1 4) (2 3) (1 1 3) (1 2 2) (1 1 1 2) (1 1 1 1 1))

 

If you need the function in the OM system I could add it with the next update.

In what context you are using this combination?

  • Author

I use this to select different unique modules for Live-Electronics.

Here ist my adapted function:

 

(defun comb-to-sum (n &key (reps t))
  (let* ((nums (gen-integer 1 n))
         (x 0)
         (result
          (find-unique
           (sort-asc
            (flatten-sublist
             (loop repeat n
               for i = (combination2 (incf x) nums)
               collect (loop for c in i
                         if (= (sum c) n)
                         collect c)))))))
    (if reps
      result
      (loop for i in result
        when (equal (sum (remove-duplicates i)) n)
        collect i))))

(comb-to-sum 5 :reps nil) ; => ((5) (1 4) (2 3))

 

Create an account or sign in to comment


Copyright © 2014-2025 Opusmodus™ Ltd. All rights reserved.
Product features, specifications, system requirements and availability are subject to change without notice.
Opusmodus, the Opusmodus logo, and other Opusmodus trademarks are either registered trademarks or trademarks of Opusmodus Ltd.
All other trademarks contained herein are the property of their respective owners.

Powered by Invision Community

Important Information

Terms of Use Privacy Policy

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.