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

  • Home
  • SEARCH
  • 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 7679301
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T17:50:47+00:00 2026-05-31T17:50:47+00:00

Hi I am trying to write a program where given a list of lists

  • 0

Hi I am trying to write a program where given a list of lists check to see if they are equal in size and return #t if they are.

So for example if i were to write (list-counter? ‘((1 2 3) (4 5 6) (7 8 9))) the program would return #t, and (list-counter? ‘((1 2 3) (4 5 6) (7 8))) would return #f.

SO far this is what I have done:

 (define list-counter?
  (lambda (x)
    (if (list? x)
        (if (list?(car x))
      (let (l (length (car x))))
        (if (equal? l (length(car x))))
        (list-counter?(cdr x))
 ) ) ) ) ) 

I think where I am going wrong is after I set the length of l to the length of the first list. Any help would be appreciated.

  • 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-05-31T17:50:49+00:00Added an answer on May 31, 2026 at 5:50 pm

    There are several ways to solve this problem. For instance, by hand and going step-by-step:

    (define (all-lengths lists)
      (if (null? lists)
          '()
          (cons (length (car lists))
                (all-lengths (cdr lists)))))
    
    (define (all-equal? head lengths)
      (if (null? lengths)
          true
          (and (= head (car lengths))
               (all-equal? head (cdr lengths)))))
    
    (define (list-counter? lists)
      (let ((lengths (all-lengths lists)))
        (all-equal? (car lengths) (cdr lengths))))
    

    Let me explain the above procedures. I’m dividing the problem in two steps, first create a new list with the lengths of each sublist – that’s what all-lengths does. Then, compare the first element in a list with the rest of the elements, and see if they’re all equal – that’s what all-equal? does. Finally, list-counter? wraps it all together, calling both of the previous procedures with the right parameters.

    Or even simpler (and shorter), by using list procedures (higher-order procedures):

    (define (list-counter? lists)
      (apply = (map length lists)))
    

    For understanding the second solution, observe that all-lengths and all-equal? represent special cases of more general procedures. When we need to create a new list with the result of applying a procedure to each of the elements of another list, we use map. And when we need to apply a procedure (= in this case) to all of the elements of a list at the same time, we use apply. And that’s exactly what the second version of list-counter? is doing.

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

Sidebar

Related Questions

I am trying to write a python program that calculates a histogram, given a
I'm trying to write program calculating average of given numbers stored in an array.
I'm trying to write a program in Java that when given an MxN matrix
I'm trying write a C program that sends an UDP packet to a given
I'm trying to write a program in R that when, given a vector, will
I am trying to write a program that is given a maze and tries
i am trying to write a scheme program which will take a list of
I am trying to write a program that gives a list and back a
I'm trying to write a program to process the BSD-style process accounting file under
I'm trying to write a program that uses sockets to connect with other instances

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.