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

  • Home
  • SEARCH
  • 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 474719
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T00:18:58+00:00 2026-05-13T00:18:58+00:00

Given inputs 1-32 how can I generate the below output? in. out 1 1

  • 0

Given inputs 1-32 how can I generate the below output?

in. out

  1. 1
  2. 1
  3. 1
  4. 1
  5. 2
  6. 2
  7. 2
  8. 2
  9. 1
  10. 1
  11. 1
  12. 1
  13. 2
  14. 2
  15. 2
  16. 2
    …

Edit Not Homework.. just lack of sleep.

I am working in C#, but I was looking for a language agnostic algorithm.

Edit 2 To provide a bit more background… I have an array of 32 items that represents a two dimensional checkerboard. I needed the last part of this algorithm to convert between the vector and the graph, where the index aligns on the black squares on the checkerboard.

Final Code:

 --Index;
 int row = Index >> 2;
 int col = 2 * Index - (((Index & 0x04) >> 2 == 1) ? 2 : 1);
  • 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-13T00:18:59+00:00Added an answer on May 13, 2026 at 12:18 am

    Assuming that you can use bitwise operators you can check what the numbers with same output have in common, in this case I preferred using input 0-31 because it’s simpler (you can just subtract 1 to actual values)

    What you have?

    0x0000 -> 1
    0x0001 -> 1
    0x0010 -> 1
    0x0011 -> 1
    0x0100 -> 2
    0x0101 -> 2
    0x0110 -> 2
    0x0111 -> 2
    0x1000 -> 1
    0x1001 -> 1
    0x1010 -> 1
    0x1011 -> 1
    0x1100 -> 2
    ...
    

    It’s quite easy if you notice that third bit is always 0 when output should be 1 and viceversa it’s always 1 when output should be 2

    so:

    char codify(char input)
    {
         return ((((input-1)&0x04)>>2 == 1)?(2):(1));
    }
    

    EDIT

    As suggested by comment it should work also with

    char codify(char input)
    {
         return ((input-1 & 0x04)?(2):(1));
    }
    

    because in some languages (like C) 0 will evaluate to false and any other value to true. I’m not sure if it works in C# too because I’ve never programmed in that language. Of course this is not a language-agnostic answer but it’s more C-elegant!

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

Sidebar

Related Questions

How can I give the input field below the characteristics listed below? Characteristics: -Text
I'm trying to do some very basic time math - basically, given inputs of
Given an input sequence, what is the best way to find the longest (not
Can somebody suggest me a template engine (preferably written in Java) that could generate
I'm currently working on a project which uses XSL-Transformations to generate HTML from XML.
I have a CSV file and using fgetcsv I can happily generate each line
I need to generate all the partitions of a given integer. I found this
How can you solve the following error messages given by PHPdoc? I run madedoc.sh
If I have a form element as given below, then calling the form's submit
Given this input: [1,2,3,4] I'd like to generate the set of spanning sets: [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.