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. Neither is this a programming question.

Neither is this a programming question.

Scheduled Pinned Locked Moved The Lounge
questioncsharphelp
16 Posts 9 Posters 3 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.
  • K Kyle Sponable

    Sorry I was completely wrong, you need to know how many items to initialize the arrays, umm well couldn't you store in a linked list and then iterate through the entries with a counter?

    B Offline
    B Offline
    Brady Kelly
    wrote on last edited by
    #6

    Surely there must be a mathematical answer? I keep getting distracted to try and work it out anyway, so I'm trying again.

    1 Reply Last reply
    0
    • B Brady Kelly

      It's an arithmetic question, and I'm feeling very dense for asking it, but I have coding to get on with and haven't time to play with arithmetic, i.e. for two columns my problem is solved, and I move on. But, let's say I have x items and y columns. How do I determine the maximum number of items per column? I said I was feeling dense. :doh: I'm just going to carry on with simple C# for the remainder of the evening. ;P

      G Offline
      G Offline
      Gary Wheeler
      wrote on last edited by
      #7

      With x total items, and y columns:

      int x,y;
      int items_per_column;
       
      items_per_column = x / y;
      if ((x % y) != 0) items_per_column += 1;

      Software Zen: delete this;

      C 1 Reply Last reply
      0
      • L Lost User

        Math.Ceiling(x/y) ??

        B Offline
        B Offline
        Brady Kelly
        wrote on last edited by
        #8

        Sweet, thanks! :thumbsup: Now for real man points, how do does one do that with integer arithmetic?

        L M 2 Replies Last reply
        0
        • B Brady Kelly

          Sweet, thanks! :thumbsup: Now for real man points, how do does one do that with integer arithmetic?

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

          Convert.ToInt32(x/y)+1 :) Edit, don't use convert, it rounds up if remainder is greater than .5, just use simple division, that discards the remainder

          1 Reply Last reply
          0
          • G Gary Wheeler

            With x total items, and y columns:

            int x,y;
            int items_per_column;
             
            items_per_column = x / y;
            if ((x % y) != 0) items_per_column += 1;

            Software Zen: delete this;

            C Offline
            C Offline
            CPallini
            wrote on last edited by
            #10

            In my columnless house your program is buggy. :rolleyes:

            If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler. -- Alfonso the Wise, 13th Century King of Castile.
            This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong. -- Iain Clarke
            [My articles]

            G 1 Reply Last reply
            0
            • B Brady Kelly

              Sweet, thanks! :thumbsup: Now for real man points, how do does one do that with integer arithmetic?

              M Offline
              M Offline
              Manfred Rudolf Bihy
              wrote on last edited by
              #11

              int x = 113;
              int y = 23:

              // Making sure x is evenly divisable by y
              // So to speak Math.Ceiling for integer division
              int r = (x + (y - x % y)) / y;

              Cheers!

              —MRB

              "With sufficient thrust, pigs fly just fine."

              Ross Callon, The Twelve Networking Truths, RFC1925

              B 1 Reply Last reply
              0
              • B Brady Kelly

                It's an arithmetic question, and I'm feeling very dense for asking it, but I have coding to get on with and haven't time to play with arithmetic, i.e. for two columns my problem is solved, and I move on. But, let's say I have x items and y columns. How do I determine the maximum number of items per column? I said I was feeling dense. :doh: I'm just going to carry on with simple C# for the remainder of the evening. ;P

                N Offline
                N Offline
                Not Active
                wrote on last edited by
                #12

                The answer is always 42


                No comment

                1 Reply Last reply
                0
                • M Manfred Rudolf Bihy

                  int x = 113;
                  int y = 23:

                  // Making sure x is evenly divisable by y
                  // So to speak Math.Ceiling for integer division
                  int r = (x + (y - x % y)) / y;

                  Cheers!

                  —MRB

                  "With sufficient thrust, pigs fly just fine."

                  Ross Callon, The Twelve Networking Truths, RFC1925

                  B Offline
                  B Offline
                  Brady Kelly
                  wrote on last edited by
                  #13

                  Thank you, have some points! :rose:

                  1 Reply Last reply
                  0
                  • C CPallini

                    In my columnless house your program is buggy. :rolleyes:

                    If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler. -- Alfonso the Wise, 13th Century King of Castile.
                    This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong. -- Iain Clarke
                    [My articles]

                    G Offline
                    G Offline
                    Gary Wheeler
                    wrote on last edited by
                    #14

                    int x,y;
                    int items_per_column;

                    if (y != 0)
                    {
                    items_per_column = x / y;
                    if ((x % y) != 0) items_per_column += 1;
                    }
                    else
                    {
                    items_per_column = x; // for lack of anything better to do
                    }

                    Bitch, bitch, bitch...

                    Software Zen: delete this;

                    C 1 Reply Last reply
                    0
                    • G Gary Wheeler

                      int x,y;
                      int items_per_column;

                      if (y != 0)
                      {
                      items_per_column = x / y;
                      if ((x % y) != 0) items_per_column += 1;
                      }
                      else
                      {
                      items_per_column = x; // for lack of anything better to do
                      }

                      Bitch, bitch, bitch...

                      Software Zen: delete this;

                      C Offline
                      C Offline
                      CPallini
                      wrote on last edited by
                      #15

                      Nope, Nope, Nope!

                      if (y != 0)
                      {
                      items_per_column = x / y;
                      if ((x % y) != 0) items_per_column += 1;
                      }
                      else if ( x != 0)
                      {
                      items_per_column = IM_SORRY_JACK_WE_NEED_MORE_MEMORY_FOR_INTEGERS;
                      }
                      else
                      {
                      items_per_column = PLEASE_PICK_ONE_OR_ANOTHER_OR;
                      }

                      :laugh:

                      If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler. -- Alfonso the Wise, 13th Century King of Castile.
                      This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong. -- Iain Clarke
                      [My articles]

                      G 1 Reply Last reply
                      0
                      • C CPallini

                        Nope, Nope, Nope!

                        if (y != 0)
                        {
                        items_per_column = x / y;
                        if ((x % y) != 0) items_per_column += 1;
                        }
                        else if ( x != 0)
                        {
                        items_per_column = IM_SORRY_JACK_WE_NEED_MORE_MEMORY_FOR_INTEGERS;
                        }
                        else
                        {
                        items_per_column = PLEASE_PICK_ONE_OR_ANOTHER_OR;
                        }

                        :laugh:

                        If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler. -- Alfonso the Wise, 13th Century King of Castile.
                        This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong. -- Iain Clarke
                        [My articles]

                        G Offline
                        G Offline
                        Gary Wheeler
                        wrote on last edited by
                        #16

                        int x,y;
                        int items_per_column;

                        if (y > 0)
                        {
                        items_per_column = x / y;
                        if ((x % y) != 0) items_per_column += 1;
                        }
                        else if (y < 0)
                        {
                        throw new WTF_Exception();
                        }
                        else
                        {
                        throw new YourePissingMeOffException();
                        }

                        Software Zen: delete this;

                        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