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

Ask A Question

Stats

  • Questions 260k
  • Answers 260k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer Try using an empty collapse argument within the paste function:… May 13, 2026 at 11:22 am
  • Editorial Team
    Editorial Team added an answer Your problem is you do: from forum.managers import * (at… May 13, 2026 at 11:22 am
  • Editorial Team
    Editorial Team added an answer If you don't want to send any data, just omit… May 13, 2026 at 11:22 am

Related Questions

Having already read this question I'm reasonably certain that a given process using floating
Given this input: [1,2,3,4] I'd like to generate the set of spanning sets: [1]
You always hear that functional code is inherently easier to parallelize than non-functional code,
I have the following table Table bots{ ip_address varchar(15), bot_name varchar(32) } Given that

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.