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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T11:23:35+00:00 2026-06-14T11:23:35+00:00

I want to find the difference between two numbers in a range, but I

  • 0

I want to find the difference between two numbers in a range, but I need to be able to wrap around to the beginning of the range, like a circular list.

The range is 9.

So if the number is 6 and the guess is 5 the answer should be 1, but if the number is 8 and the guess is 2, then the answer should be 3.

My first thought was to bump the number by 10 like this:

n is the correct number, g is the guess, r is the result. 

( let
   [ r (min (- (+ n 10) g) (- g n)) ]

   (if (> 0 r) ( * -1 r ) r) ) 
)

… and that worked for wrapping around, but then the problem is that the existence of the number 10 increases the result by 1 if it wraps. Just subtracting 1 from the result or the number doesn’t work either in all cases.

Depending on the numbers in question, the result is negative, so the if statement is to swap it around to positive.

This isn’t a clojure problem exactly, it’s really a math issue and I’d have this problem in any language, but it so happens that’s what I’m writing it in. I’ve only just started using clojure (or any functional language), so it’s entirely possibly I’m doing things wrong or wildly unidiomatic.

thanks for any help

  • 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-14T11:23:36+00:00Added an answer on June 14, 2026 at 11:23 am

    If you include zero in your loop the question becomes smaller of A – B mod R or B – A mod R

    R = 9
    8 - 3 mod 9 = 5
    3 - 8 mod 9 = 4
    min(5 3) = 3
    

    You can get the effect of not allowing guesses of zero by decrementing the numbers you read and incramenting the numbers you print though your game will be mathematically easier if you allow them to guess the number zero.

    (defn mod- [x y r] 
      (let [res (rem (- x y) r)]
      (if (neg? res)
        (+ res r)
        res)))
    
    (min (mod- A B r) (mod- B A r))
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to find difference between two time-components, but I am not getting what
I want to find out the difference between two Dates (in terms of minutes)
I want to find time difference between two date and then compare the difference
Let's say I want to find out the difference in seconds between two times.
We want to find the number of days between two dates. This is simple
Is there any way find difference between two cs files. I already ask question
Lately, I've been wondering how to find the difference between two files with PHP.
I want to know what the difference between these two foreignkey definitions are. (1)
Help me please to find out what's the difference between these two code snippets:
Can someone tell me the difference between these two queries? db.foo.find({ $and: [{a: 1},

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.