Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. The Lounge
  3. Interview follow up

Interview follow up

Scheduled Pinned Locked Moved The Lounge
helpcsharpcomhostingquestion
27 Posts 8 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • T TPFKAPB

    leppie wrote:

    101 => -1 (no repeats, repeat implies at least 2 sequences)

    Shouldn't that be 1 repeat and still valid? ie 10 and then 1.. Especially given your answer to the second pattern

    leppie wrote:

    11011011 => 3 (still 3 and valid as the remaining subset, 11, is in 110)

    L Offline
    L Offline
    leppie
    wrote on last edited by
    #10

    TPFKAPB wrote:

    Shouldn't that be 1 repeat and still valid? ie 10 and then 1..

    Nope, that is correct. "repeat implies at least 2 (complete) sequences"

    IronScheme
    ((λ (x) `(,x ',x)) '(λ (x) `(,x ',x)))

    T 1 Reply Last reply
    0
    • L leppie

      TPFKAPB wrote:

      Shouldn't that be 1 repeat and still valid? ie 10 and then 1..

      Nope, that is correct. "repeat implies at least 2 (complete) sequences"

      IronScheme
      ((λ (x) `(,x ',x)) '(λ (x) `(,x ',x)))

      T Offline
      T Offline
      TPFKAPB
      wrote on last edited by
      #11

      Ok so then what about the line below that. 11 => 1 That is only one sequence is it not? Or two sequences but then it should read 11 => 2

      L 1 Reply Last reply
      0
      • T TPFKAPB

        Ok so then what about the line below that. 11 => 1 That is only one sequence is it not? Or two sequences but then it should read 11 => 2

        L Offline
        L Offline
        leppie
        wrote on last edited by
        #12

        You made a small interpretation mistake (I do it all the time too). The result is the minimum period, not the number of repeats :)

        IronScheme
        ((λ (x) `(,x ',x)) '(λ (x) `(,x ',x)))

        T 1 Reply Last reply
        0
        • L leppie

          You made a small interpretation mistake (I do it all the time too). The result is the minimum period, not the number of repeats :)

          IronScheme
          ((λ (x) `(,x ',x)) '(λ (x) `(,x ',x)))

          T Offline
          T Offline
          TPFKAPB
          wrote on last edited by
          #13

          Ah yes I remember that part now. Did think it was a bit strange that I thought I could see an error after only a couple of seconds looking at something you had looked at for hours. Thought it must have been me going wrong somewhere and was interested to know where.

          1 Reply Last reply
          0
          • L leppie

            Was given a problem that was suppose to come from the 'easy' bin. Two hours later I was still not finished... On the plus side, the interviewer attempted the problem at the same time, and also got stuck :) He said the problem must have been miscategorized. He told me to finish at home and to send the solution when done ;p Anyways, after a good nights sleep (with some wack apocalyptic dream I had), I started from scratch and coded a solution in about an hour this morning. The given problem: Binary period (dont bother googling for answers as you will likely just end up getting astronomy results or if you have google foo, a few very mathematical papers mostly related to cryptography) Given a number N larger than 0 (range was given, but does not matter), find the minimum period of repeating bit sequences or -1 if none is found. Examples

            110110110 => 3 (as 110 repeats)
            11011011 => 3 (still 3 and valid as the remaining subset, 11, is in 110)
            110110111 => -1 (no period)
            101 => -1 (no repeats, repeat implies at least 2 sequences)
            10101 => 2 (repeat at least over 2 sequences)
            11 => 1

            10101010101 => 2
            111011011101101110 => 7
            111111111111111110 => -1

            My answer in Scheme can be viewed and run here[^]. Edit: Web host seems to be down now... Edit 2: Seems to be back up again, please only look one at a time ;p Damn you shared hosting. If above link is down, view here[^].

            IronScheme
            ((λ (x) `(,x ',x)) '(λ (x) `(,x ',x)))

            J Offline
            J Offline
            Jonathan Nethercott
            wrote on last edited by
            #14

            This looks like correlation (autocorrelation?) to me. I would look for a solution along the lines of: num xor (num shift left 1) num xor (num shift left 2) etc. repeat until (number of bits / 2) Not a very good bit of pseudo code, but hopefully you get the idea ;) I'm not sure how you'd deal with leading and trailing parts of a sequence, but I'm sure there must be an elegant way of incorporating that...

            Jon CodeWrite

            L 1 Reply Last reply
            0
            • L leppie

              Was given a problem that was suppose to come from the 'easy' bin. Two hours later I was still not finished... On the plus side, the interviewer attempted the problem at the same time, and also got stuck :) He said the problem must have been miscategorized. He told me to finish at home and to send the solution when done ;p Anyways, after a good nights sleep (with some wack apocalyptic dream I had), I started from scratch and coded a solution in about an hour this morning. The given problem: Binary period (dont bother googling for answers as you will likely just end up getting astronomy results or if you have google foo, a few very mathematical papers mostly related to cryptography) Given a number N larger than 0 (range was given, but does not matter), find the minimum period of repeating bit sequences or -1 if none is found. Examples

              110110110 => 3 (as 110 repeats)
              11011011 => 3 (still 3 and valid as the remaining subset, 11, is in 110)
              110110111 => -1 (no period)
              101 => -1 (no repeats, repeat implies at least 2 sequences)
              10101 => 2 (repeat at least over 2 sequences)
              11 => 1

              10101010101 => 2
              111011011101101110 => 7
              111111111111111110 => -1

              My answer in Scheme can be viewed and run here[^]. Edit: Web host seems to be down now... Edit 2: Seems to be back up again, please only look one at a time ;p Damn you shared hosting. If above link is down, view here[^].

              IronScheme
              ((λ (x) `(,x ',x)) '(λ (x) `(,x ',x)))

              S Offline
              S Offline
              Septimus Hedgehog
              wrote on last edited by
              #15

              When will you hear if you've got the job? Best of luck.

              "I do not have to forgive my enemies, I have had them all shot." — Ramón Maria Narváez (1800-68). "I don't need to shoot my enemies, I don't have any." - Me (2012).

              L 1 Reply Last reply
              0
              • L leppie

                Was given a problem that was suppose to come from the 'easy' bin. Two hours later I was still not finished... On the plus side, the interviewer attempted the problem at the same time, and also got stuck :) He said the problem must have been miscategorized. He told me to finish at home and to send the solution when done ;p Anyways, after a good nights sleep (with some wack apocalyptic dream I had), I started from scratch and coded a solution in about an hour this morning. The given problem: Binary period (dont bother googling for answers as you will likely just end up getting astronomy results or if you have google foo, a few very mathematical papers mostly related to cryptography) Given a number N larger than 0 (range was given, but does not matter), find the minimum period of repeating bit sequences or -1 if none is found. Examples

                110110110 => 3 (as 110 repeats)
                11011011 => 3 (still 3 and valid as the remaining subset, 11, is in 110)
                110110111 => -1 (no period)
                101 => -1 (no repeats, repeat implies at least 2 sequences)
                10101 => 2 (repeat at least over 2 sequences)
                11 => 1

                10101010101 => 2
                111011011101101110 => 7
                111111111111111110 => -1

                My answer in Scheme can be viewed and run here[^]. Edit: Web host seems to be down now... Edit 2: Seems to be back up again, please only look one at a time ;p Damn you shared hosting. If above link is down, view here[^].

                IronScheme
                ((λ (x) `(,x ',x)) '(λ (x) `(,x ',x)))

                M Offline
                M Offline
                Member 2053006
                wrote on last edited by
                #16

                Is the simplistic solution of starting with length 1 and checking each character, then increasing to length 2 etc too processor intensive? e.g. for 11011011 1 1 0 O O - Not 1, so period is not 1. K K 11 01 10 11 OK - Not 11, so period is not 2 110 110 11 All OK - Period is 3. Failing that would a FFT work on this information?

                L 1 Reply Last reply
                0
                • M Member 2053006

                  Is the simplistic solution of starting with length 1 and checking each character, then increasing to length 2 etc too processor intensive? e.g. for 11011011 1 1 0 O O - Not 1, so period is not 1. K K 11 01 10 11 OK - Not 11, so period is not 2 110 110 11 All OK - Period is 3. Failing that would a FFT work on this information?

                  L Offline
                  L Offline
                  leppie
                  wrote on last edited by
                  #17

                  Member 2053006 wrote:

                  Failing that would a FFT work on this information?

                  That was my first thought, but coding one from scratch with no external help is a bit tough I think :) That is probably the most efficient way to do it.

                  IronScheme
                  ((λ (x) `(,x ',x)) '(λ (x) `(,x ',x)))

                  1 Reply Last reply
                  0
                  • J Jonathan Nethercott

                    This looks like correlation (autocorrelation?) to me. I would look for a solution along the lines of: num xor (num shift left 1) num xor (num shift left 2) etc. repeat until (number of bits / 2) Not a very good bit of pseudo code, but hopefully you get the idea ;) I'm not sure how you'd deal with leading and trailing parts of a sequence, but I'm sure there must be an elegant way of incorporating that...

                    Jon CodeWrite

                    L Offline
                    L Offline
                    leppie
                    wrote on last edited by
                    #18

                    Jon Nethercott wrote:

                    I'm not sure how you'd deal with leading and trailing parts of a sequence, but I'm sure there must be an elegant way of incorporating that...

                    There are no leading parts (thank FSM!). As for the trailing bit, my elegant solution was to do a negative right shift (see line 11, when rs is negative) that fits into the rest (test on line 17). Brain too tired to remember exactly what I did there now ;p

                    IronScheme
                    ((λ (x) `(,x ',x)) '(λ (x) `(,x ',x)))

                    J 1 Reply Last reply
                    0
                    • S Septimus Hedgehog

                      When will you hear if you've got the job? Best of luck.

                      "I do not have to forgive my enemies, I have had them all shot." — Ramón Maria Narváez (1800-68). "I don't need to shoot my enemies, I don't have any." - Me (2012).

                      L Offline
                      L Offline
                      leppie
                      wrote on last edited by
                      #19

                      PHS241 wrote:

                      When will you hear if you've got the job?

                      He wants to have another telephonic discussion next week and I guess an offer will be made at that stage, if they so desire.

                      IronScheme
                      ((λ (x) `(,x ',x)) '(λ (x) `(,x ',x)))

                      1 Reply Last reply
                      0
                      • L leppie

                        Jon Nethercott wrote:

                        I'm not sure how you'd deal with leading and trailing parts of a sequence, but I'm sure there must be an elegant way of incorporating that...

                        There are no leading parts (thank FSM!). As for the trailing bit, my elegant solution was to do a negative right shift (see line 11, when rs is negative) that fits into the rest (test on line 17). Brain too tired to remember exactly what I did there now ;p

                        IronScheme
                        ((λ (x) `(,x ',x)) '(λ (x) `(,x ',x)))

                        J Offline
                        J Offline
                        Jonathan Nethercott
                        wrote on last edited by
                        #20

                        I think this should do it:

                        private int BinaryPeriod(int num)
                        {
                        int result = -1;
                        int numBits = (int)((Math.Log(num) / Math.Log(2))) + 1;

                        for (int i = 1; i <= numBits / 2 && result == -1; i++)
                        {
                            if (((num & ((1 << (numBits - i)) - 1)) ^ (num >> i)) == 0)
                                result = i;
                        }
                        return result;
                        

                        }

                        I've done it in C#, but hopefully it should be fairly generic code. The important line is:

                        if (((num & ((1 << (numBits - i)) - 1)) ^ (num >> i)) == 0)

                        which strips the top i bits and XORs that with num right shifted. If the result is 0 then we have found an autocorrelation.

                        Jon CodeWrite

                        L 2 Replies Last reply
                        0
                        • J Jonathan Nethercott

                          I think this should do it:

                          private int BinaryPeriod(int num)
                          {
                          int result = -1;
                          int numBits = (int)((Math.Log(num) / Math.Log(2))) + 1;

                          for (int i = 1; i <= numBits / 2 && result == -1; i++)
                          {
                              if (((num & ((1 << (numBits - i)) - 1)) ^ (num >> i)) == 0)
                                  result = i;
                          }
                          return result;
                          

                          }

                          I've done it in C#, but hopefully it should be fairly generic code. The important line is:

                          if (((num & ((1 << (numBits - i)) - 1)) ^ (num >> i)) == 0)

                          which strips the top i bits and XORs that with num right shifted. If the result is 0 then we have found an autocorrelation.

                          Jon CodeWrite

                          L Offline
                          L Offline
                          leppie
                          wrote on last edited by
                          #21

                          Very good! Wish I knew of it :(

                          IronScheme
                          ((λ (x) `(,x ',x)) '(λ (x) `(,x ',x)))

                          J 1 Reply Last reply
                          0
                          • J Jonathan Nethercott

                            I think this should do it:

                            private int BinaryPeriod(int num)
                            {
                            int result = -1;
                            int numBits = (int)((Math.Log(num) / Math.Log(2))) + 1;

                            for (int i = 1; i <= numBits / 2 && result == -1; i++)
                            {
                                if (((num & ((1 << (numBits - i)) - 1)) ^ (num >> i)) == 0)
                                    result = i;
                            }
                            return result;
                            

                            }

                            I've done it in C#, but hopefully it should be fairly generic code. The important line is:

                            if (((num & ((1 << (numBits - i)) - 1)) ^ (num >> i)) == 0)

                            which strips the top i bits and XORs that with num right shifted. If the result is 0 then we have found an autocorrelation.

                            Jon CodeWrite

                            L Offline
                            L Offline
                            leppie
                            wrote on last edited by
                            #22

                            And here we have it in Scheme :) http://eval.ironscheme.net/?id=59[^] Thanks again!

                            IronScheme
                            ((λ (x) `(,x ',x)) '(λ (x) `(,x ',x)))

                            1 Reply Last reply
                            0
                            • L leppie

                              Very good! Wish I knew of it :(

                              IronScheme
                              ((λ (x) `(,x ',x)) '(λ (x) `(,x ',x)))

                              J Offline
                              J Offline
                              Jonathan Nethercott
                              wrote on last edited by
                              #23

                              Thank you :) I love solving problems like this - although that has distracted me a bit from what I'm supposed to be doing ;P Good luck with the job!

                              Jon CodeWrite

                              1 Reply Last reply
                              0
                              • L leppie

                                Was given a problem that was suppose to come from the 'easy' bin. Two hours later I was still not finished... On the plus side, the interviewer attempted the problem at the same time, and also got stuck :) He said the problem must have been miscategorized. He told me to finish at home and to send the solution when done ;p Anyways, after a good nights sleep (with some wack apocalyptic dream I had), I started from scratch and coded a solution in about an hour this morning. The given problem: Binary period (dont bother googling for answers as you will likely just end up getting astronomy results or if you have google foo, a few very mathematical papers mostly related to cryptography) Given a number N larger than 0 (range was given, but does not matter), find the minimum period of repeating bit sequences or -1 if none is found. Examples

                                110110110 => 3 (as 110 repeats)
                                11011011 => 3 (still 3 and valid as the remaining subset, 11, is in 110)
                                110110111 => -1 (no period)
                                101 => -1 (no repeats, repeat implies at least 2 sequences)
                                10101 => 2 (repeat at least over 2 sequences)
                                11 => 1

                                10101010101 => 2
                                111011011101101110 => 7
                                111111111111111110 => -1

                                My answer in Scheme can be viewed and run here[^]. Edit: Web host seems to be down now... Edit 2: Seems to be back up again, please only look one at a time ;p Damn you shared hosting. If above link is down, view here[^].

                                IronScheme
                                ((λ (x) `(,x ',x)) '(λ (x) `(,x ',x)))

                                E Offline
                                E Offline
                                Ennis Ray Lynch Jr
                                wrote on last edited by
                                #24

                                Heh, I had to do that in University.

                                Need custom software developed? I do custom programming based primarily on MS tools with an emphasis on C# development and consulting. I also do Android Programming as I find it a refreshing break from the MS. "And they, since they Were not the one dead, turned to their affairs" -- Robert Frost

                                L 1 Reply Last reply
                                0
                                • E Ennis Ray Lynch Jr

                                  Heh, I had to do that in University.

                                  Need custom software developed? I do custom programming based primarily on MS tools with an emphasis on C# development and consulting. I also do Android Programming as I find it a refreshing break from the MS. "And they, since they Were not the one dead, turned to their affairs" -- Robert Frost

                                  L Offline
                                  L Offline
                                  leppie
                                  wrote on last edited by
                                  #25

                                  Was that some kind of homework or other task? Perhaps thesis? ;p

                                  IronScheme
                                  ((λ (x) `(,x ',x)) '(λ (x) `(,x ',x)))

                                  E 1 Reply Last reply
                                  0
                                  • L leppie

                                    Was that some kind of homework or other task? Perhaps thesis? ;p

                                    IronScheme
                                    ((λ (x) `(,x ',x)) '(λ (x) `(,x ',x)))

                                    E Offline
                                    E Offline
                                    Ennis Ray Lynch Jr
                                    wrote on last edited by
                                    #26

                                    Well my degree was computer science. All we did was learn stuff like this. Wouldn't say I knew much about "programming" until after school. But solving problems with code, easy.

                                    Need custom software developed? I do custom programming based primarily on MS tools with an emphasis on C# development and consulting. I also do Android Programming as I find it a refreshing break from the MS. "And they, since they Were not the one dead, turned to their affairs" -- Robert Frost

                                    L 1 Reply Last reply
                                    0
                                    • E Ennis Ray Lynch Jr

                                      Well my degree was computer science. All we did was learn stuff like this. Wouldn't say I knew much about "programming" until after school. But solving problems with code, easy.

                                      Need custom software developed? I do custom programming based primarily on MS tools with an emphasis on C# development and consulting. I also do Android Programming as I find it a refreshing break from the MS. "And they, since they Were not the one dead, turned to their affairs" -- Robert Frost

                                      L Offline
                                      L Offline
                                      leppie
                                      wrote on last edited by
                                      #27

                                      Not even in my 2nd year course (just before I decided to go back to working class) we did stuff like this... I left when when we were busy with Data Structures and Algorithms.

                                      IronScheme
                                      ((λ (x) `(,x ',x)) '(λ (x) `(,x ',x)))

                                      1 Reply Last reply
                                      0
                                      Reply
                                      • Reply as topic
                                      Log in to reply
                                      • Oldest to Newest
                                      • Newest to Oldest
                                      • Most Votes


                                      • Login

                                      • Don't have an account? Register

                                      • Login or register to search.
                                      • First post
                                        Last post
                                      0
                                      • Categories
                                      • Recent
                                      • Tags
                                      • Popular
                                      • World
                                      • Users
                                      • Groups