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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T21:30:46+00:00 2026-06-18T21:30:46+00:00

i’m kinda of confused how i can construct a for loop in scheme. the

  • 0

i’m kinda of confused how i can construct a for loop in scheme. the for-loop should be implemented in Part II. where it takes a list of numbers and insert each element inside the list in Part I to find the length. I was cable to get the first element but i need a for loop or what so ever to get an output like this: ‘(7 10 5 16 106 37)
here is my code :

#lang racket
; Part I
(define (sequence n)
(cond  [(= n 1)
      (list n)]
[(even? n)
( cons n(sequence( / n 2)))]
[(odd? n) 
( cons n(sequence (+(* n 3) 1))) ] ))

(sequence 3)

; Part II
(define (find-length items)
( cond [(null? items)
      (list items)]
  [find-length(length(sequence(car items))) ]   
  ))

  (find-length '(10 13 16 22 95 158))

here is the output :

 '(3 10 5 16 8 4 2 1)
 7
  • 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-18T21:30:47+00:00Added an answer on June 18, 2026 at 9:30 pm

    Let me get this straight, you need the length of the Collatz sequence for each of the numbers in the items list? Clearly this is homework, so I can’t give a straight answer this time. Here’s the general structure of the solution, fill-in the blanks:

    (define (find-length items)
      (if (null? items)           ; if the list is null
          <???>                   ; return the empty list
          (cons                   ; otherwise `cons` the
           (length <???>)         ; length of Collatz sequence of first element
           (find-length <???>)))) ; and recur over the rest of the list
    

    Test the procedure, the result should be as shown below:

    (find-length '(10 13 16 22 95 158))
    => '(7 10 5 16 106 37)
    

    Notice that your answer was almost right – the base case for this procedure is simply the empty list, and you forgot to call the recursion. In Scheme, at least for know, try not to think about while, for loops: implement iteration in terms of recursion, that’s the idiomatic way to do it. After you get that straight, you can start using one of the built-in looping constructs available in Racket.

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

Sidebar

Related Questions

link Im having trouble converting the html entites into html characters, (&# 8217;) i
I am confused How to use looping for Json response Array in another Array.
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I have an array which has BIG numbers and small numbers in it. I
I'm trying to convert HTML to plain text. I get many &\#8217; &\#8220; etc.
Does anyone know how can I replace this 2 symbol below from the string
I want to construct a data frame in an Rcpp function, but when I
I am trying to loop through a bunch of documents I have to put
Let's say I'm outputting a post title and in our database, it's Hello Y&#8217;all
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function

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.