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. Other Discussions
  3. The Weird and The Wonderful
  4. What position is the letter A? Let's use a lookup table!

What position is the letter A? Let's use a lookup table!

Scheduled Pinned Locked Moved The Weird and The Wonderful
rubyquestion
25 Posts 12 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.
  • L Lost User

    So, the location of "a" is at "IndexOutOfRangeException"?

    Bastard Programmer from Hell :suss: If you can't read my code, try converting it here[^][](X-Clacks-Overhead: GNU Terry Pratchett)

    R Offline
    R Offline
    Rotted Frog
    wrote on last edited by
    #8

    yes, we need to add 'a' to 'z' in as well. I'll assign it out to one of my team to fix immediately.

    1 Reply Last reply
    0
    • V V 0

      how about :

      public class NumberMap
      {
      private static Dictionary number = new Dictionary();

      static NumberMap()
      {
          number.Add('1', 1);
          number.Add('2', 2);
          number.Add('3', 3);
          number.Add('4', 4);
          number.Add('5', 5);
          number.Add('6', 6);
          number.Add('7', 7);
          number.Add('8', 8);
          number.Add('9', 9);
          number.Add('0', 0);
      }
      

      }

      V.
      (MQOTD rules and previous solutions)

      R Offline
      R Offline
      Rotted Frog
      wrote on last edited by
      #9

      Well done. You get all the bonus points.

      1 Reply Last reply
      0
      • N Nagy Vilmos

        That was written just before you stopped drinking? Yes?

        veni bibi saltavi

        OriginalGriffO Offline
        OriginalGriffO Offline
        OriginalGriff
        wrote on last edited by
        #10

        It was written as a follow up to Converting numbers to the word equivalent. [^] since we were getting a lot of "Roman numbers" homework in QA back then.

        Bad command or file name. Bad, bad command! Sit! Stay! Staaaay...

        "I have no idea what I did, but I'm taking full credit for it." - ThisOldTony
        "Common sense is so rare these days, it should be classified as a super power" - Random T-shirt

        N 1 Reply Last reply
        0
        • OriginalGriffO OriginalGriff

          It was written as a follow up to Converting numbers to the word equivalent. [^] since we were getting a lot of "Roman numbers" homework in QA back then.

          Bad command or file name. Bad, bad command! Sit! Stay! Staaaay...

          N Offline
          N Offline
          Nagy Vilmos
          wrote on last edited by
          #11

          So you'd moved off the booze by then; onto the class 'A' drugs. :laugh:

          veni bibi saltavi

          OriginalGriffO 1 Reply Last reply
          0
          • N Nagy Vilmos

            So you'd moved off the booze by then; onto the class 'A' drugs. :laugh:

            veni bibi saltavi

            OriginalGriffO Offline
            OriginalGriffO Offline
            OriginalGriff
            wrote on last edited by
            #12

            Class A++ I suspect... :~

            Bad command or file name. Bad, bad command! Sit! Stay! Staaaay...

            "I have no idea what I did, but I'm taking full credit for it." - ThisOldTony
            "Common sense is so rare these days, it should be classified as a super power" - Random T-shirt

            N 1 Reply Last reply
            0
            • OriginalGriffO OriginalGriff

              Class A++ I suspect... :~

              Bad command or file name. Bad, bad command! Sit! Stay! Staaaay...

              N Offline
              N Offline
              Nagy Vilmos
              wrote on last edited by
              #13

              Doing crack, heroin and meths is a stage people go through. Just don't do VB!

              veni bibi saltavi

              1 Reply Last reply
              0
              • R Rotted Frog

                Just found this gem hiding in a project I've just inherited. Fortunately it doesn't appear to be used.

                public class AlphabetPositionMap
                {
                private static Dictionary<char, int> alphabet = new Dictionary<char, int>();

                static AlphabetPositionMap()
                {
                    alphabet.Add('A', 1);
                    alphabet.Add('B', 2);
                    alphabet.Add('C', 3);
                    alphabet.Add('D', 4);
                    alphabet.Add('E', 5);
                    alphabet.Add('F', 6);
                    alphabet.Add('G', 7);
                    alphabet.Add('H', 8);
                    alphabet.Add('I', 9);
                    alphabet.Add('J', 10);
                    alphabet.Add('K', 11);
                    alphabet.Add('L', 12);
                    alphabet.Add('M', 13);
                    alphabet.Add('N', 14);
                    alphabet.Add('O', 15);
                    alphabet.Add('P', 16);
                    alphabet.Add('Q', 17);
                    alphabet.Add('R', 18);
                    alphabet.Add('S', 19);
                    alphabet.Add('T', 20);
                    alphabet.Add('U', 21);
                    alphabet.Add('V', 22);
                    alphabet.Add('W', 23);
                    alphabet.Add('X', 24);
                    alphabet.Add('Y', 25);
                    alphabet.Add('Z', 26);
                
                }
                
                public static int Position(char letter)
                {
                    return alphabet\[letter\];
                }
                

                }

                Prizes awarded to anyone who can find a more pointless use of a lookup table.

                R Offline
                R Offline
                Rotted Frog
                wrote on last edited by
                #14

                And it gets better... Just noticed the next class on from that one:

                public class ZeroBasedAlphabetPositionMap
                {
                private static Dictionary<char, int> alphabet = new Dictionary<char, int>();

                static ZeroBasedAlphabetPositionMap()
                {
                    alphabet.Add('A', 0);
                    alphabet.Add('B', 1);
                    alphabet.Add('C', 2);
                    alphabet.Add('D', 3);
                    alphabet.Add('E', 4);
                    alphabet.Add('F', 5);
                    alphabet.Add('G', 6);
                    alphabet.Add('H', 7);
                    alphabet.Add('I', 8);
                    alphabet.Add('J', 9);
                    alphabet.Add('K', 10);
                    alphabet.Add('L', 11);
                    alphabet.Add('M', 12);
                    alphabet.Add('N', 13);
                    alphabet.Add('O', 14);
                    alphabet.Add('P', 15);
                    alphabet.Add('Q', 16);
                    alphabet.Add('R', 17);
                    alphabet.Add('S', 18);
                    alphabet.Add('T', 19);
                    alphabet.Add('U', 20);
                    alphabet.Add('V', 21);
                    alphabet.Add('W', 22);
                    alphabet.Add('X', 23);
                    alphabet.Add('Y', 24);
                    alphabet.Add('Z', 25);
                
                }
                
                public static int Position(char letter)
                {
                    return alphabet\[letter\];
                }
                

                }

                L 1 Reply Last reply
                0
                • R Rotted Frog

                  And it gets better... Just noticed the next class on from that one:

                  public class ZeroBasedAlphabetPositionMap
                  {
                  private static Dictionary<char, int> alphabet = new Dictionary<char, int>();

                  static ZeroBasedAlphabetPositionMap()
                  {
                      alphabet.Add('A', 0);
                      alphabet.Add('B', 1);
                      alphabet.Add('C', 2);
                      alphabet.Add('D', 3);
                      alphabet.Add('E', 4);
                      alphabet.Add('F', 5);
                      alphabet.Add('G', 6);
                      alphabet.Add('H', 7);
                      alphabet.Add('I', 8);
                      alphabet.Add('J', 9);
                      alphabet.Add('K', 10);
                      alphabet.Add('L', 11);
                      alphabet.Add('M', 12);
                      alphabet.Add('N', 13);
                      alphabet.Add('O', 14);
                      alphabet.Add('P', 15);
                      alphabet.Add('Q', 16);
                      alphabet.Add('R', 17);
                      alphabet.Add('S', 18);
                      alphabet.Add('T', 19);
                      alphabet.Add('U', 20);
                      alphabet.Add('V', 21);
                      alphabet.Add('W', 22);
                      alphabet.Add('X', 23);
                      alphabet.Add('Y', 24);
                      alphabet.Add('Z', 25);
                  
                  }
                  
                  public static int Position(char letter)
                  {
                      return alphabet\[letter\];
                  }
                  

                  }

                  L Offline
                  L Offline
                  Lost User
                  wrote on last edited by
                  #15

                  You should not pay developers by LOC :wtf:

                  Bastard Programmer from Hell :suss: If you can't read my code, try converting it here[^][](X-Clacks-Overhead: GNU Terry Pratchett)

                  1 Reply Last reply
                  0
                  • R Rotted Frog

                    Just found this gem hiding in a project I've just inherited. Fortunately it doesn't appear to be used.

                    public class AlphabetPositionMap
                    {
                    private static Dictionary<char, int> alphabet = new Dictionary<char, int>();

                    static AlphabetPositionMap()
                    {
                        alphabet.Add('A', 1);
                        alphabet.Add('B', 2);
                        alphabet.Add('C', 3);
                        alphabet.Add('D', 4);
                        alphabet.Add('E', 5);
                        alphabet.Add('F', 6);
                        alphabet.Add('G', 7);
                        alphabet.Add('H', 8);
                        alphabet.Add('I', 9);
                        alphabet.Add('J', 10);
                        alphabet.Add('K', 11);
                        alphabet.Add('L', 12);
                        alphabet.Add('M', 13);
                        alphabet.Add('N', 14);
                        alphabet.Add('O', 15);
                        alphabet.Add('P', 16);
                        alphabet.Add('Q', 17);
                        alphabet.Add('R', 18);
                        alphabet.Add('S', 19);
                        alphabet.Add('T', 20);
                        alphabet.Add('U', 21);
                        alphabet.Add('V', 22);
                        alphabet.Add('W', 23);
                        alphabet.Add('X', 24);
                        alphabet.Add('Y', 25);
                        alphabet.Add('Z', 26);
                    
                    }
                    
                    public static int Position(char letter)
                    {
                        return alphabet\[letter\];
                    }
                    

                    }

                    Prizes awarded to anyone who can find a more pointless use of a lookup table.

                    K Offline
                    K Offline
                    kmoorevs
                    wrote on last edited by
                    #16

                    :thumbsup: Nice find and thanks for sharing! I feel better now! :laugh:

                    "Go forth into the source" - Neal Morse

                    1 Reply Last reply
                    0
                    • R Rotted Frog

                      Just found this gem hiding in a project I've just inherited. Fortunately it doesn't appear to be used.

                      public class AlphabetPositionMap
                      {
                      private static Dictionary<char, int> alphabet = new Dictionary<char, int>();

                      static AlphabetPositionMap()
                      {
                          alphabet.Add('A', 1);
                          alphabet.Add('B', 2);
                          alphabet.Add('C', 3);
                          alphabet.Add('D', 4);
                          alphabet.Add('E', 5);
                          alphabet.Add('F', 6);
                          alphabet.Add('G', 7);
                          alphabet.Add('H', 8);
                          alphabet.Add('I', 9);
                          alphabet.Add('J', 10);
                          alphabet.Add('K', 11);
                          alphabet.Add('L', 12);
                          alphabet.Add('M', 13);
                          alphabet.Add('N', 14);
                          alphabet.Add('O', 15);
                          alphabet.Add('P', 16);
                          alphabet.Add('Q', 17);
                          alphabet.Add('R', 18);
                          alphabet.Add('S', 19);
                          alphabet.Add('T', 20);
                          alphabet.Add('U', 21);
                          alphabet.Add('V', 22);
                          alphabet.Add('W', 23);
                          alphabet.Add('X', 24);
                          alphabet.Add('Y', 25);
                          alphabet.Add('Z', 26);
                      
                      }
                      
                      public static int Position(char letter)
                      {
                          return alphabet\[letter\];
                      }
                      

                      }

                      Prizes awarded to anyone who can find a more pointless use of a lookup table.

                      P Offline
                      P Offline
                      PIEBALDconsult
                      wrote on last edited by
                      #17

                      How about adding another lookup that gets the uppercase equivalent of a lowercase letter?

                      L 1 Reply Last reply
                      0
                      • V V 0

                        how about :

                        public class NumberMap
                        {
                        private static Dictionary number = new Dictionary();

                        static NumberMap()
                        {
                            number.Add('1', 1);
                            number.Add('2', 2);
                            number.Add('3', 3);
                            number.Add('4', 4);
                            number.Add('5', 5);
                            number.Add('6', 6);
                            number.Add('7', 7);
                            number.Add('8', 8);
                            number.Add('9', 9);
                            number.Add('0', 0);
                        }
                        

                        }

                        V.
                        (MQOTD rules and previous solutions)

                        S Offline
                        S Offline
                        Sascha Lefevre
                        wrote on last edited by
                        #18

                        Even more bonus points for a pointless lookup table for not being able to actually do a lookup :laugh:

                        If the brain were so simple we could understand it, we would be so simple we couldn't. — Lyall Watson

                        V 1 Reply Last reply
                        0
                        • P PIEBALDconsult

                          How about adding another lookup that gets the uppercase equivalent of a lowercase letter?

                          L Offline
                          L Offline
                          Lost User
                          wrote on last edited by
                          #19

                          AlphabetPositionMap seems to have a brother called ZeroBasedAlphabetPositionMap[^]. Yes, it is missing lowercaps variants, meaning there should at least be four of these methods. And globalization is missed completely. Scheiß drauf.

                          Bastard Programmer from Hell :suss: If you can't read my code, try converting it here[^][](X-Clacks-Overhead: GNU Terry Pratchett)

                          1 Reply Last reply
                          0
                          • R Rotted Frog

                            Just found this gem hiding in a project I've just inherited. Fortunately it doesn't appear to be used.

                            public class AlphabetPositionMap
                            {
                            private static Dictionary<char, int> alphabet = new Dictionary<char, int>();

                            static AlphabetPositionMap()
                            {
                                alphabet.Add('A', 1);
                                alphabet.Add('B', 2);
                                alphabet.Add('C', 3);
                                alphabet.Add('D', 4);
                                alphabet.Add('E', 5);
                                alphabet.Add('F', 6);
                                alphabet.Add('G', 7);
                                alphabet.Add('H', 8);
                                alphabet.Add('I', 9);
                                alphabet.Add('J', 10);
                                alphabet.Add('K', 11);
                                alphabet.Add('L', 12);
                                alphabet.Add('M', 13);
                                alphabet.Add('N', 14);
                                alphabet.Add('O', 15);
                                alphabet.Add('P', 16);
                                alphabet.Add('Q', 17);
                                alphabet.Add('R', 18);
                                alphabet.Add('S', 19);
                                alphabet.Add('T', 20);
                                alphabet.Add('U', 21);
                                alphabet.Add('V', 22);
                                alphabet.Add('W', 23);
                                alphabet.Add('X', 24);
                                alphabet.Add('Y', 25);
                                alphabet.Add('Z', 26);
                            
                            }
                            
                            public static int Position(char letter)
                            {
                                return alphabet\[letter\];
                            }
                            

                            }

                            Prizes awarded to anyone who can find a more pointless use of a lookup table.

                            P Offline
                            P Offline
                            PaulLinton
                            wrote on last edited by
                            #20

                            I thought I had a more useless lookup table, but I was wrong

                            private static Dictionary alphabet = new Dictionary();
                            static AlphabetPositionMap()
                            {
                            alphabet['A'] = 'A';
                            alphabet['B'] = 'B';
                            // you get the idea
                            }

                            I am wrong because it is only a small step from this code to creating an Enigma machine in software, which I believe had some amount of use a few years back. Failed at being useless :sigh:

                            1 Reply Last reply
                            0
                            • S Sascha Lefevre

                              Even more bonus points for a pointless lookup table for not being able to actually do a lookup :laugh:

                              If the brain were so simple we could understand it, we would be so simple we couldn't. — Lyall Watson

                              V Offline
                              V Offline
                              V 0
                              wrote on last edited by
                              #21

                              It's all in the wrist baby ;P

                              V.
                              (MQOTD rules and previous solutions)

                              1 Reply Last reply
                              0
                              • R Rotted Frog

                                Just found this gem hiding in a project I've just inherited. Fortunately it doesn't appear to be used.

                                public class AlphabetPositionMap
                                {
                                private static Dictionary<char, int> alphabet = new Dictionary<char, int>();

                                static AlphabetPositionMap()
                                {
                                    alphabet.Add('A', 1);
                                    alphabet.Add('B', 2);
                                    alphabet.Add('C', 3);
                                    alphabet.Add('D', 4);
                                    alphabet.Add('E', 5);
                                    alphabet.Add('F', 6);
                                    alphabet.Add('G', 7);
                                    alphabet.Add('H', 8);
                                    alphabet.Add('I', 9);
                                    alphabet.Add('J', 10);
                                    alphabet.Add('K', 11);
                                    alphabet.Add('L', 12);
                                    alphabet.Add('M', 13);
                                    alphabet.Add('N', 14);
                                    alphabet.Add('O', 15);
                                    alphabet.Add('P', 16);
                                    alphabet.Add('Q', 17);
                                    alphabet.Add('R', 18);
                                    alphabet.Add('S', 19);
                                    alphabet.Add('T', 20);
                                    alphabet.Add('U', 21);
                                    alphabet.Add('V', 22);
                                    alphabet.Add('W', 23);
                                    alphabet.Add('X', 24);
                                    alphabet.Add('Y', 25);
                                    alphabet.Add('Z', 26);
                                
                                }
                                
                                public static int Position(char letter)
                                {
                                    return alphabet\[letter\];
                                }
                                

                                }

                                Prizes awarded to anyone who can find a more pointless use of a lookup table.

                                I Offline
                                I Offline
                                imagiro
                                wrote on last edited by
                                #22

                                ... the map is static...

                                1 Reply Last reply
                                0
                                • V V 0

                                  how about :

                                  public class NumberMap
                                  {
                                  private static Dictionary number = new Dictionary();

                                  static NumberMap()
                                  {
                                      number.Add('1', 1);
                                      number.Add('2', 2);
                                      number.Add('3', 3);
                                      number.Add('4', 4);
                                      number.Add('5', 5);
                                      number.Add('6', 6);
                                      number.Add('7', 7);
                                      number.Add('8', 8);
                                      number.Add('9', 9);
                                      number.Add('0', 0);
                                  }
                                  

                                  }

                                  V.
                                  (MQOTD rules and previous solutions)

                                  G Offline
                                  G Offline
                                  GuyThiebaut
                                  wrote on last edited by
                                  #23

                                  I've noticed that you do not cover lowercase numbers.

                                  “That which can be asserted without evidence, can be dismissed without evidence.”

                                  ― Christopher Hitchens

                                  V 1 Reply Last reply
                                  0
                                  • G GuyThiebaut

                                    I've noticed that you do not cover lowercase numbers.

                                    “That which can be asserted without evidence, can be dismissed without evidence.”

                                    ― Christopher Hitchens

                                    V Offline
                                    V Offline
                                    V 0
                                    wrote on last edited by
                                    #24

                                    There is a seperate uppercase number lookup table for that ! :laugh:

                                    V.
                                    (MQOTD rules and previous solutions)

                                    G 1 Reply Last reply
                                    0
                                    • V V 0

                                      There is a seperate uppercase number lookup table for that ! :laugh:

                                      V.
                                      (MQOTD rules and previous solutions)

                                      G Offline
                                      G Offline
                                      GuyThiebaut
                                      wrote on last edited by
                                      #25

                                      I was thinking more of something like "1".tolower might work.

                                      “That which can be asserted without evidence, can be dismissed without evidence.”

                                      ― Christopher Hitchens

                                      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