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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T18:24:53+00:00 2026-05-23T18:24:53+00:00

I was playing around with trying the complete the Hofstadter-Conway $10,000 sequence task in

  • 0

I was playing around with trying the complete the Hofstadter-Conway $10,000 sequence task in Scala on Rosetta Code. I want to use as idiomatic Scala as possible, but I’m having trouble implementing the algorithm without using raw recursion, which normally one only would use as a last resort. Here is what I currently have:

object HofstadterConway {

 def makeHCSequence(max: Int): Seq[Int] = {
   def hc(v: Vector[Int], idx: Int): Vector[Int] = {
     if (idx == (max + 1)) {
       v.tail
     } else if (idx <= 2) {
       hc(v :+ 1, idx + 1)
     } else {
       hc (v :+ (v(v(idx - 1)) + v(idx - v(idx - 1))), idx + 1)
     }
   }
   hc(Vector(), 0)
 }
}

Is there a way to do this more idiomatically?

  • 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-23T18:24:53+00:00Added an answer on May 23, 2026 at 6:24 pm

    I was going to post this earlier, but I don’t have enough SO cred to post answers to my own questions within 8 hours, so I had to wait. As @axel22 noted, this was part of the solution I posted on Rosetta Code website last night.

      def makeHCSequence(max: Int): Seq[Int] = 
        (0 to max - 1).foldLeft (Vector[Int]()) { (v, idx) =>
          if (idx <= 1) v :+ 1 else v :+ (v(v(idx - 1) - 1) + v(idx - v(idx - 1)))
        }
    

    My problem was for some reason my mind got stuck trying to come up with a solution using Vector.range or Vector.iterate, the obvious choice of foldleft just wasn’t occurring to me.

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

Sidebar

Related Questions

I'm playing around, trying to write some code to use the tr.im APIs to
I'm playing around with Scala and servlets and I'm trying to use the JEE6
Just playing around with java trying to learn it etc. Here is my code
I'm playing around with some code katas and trying to get a better understanding
I'm trying to figure out how TransactionScope works playing around with sample code representing
As I'm trying to understand SQL by playing around with the code a bit,
I'm playing around with Facebook Connect, trying to use Facebook as the means or
I am playing around with trying to make a simple Roguelike game to learn
Ive been playing around with delegates trying to learn and I ran into one
I'm playing around with Rhino Mocks and am trying to set some dummy results

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.