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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T04:53:30+00:00 2026-06-03T04:53:30+00:00

Sorry if the title is bad… So my problem is that i got this

  • 0

Sorry if the title is bad…

So my problem is that i got this code:

asd (a:as) (b:bs)= tail(rox(tail(rox (tail (rox (a:as) (b:bs))) (b:bs))) (b:bs))
rox [] as = as
rox as [] = as
rox (a:as) (b:bs) = map abs (a-b:rox as bs)

my type must be: asd :: [Int]->[Int]->[Int]

I spent my half day figuring out a good solution, but I just cant think on one, so I would be very happy if someone could help me.
I want to subtract from the (a:as)list the (b:bs)list and after this I want to delete the first number and do it again with the result(result-(b:bs)), until I get a (length (b:bs))-1) list. And if the (a:as)/result is lower than the (b:bs), for exapmle: 00101<10011 I need to change all (b:bs) numbers to 0(and if the result is higher again keep using the (b:bs)). The exapmle is working fine with the code above, but I want to use it with any list. Maybe I need to use the iterate function but I wasnt able to figure out how.

Here is an example:

11010(a:as)
101(b:bs)
01110(result)
 1110(after using tail)
 101(b:bs again)
 0100(result)
  100(after tail)
  101(b:bs)
  001(result)
   01(final result after using tail, so its 1number shorter than the (b:bs) list

Thank you so much for your help!

edit:
With this I can check which binary number is higher, so with this I can turn all bs number into 0, but i dont know how to implement it.

(%>=%) :: [Int] -> [Int] -> Bool
(%>=%) [] [] = True
(%>=%) as [] = True
(%>=%) [] bs = False
(%>=%) as bs
    | filter (/=0) (takeWhile (>(-1))(ro as bs))==[]=False
    | elem 1 (takeWhile (>(-1))(ro as bs))==True=True

ro :: [Int] -> [Int] -> [Int]
ro []       bs       = bs
ro as       []       = as
ro (a:as) (b:bs) = (2*a) - b: ro as bs

Result:

asd [1,1,1,0,0,1,0,1,0,0,0,0] [1,1,0,1,1]
asd [0,1,1,1,1,0,1,0,0,0,0] [1,1,0,1,1]
asd [1,1,1,1,0,1,0,0,0,0] [1,1,0,1,1]
asd [0,1,0,1,1,0,0,0,0] [1,1,0,1,1]
asd [1,0,1,1,0,0,0,0] [1,1,0,1,1]
asd [0,1,1,0,0,0,0] [1,1,0,1,1] < here is something wrong because its: 1,1,0,1,0,0,0 and from here everything is wrong
asd [1,1,0,0,0,0] [1,1,0,1,1]
asd [1,0,0,0,0] [1,1,0,1,1]
asd [0,0,0,0] [1,1,0,1,1]
[0,0,0,0]
  • 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-03T04:53:32+00:00Added an answer on June 3, 2026 at 4:53 am

    It seems like you’re trying to implement the remainder rem (similar to modulo mod) function but for binary lists. It is much faster if you convert the list to an Integer and perform rem on it.

    First, a function that converts from binary to an Integer:

    unbinary :: [Int] -> Integer
    unbinary = foldl (\ a b -> a * 2 + fromIntegral b) 0
    

    Then, a function that converts an Integer into binary:

    binary :: Integer -> [Int]
    binary = reverse . go
      where
        go 0 = []
        go d =
          let (q, r) = quotRem d 2
          in fromIntegral r : binary q
    

    Finally, a function that handles rem for binary lists:

    remBinary :: [Int] -> [Int] -> [Int]
    remBinary a b = binary $ inta `rem` intb
      where
        inta = unbinary a
        intb = unbinary b
    

    The “beauty” of this solution is that you can replace the 2’s with any number (3, 6, 13 etc) and it will work for any base – not just binary.


    To answer your original question:

    This is a very strange function indeed, and I would not use iterate for it.

    asd :: [Int] -> [Int] -> [Int]
    -- If there is nothing to subtract, let's assume that we should return as
    asd as [] = as
    asd as bs
      -- If the length of `as` is shorter than `bs`, we are done.
      | length as < length bs
      = as
      | head as == 0
      = asd (tail as) bs
      -- Otherwise, compute `rox as bs`, take its `tail`, and call `asd` recursively
      | otherwise
      = asd (tail (rox as bs)) bs
    
    -- I simplified your version of this function a bit
    rox :: [Int] -> [Int] -> [Int]
    rox []       bs       = bs
    rox as       []       = as
    rox (a : as) (b : bs) = abs (a - b) : rox as bs
    

    The last part of asd could also be written like this:

      = let diff = rox as bs
            tailOfDiff = tail diff
        in asd tailOfDiff bs
    

    That way, it follows your description more closely.

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

Sidebar

Related Questions

sorry for the bad title, I don't know how to describe my problem. I
Sorry for the bad title, I wasn't sure what else to call this question.
Sorry for the bad question title. Let's say that I have DateRange class that
Sorry for the bad title, but I have no idea how to put this
Sorry for the bad title, I've no idea what to call this question. I
first of all: sorry for bad title, didn't knew how to tell my problem
Sorry for a title that bad, but i didn't know how to describe my
Sorry for the bad title, but I don't know how to name this. My
Sorry for the bad title, but I couldn't think of a better one. I'm
Sorry for bad english and bad title! I have the table post id title

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.