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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T17:50:58+00:00 2026-06-15T17:50:58+00:00

I want a function that changes (1 to 0) on a list of lists,

  • 0

I want a function that changes (1 to 0) on a list of lists, when number of 1’s in that line/column isn’t even. I have done these functions:

1) Sees if the lines in a list are even or not:

  parityLine :: [[Int]] -> [Bool]
  parityLine [] =[]
  parityLine (x:xs)
                |sum(x) `mod` 2 == 0 = True:(parityLine(xs))
                |otherwise = False:(parityLine(xs))

2) Sum the corresponding elements on a list of lists:

 sumPositions :: [[Int]] -> [Int]
 sumPositions [] = []
 sumPositions (x:xs) = foldl (zipWith (+)) (repeat 0) (x:xs)

3) Sees if the columns in a list are even or not:

 parityColumn :: [Int] -> [Bool]
 parityColumn [] = []
 parityColumn (x:xs)
    |head(x:xs) `mod` 2 == 0 = True:parityColumn(xs)
    |otherwise = False:parityColumn(xs)

4) Does the operation or with two boolean lists:

 bol :: [Bool] -> [Bool] -> [[Bool]]
 bol  [] _ = []
 bol (x:xs) (y:ys)= (map (||x) (y:ys)):(bol xs (y:ys))

5) Correct List:

 correct :: [[Int]] -> [[Bool]]
 correct [] = []
 correct (x:xs)=(bol(parityLine (x:xs))(parityColumn(sumPositions(x:xs)))) 

So what I want is to alter the function correct to [[Int]]->[[Int]] that does this:

    My Int list(x:xs)                 With my correct function applied

    [[0,0,1,1],                            [[True,True,True,True],
     [1,0,1,1],                             [True,True,False,True],
     [0,1,0,1],                             [True,True,True,True]
     [1,1,1,1]]                             [True,True,True,True]]

Now I can see that in the second line third column, False, so I have to correct that number 1 to have a number of 1’s even. If there is more than one False in that list, I only want to correct one of these 1’s.

As a result, I want that function correct returns:

 [[0,0,1,1],
  [1,0,0,1],
  [0,1,0,1],
  [1,1,1,1]]

Thanks.

  • 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-15T17:51:00+00:00Added an answer on June 15, 2026 at 5:51 pm

    I’ll give an answer that starts where you are rather than from scratch, so we’re doing it more your way than mine.

    First let’s do it for a single element:

    leaveIf :: Bool -> Int -> Int
    leaveIf yes 0 = if yes then 0 else 1
    leaveIf yes 1 = if yes then 1 else 0
    

    (You could use guards for that, but my phone doesn’t have the vertical bar character!)

    Next we can do it for a list of lists:

    edit :: [[Bool]] -> [[Int]] -> [[Int]]
    edit boolss intss = zipWith (zipWith leaveIf) boolss intss
    

    EDIT: You’d like to only change one, so we’ll need a way of making subsequent Falses into Trues:

    makeTrue :: [Bool] -> [Bool]
    makeTrue xs = map (const True) xs
    

    I’ve used the function const :: a -> b -> a. For example, const 5 'c' is just 5. I could shorten that definition to makeTrue = map (const True). Once you get used to thinking that way, you’ll find the shorter version clearer.

    oneFalse :: [[Bool]] -> [[Bool]]
    oneFalse [] = []
    oneFalse (xs:xss) = let (trues,falses) = break (==False) xs in
         case falses of 
           [] -> trues:oneFalse xss
           (False:others) -> (trues ++ False : makeTrue others) : map makeTrue xss
    

    (==False) could be written more simply as not, but less clearly perhaps.
    so for example

    > oneFalse [[True,True,True,True],[True,False,True,False],[True,False,False,True]]
    [[True,True,True,True],[True,False,True,True],[True,True,True,True]]
    

    So now we can have

    editOne :: [[Bool]] -> [[Int]] -> [[Int]]
    editOne boolss intss = zipWith (zipWith leaveIf) (oneFalse boolss) intss
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to change the toggle function so that it changes the text of
I want a python function that takes a pdf and returns a list of
I want to write a function that takes a list of numbers and returns
I want create a function that verify if the numbers of a list fall
I have a function that takes in a list, and if there are 2
I just want a function that can take 2 parameters: the URL to POST
Say I want a function that takes two floats ( x and y ),
I'm trying to call a function that contains jQuery code. I want this function
I want to write a function that identifies all the links on a particular
I want to make a function that takes an entered value and converts it

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.