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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T14:12:39+00:00 2026-06-17T14:12:39+00:00

I am designing a function that consumes a natural number (like 0, 1, 2,

  • 0

I am designing a function that consumes a natural number (like 0, 1, 2, ….etc) and returns the string representing it in unary (base 1) using the symbol I and also displaying the number in decimal after its unary form. So if I type in 2, I would get "II (2)". 5, I would get "IIIII (5)" .

I’ve done it this way:

  (define (number->unary c )
      (cond
       [(= c  1 )  "I (1)" ]
       [(= c  2 ) "II (2)" ]
       [(= c  3) "III (3)"]
       [(= c  4) "IIII (4)"]
       [(= c  5) "IIIII (5)"]
       [(= c  6) "IIIIII (6)"]
       [(= c  7) "IIIIIII (7)"]
       [(= c  8) "IIIIIIII (8)"]
       [(= c  9) "IIIIIIIII (9)"]
       [(= c  10) "IIIIIIIIII (10)"]))

but is there an easier way to do this problem? I’ve been reading about number->string, string-appends, and replicates but I am not sure where to start.

  • 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-17T14:12:40+00:00Added an answer on June 17, 2026 at 2:12 pm

    There’s an easier way indeed – using a loop for generating the appropriate number of "I" characters. Think of it, what would happen if c equals 100? you shouldn’t have to create a hundred conditions for this!

    Here’s one possible way, using a helper procedure for implementing iteration with a recursive procedure called loop:

    (define (number->unary c)
      (loop c (string-append " (" (number->string c) ")")))
    
    (define (loop num str)
      (if (zero? num)
          str
          (loop (sub1 num) (string-append "I" str))))
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm designing a function that will convert a string into a float. e.g. 45.5
I'm designing a function that takes as argument one structure and any number of
Programming language: Java Task: designing a hash function that maps Chinese Strings to numbers
I have a problem with designing my function so that it can act differently
I am designing a layout that looks like: == header == == ad banner
I'm designing an authentication system that works like the following: User enters password Salt
I'm designing a remake of tetris and need a timer function that runs at
-- FIDDLE -- I'm designing a form that acts like a wizard, walking the
While designing a class or a function, which way, that is shown below, is
I'm designing an application that will allow me to draw some functions on a

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.