• Log InLog In
  • Register
Liquid`
Team Liquid Liquipedia
EDT 11:31
CEST 17:31
KST 00:31
  • Home
  • Forum
  • Calendar
  • Streams
  • Liquipedia
  • Features
  • Store
  • EPT
  • TL+
  • StarCraft 2
  • Brood War
  • Smash
  • Heroes
  • Counter-Strike
  • Overwatch
  • Liquibet
  • Fantasy StarCraft
  • TLPD
  • StarCraft 2
  • Brood War
  • Blogs
Forum Sidebar
Events/Features
News
Featured News
Team Liquid Map Contest #22 - The Finalists14[ASL21] Ro16 Preview Pt1: Fresh Flow9[ASL21] Ro24 Preview Pt2: News Flash10[ASL21] Ro24 Preview Pt1: New Chaos0Team Liquid Map Contest #22 - Presented by Monster Energy21
Community News
2026 GSL Season 1 Qualifiers11Maestros of the Game 2 announced32026 GSL Tour plans announced11Weekly Cups (April 6-12): herO doubles, "Villains" prevail1MaNa leaves Team Liquid22
StarCraft 2
General
MaNa leaves Team Liquid 2026 GSL Tour plans announced Team Liquid Map Contest #22 - The Finalists Weekly Cups (April 6-12): herO doubles, "Villains" prevail Oliveira Would Have Returned If EWC Continued
Tourneys
Sparkling Tuna Cup - Weekly Open Tournament GSL CK: More events planned pending crowdfunding 2026 GSL Season 1 Qualifiers Master Swan Open (Global Bronze-Master 2) SEL Doubles (SC Evo Bimonthly)
Strategy
Custom Maps
[D]RTS in all its shapes and glory <3 [A] Nemrods 1/4 players [M] (2) Frigid Storage
External Content
The PondCast: SC2 News & Results Mutation # 521 Memorable Boss Mutation # 520 Moving Fees Mutation # 519 Inner Power
Brood War
General
Gypsy to Korea ASL21 General Discussion BGH Auto Balance -> http://bghmmr.eu/ Pros React To: Tulbo in Ro.16 Group A Data needed
Tourneys
Escore Tournament StarCraft Season 2 [Megathread] Daily Proleagues [ASL21] Ro16 Group A [ASL21] Ro16 Group B
Strategy
Simple Questions, Simple Answers What's the deal with APM & what's its true value Any training maps people recommend? Fighting Spirit mining rates
Other Games
General Games
Nintendo Switch Thread General RTS Discussion Thread Battle Aces/David Kim RTS Megathread Stormgate/Frost Giant Megathread Starcraft Tabletop Miniature Game
Dota 2
The Story of Wings Gaming
League of Legends
G2 just beat GenG in First stand
Heroes of the Storm
Simple Questions, Simple Answers Heroes of the Storm 2.0
Hearthstone
Deck construction bug Heroes of StarCraft mini-set
TL Mafia
Vanilla Mini Mafia Mafia Game Mode Feedback/Ideas TL Mafia Community Thread Five o'clock TL Mafia
Community
General
Things Aren’t Peaceful in Palestine US Politics Mega-thread Russo-Ukrainian War Thread YouTube Thread Canadian Politics Mega-thread
Fan Clubs
The IdrA Fan Club
Media & Entertainment
Anime Discussion Thread [Req][Books] Good Fantasy/SciFi books [Manga] One Piece Movie Discussion!
Sports
2024 - 2026 Football Thread McBoner: A hockey love story Formula 1 Discussion Cricket [SPORT]
World Cup 2022
Tech Support
[G] How to Block Livestream Ads
TL Community
The Automated Ban List
Blogs
Reappraising The Situation T…
TrAiDoS
lurker extra damage testi…
StaticNine
Broowar part 2
qwaykee
Funny Nicknames
LUCKY_NOOB
Iranian anarchists: organize…
XenOsky
ASL S21 English Commentary…
namkraft
Customize Sidebar...

Website Feedback

Closed Threads



Active: 2185 users

The Big Programming Thread - Page 373

Forum Index > General Forum
Post a Reply
Prev 1 371 372 373 374 375 1032 Next
Thread Rules
1. This is not a "do my homework for me" thread. If you have specific questions, ask, but don't post an assignment or homework problem and expect an exact solution.
2. No recruiting for your cockamamie projects (you won't replace facebook with 3 dudes you found on the internet and $20)
3. If you can't articulate why a language is bad, don't start slinging shit about it. Just remember that nothing is worse than making CSS IE6 compatible.
4. Use [code] tags to format code blocks.
RoyGBiv_13
Profile Blog Joined August 2010
United States1275 Posts
October 15 2013 22:55 GMT
#7441
On October 16 2013 07:43 misirlou wrote:
Show nested quote +
On October 16 2013 07:08 obesechicken13 wrote:
I'm doing a student project management website project for school capstone. Has anyone ever made/seen one of these for student groups before? Has anyone used one?

We're considering using Ruby because we hear it is newer and shinier than PHP or ASP.net. We know PHP and Asp.net already.

What hosts are free and available for this? I'm considering Heroku and Amazon and Sitegrounds. Siteground only has it for very expensive dedicated hosting and still seems new to providing ruby support. Heroku is free but I'm worried about speed and scalability. Amazon is cheap for development purposes but I'm worried about scalability in the future.


Don't you want to use something like Redmine or gitlab? I don't like ruby but my college uses Redmine (they started using Trac on some courses this year but I think it's still new and buggy), me and some students formed a student group for extra-curricular developement so we needed a way to manage the projects and source repos on our own private server (college redmine only teachers can create projects and assign students, its easier if we could do everything we wanted), so we deployed redmine there under <host>/redmine and we modified the project creation source so it would also automatically create a bare git repo on the server under /srv/git/reponame that we can acess through https://host/git/reponame .
Redmine does this natively for SVN IIRC but we wanted to use git instead.


Though not free, I use and love Digital Ocean for cheap, good virtual private servers. Amazon also has a free tier, and most of these companies will subsidize you if you e-mail them, CC'ing a teacher/professor.
Any sufficiently advanced technology is indistinguishable from magic
obesechicken13
Profile Blog Joined July 2008
United States10467 Posts
Last Edited: 2013-10-15 22:59:44
October 15 2013 22:58 GMT
#7442
On October 16 2013 07:43 misirlou wrote:
Show nested quote +
On October 16 2013 07:08 obesechicken13 wrote:
I'm doing a student project management website project for school capstone. Has anyone ever made/seen one of these for student groups before? Has anyone used one?

We're considering using Ruby because we hear it is newer and shinier than PHP or ASP.net. We know PHP and Asp.net already.

What hosts are free and available for this? I'm considering Heroku and Amazon and Sitegrounds. Siteground only has it for very expensive dedicated hosting and still seems new to providing ruby support. Heroku is free but I'm worried about speed and scalability. Amazon is cheap for development purposes but I'm worried about scalability in the future.


Don't you want to use something like Redmine or gitlab? I don't like ruby but my college uses Redmine (they started using Trac on some courses this year but I think it's still new and buggy), me and some students formed a student group for extra-curricular developement so we needed a way to manage the projects and source repos on our own private server (college redmine only teachers can create projects and assign students, its easier if we could do everything we wanted), so we deployed redmine there under <host>/redmine and we modified the project creation source so it would also automatically create a bare git repo on the server under /srv/git/reponame that we can acess through https://host/git/reponame .
Redmine does this natively for SVN IIRC but we wanted to use git instead.

I guess so. It should be similar to redmine except more tailored towards students. So it might integrate tools such as

Gradetracker http://www.gradetracker.com/
And have some advice from upper year students for courses
And perhaps integration of irc chat rooms for courses

One of the self defined constraints of our project is that the software must be free to use so I think we might be able to start with redmine as a base.
I think in our modern age technology has evolved to become more addictive. The things that don't give us pleasure aren't used as much. Work was never meant to be fun, but doing it makes us happier in the long run.
misirlou
Profile Joined June 2010
Portugal3292 Posts
October 16 2013 00:15 GMT
#7443
On October 16 2013 07:58 obesechicken13 wrote:
Show nested quote +
On October 16 2013 07:43 misirlou wrote:
On October 16 2013 07:08 obesechicken13 wrote:
I'm doing a student project management website project for school capstone. Has anyone ever made/seen one of these for student groups before? Has anyone used one?

We're considering using Ruby because we hear it is newer and shinier than PHP or ASP.net. We know PHP and Asp.net already.

What hosts are free and available for this? I'm considering Heroku and Amazon and Sitegrounds. Siteground only has it for very expensive dedicated hosting and still seems new to providing ruby support. Heroku is free but I'm worried about speed and scalability. Amazon is cheap for development purposes but I'm worried about scalability in the future.


Don't you want to use something like Redmine or gitlab? I don't like ruby but my college uses Redmine (they started using Trac on some courses this year but I think it's still new and buggy), me and some students formed a student group for extra-curricular developement so we needed a way to manage the projects and source repos on our own private server (college redmine only teachers can create projects and assign students, its easier if we could do everything we wanted), so we deployed redmine there under <host>/redmine and we modified the project creation source so it would also automatically create a bare git repo on the server under /srv/git/reponame that we can acess through https://host/git/reponame .
Redmine does this natively for SVN IIRC but we wanted to use git instead.

I guess so. It should be similar to redmine except more tailored towards students. So it might integrate tools such as

Gradetracker http://www.gradetracker.com/
And have some advice from upper year students for courses
And perhaps integration of irc chat rooms for courses

One of the self defined constraints of our project is that the software must be free to use so I think we might be able to start with redmine as a base.

Hm, redmine is more Project oriented, maybe something like moodle would be more Course oriented since thats what it seems you want. If you do use the redmine, for the advice part, you can have students make a wiki page on the project, "advices for future students" where they would just talk about their experience, mistakes and achievements, if the project is public, other students can see it.
sob3k
Profile Blog Joined August 2009
United States7572 Posts
October 16 2013 01:22 GMT
#7444
On October 16 2013 05:52 Manit0u wrote:
Show nested quote +
On October 16 2013 03:21 sob3k wrote:
So now I have that cloud image moving on the screen but when it goes off of the edge of the site it extends the site and makes the scrollbar shrink etc. How do I make this not happen? I tried setting the overflow on the cloud to hidden but that was not effective.


Put it in a container and give the container the max-width property?


This doesn't seem to work. I tried it on the body to no effect.


On October 16 2013 07:48 Encdalf wrote:
Show nested quote +
On October 16 2013 03:21 sob3k wrote:
So now I have that cloud image moving on the screen but when it goes off of the edge of the site it extends the site and makes the scrollbar shrink etc. How do I make this not happen? I tried setting the overflow on the cloud to hidden but that was not effective.

overflow: hidden needs to be set on the container, not the element. If your cloud image is absolute, and no div around it, you need to set it to the body


This isn't working either. It cuts of overflow when the site is rendered initially, but then as objects move over the edge later they stretch the width just like before.
In Hungry Hungry Hippos there are no such constraints—one can constantly attempt to collect marbles with one’s hippo, limited only by one’s hippo-levering capabilities.
sob3k
Profile Blog Joined August 2009
United States7572 Posts
October 16 2013 01:23 GMT
#7445
Also, what is a method to make sure images of variable widths start completely off the screen on one side and move completely off of the screen on the other, regardless of screen size/res?
In Hungry Hungry Hippos there are no such constraints—one can constantly attempt to collect marbles with one’s hippo, limited only by one’s hippo-levering capabilities.
Rotodyne
Profile Blog Joined July 2005
United States2263 Posts
Last Edited: 2013-10-16 04:37:22
October 16 2013 04:35 GMT
#7446
On October 16 2013 10:23 sob3k wrote:
Also, what is a method to make sure images of variable widths start completely off the screen on one side and move completely off of the screen on the other, regardless of screen size/res?


This should fix the scroll bar problem
html {
overflow:hidden;
}


If you put a container around the image:

.container {
width: 100%;
}


Then you can do
 left: -50px 
on cloud1 to get the image -50px off the left of the page
I can only play starcraft when I am shit canned. IPXZERG is a god.
sob3k
Profile Blog Joined August 2009
United States7572 Posts
October 16 2013 05:57 GMT
#7447
On October 16 2013 13:35 Rotodyne wrote:
Show nested quote +
On October 16 2013 10:23 sob3k wrote:
Also, what is a method to make sure images of variable widths start completely off the screen on one side and move completely off of the screen on the other, regardless of screen size/res?


This should fix the scroll bar problem
html {
overflow:hidden;
}


If you put a container around the image:

.container {
width: 100%;
}


Then you can do
 left: -50px 
on cloud1 to get the image -50px off the left of the page


i'll try that now, but how do I make sure they go all the way off the right side?

hmm Maybe I'll try a calc(image width+100%) that sounds like it would work.
In Hungry Hungry Hippos there are no such constraints—one can constantly attempt to collect marbles with one’s hippo, limited only by one’s hippo-levering capabilities.
Tobberoth
Profile Joined August 2010
Sweden6375 Posts
October 16 2013 06:48 GMT
#7448
On October 16 2013 07:08 obesechicken13 wrote:
We're considering using Ruby because we hear it is newer and shinier than PHP or ASP.net. We know PHP and Asp.net already.

Ruby on Rails is fine to use if you want to experience something new, but I wouldn't say it's "newer and shinier" than ASP.net. It IS newer of course, but if you're talking how to work with it, ASP.NET MVC is more or less the same and will probably be far more comfortable when coming from an ASP.NET background.

My personal opinion is that Ruby on Rails is more of a buzzword. There's more interesting things to try nowadays if you just want something "new and shiny", like node.js or barebones and similar javascript MVC frameworks.
Nesserev
Profile Blog Joined January 2011
Belgium2760 Posts
October 16 2013 07:15 GMT
#7449
--- Nuked ---
spinesheath
Profile Blog Joined June 2009
Germany8679 Posts
Last Edited: 2013-10-16 12:39:35
October 16 2013 08:12 GMT
#7450
I'm a bit short of time right now, so I can't go into much detail, but I probably will do so later today. It's really not important for my question.

What I want is some papers about how things like permutations affect minimized dfa size. Or similar things, just to have a starting point from which I can follow citations etc.

In short, shanten is a measure for the least number of draws you need to make before you can win a hand in Mahjong. I can give you a couple of links and a formal definition I once developed later.
A hand consists of 13 tiles out of a total of 136 tiles (thus you can imagine how large the number of possible hands is and why the monolithic state machine is no good).

The largest dfa I have right now has something like 600,000 states and an alphabet size of 5, so a table of about 3,000,000 ints. I'm not concerned about performance or size here though, eve though a smaller size would likely reduce the number of cache misses.

I'll describe the algorithm in detail later, too. For now: I split the hand in 4 parts, apply one of 2 dfas for each part, concatenate the results (classifying dfa), and use that as the input for the last dfa which has the shanten number as the result.

I'd certainly interested in suggestions what I could use other than dfas. Maybe there is something better, I have no idea. But I realize you would need some more information before that.


This is going to be long, and there will likely still be plenty of unclear things.
+ Show Spoiler +

In Mahjong, Riichi Mahjing to be precise, the Japanese variant, you start with a hand of 13 tiles and each turn a player draws and then discards a tile. A hand can only be won when you have 14 tiles, the last tile can either be drawn or called from an opponent's discard. You can also call a meld, a certain combination of 3 or 4 tiles, which is then immutable. A meld always is the equivalent of 3 tiles in your hand, even though some melds (kan) use up 4 tiles. You get a replacement for the extra tile. A hand can be won with the standard combination of a pair and 4 melds (both called or sitting in your hand) or with one of two special combinations (which are trivial and dealt with in a seperate way, so I ignore them here).

Turns out I cant find a link in my bookmarks where shanten is explained properly. The definition "number of tiles needed to reach tenpai" is simple, where a hand is tenpai when it is just 1 draw away from having a pair and 4 melds.
Here is the rather formal definition of shanten; I used a couple of natural language constructs that should be obvious. Since this is so complex I might have made a mistake here or there. It's not like this definition is really useable anyways.
+ Show Spoiler +
colors = { 1, 2, 3 }
color_number = { 1, ... , 9 }
color_types = { (c, n) : c ∈ colors ∧ n ∈ color_numbers }
honor_types = { 1, ... , 7 }
types = color_types ∪ honor_types
tiles = { (y, i) : y ∈ types ∧ i ∈ { 1, 2, 3, 4 } }
pairs = { p ⊂ tiles : |p| = 2 ∧ all t ∈ p same type }
koutsus = { k ⊂ tiles : |k| = 3 ∧ all t ∈ k same type }
kans = { a ⊂ tiles : |a| = 4 ∧ all t ∈ a same type }
shuntsus = { s ⊂ tiles : |s| = 3 ∧ all t ∈ s of color_types of same color
∧ s = { t1, t2, t3 }, t1.y.n = t2.y.n + 1 = t3.y.n + 2 }
melds = koutsus ∪ kans ∪ shuntsus
hands = { (d, m) : d ⊂ tiles ∧ m ⊂ melds ∧ no duplicate tiles ∧ |d| + |m| * 3 = 13 }
tenpai_hands = { h ⊂ hands : exists (p, e), p ∈ pairs, e ⊂ melds
∧ |e| + |h.m| = 4 ∧ exists z ∈ (p ∪ each f ∈ e) such that h.d = (p ∪ each f ∈ e) / z }
shanten: hand -> Z: shanten(h) = min |r|, ((h.d ∪ r) / u, h.m) ∈ tenpai_hands,
r, u ⊂ tiles, |r| = |u|

The gist of it is that I am trying to find the least number of tiles I have to replace in a hand to be one away from a pair and 4 melds, but since there are different kinds of melds (koutsu and kan have 3 or 4 tiles of the same type, shuntsu has 3 tiles of the same color in with ascending numbers n, n+1, n+2) and melds can be called, rendering them immutable, this creates a very complex recursive algorithm.


Anyways, on to my actual algorithm.
I group the tiles of an input hand by the three colors and a group of honors. I flip/order the tiles inside each group to abuse symmetries. Then I order these groups by their size. The smallest group can range from 0 to 3 tiles, while the largest group can range from 4 to 13 tiles. For each of the 4 sizes (smallest to largest) I have one dfa for colors and one for honors. Ordering them like that reduces the size of the result sets which is important for the second part.

The base languages for step 1 have an alphabet of {0, 1, 2, 3, 4} which is the multiplicity of a tile type in the current group. Each word is made up of 7 or 9 (for honors or colors respectively) letters for the tiles in called melds, 7 or 9 letters for the closed part of the hand, and 1 letter for the number of called melds. I compact these words before putting them through the dfa by eliminating letters that can only assume a single character and reordering them in a way that probably (according to anecdotal evidence) reduces the size the of the dfa.

Each of these words has a value which I call an arrangementList. An arrangement is a triplet (pair_count, meld_count, value), and there are less than 60 potential arrangements. An arrangement basically says that I could assign x pairs and y melds (of the 1 pair and 4 melds I can have total in a hand) to this color group and then it would contain value tiles that would not have to be replaced to get to tenpai. If I can reach a sum of z across the values of the arrangements of the 4 color/honor groups then I have a hand of 13 - z shanten.

Sadly I don't have a complete ordering on these arrangements, only a partial ordering is possible. Because of this, the value of each word is a list of possible arrangements, and to find the final shanten of a hand, I have to iterate over all possible combinations of elements from the 4 arrangementLists and find the optimal combination. I really don't want to do that. So I encode the arrangementList as a binary word where the nth letter says whether the arrangement with the id n applies for this group.

The result of the first phase of my algorithm therefore is 4 binary words representing the arrangements of the 4 groups in a hand. Each size group can only assume a subset of arrangements, which I take advantage of and again compact the binary words before concatenating them and inserting them into the last dfa (this cuts the concatenated length by over 50%). The result of this dfa is the shanten number.
If you have a good reason to disagree with the above, please tell me. Thank you.
heroyi
Profile Blog Joined March 2009
United States1064 Posts
Last Edited: 2013-10-16 13:32:33
October 16 2013 13:30 GMT
#7451
I has but two simple C questions

one: I understand what const array does (doesnt allow you to modify values in array) but if that is the case (when using arrays as a parameter) then what situation would call for its use? The only reason I can think of on the top of my head is that you want to (if this is even viable) use the function to make a dynamic array. Personally I think I am wrong on that logic but I still can't see the reason of the point of using the const if you don't want to change the array when using it as a parameter.

two:
simple program but I am running into a roadblock. No, this is not a hw assignment. Besides, I just help on the control flow. The program question is you are making a program to reserve seats on a small airplane of 10 seats. If user types 1, then that is a first class seat (seats 1-5) while 2 is economy(seats 6-10). If someone reserves a seat than it is taken and if all the seats are taken for a class then you ask whether they want an empty seat in the other class.

I don't understand how one could check if the seat is taken and how would you check if all the seats are taken to prompt the user if they want the other class. Also, how would you check if all the seats are taken. I am stuck on how to initalize the array so that I can just check if seat is taken and if it isn't go reserve it and break from there. Keep in mind we have not gone over pointers yet. An example (of just the first half of loop as the other half would be the exact same copy other than it being 2 as for the other class):

printf("type one or two: ")
scanf("%d",&choice)

if(choice==1)
{???
if (array[i]!=1)
{
printf("first class seat number: %d", array[i])
array[i]=1
}
}
...

wat wat in my pants
Tobberoth
Profile Joined August 2010
Sweden6375 Posts
October 16 2013 13:47 GMT
#7452
On October 16 2013 22:30 heroyi wrote:
one: I understand what const array does (doesnt allow you to modify values in array) but if that is the case (when using arrays as a parameter) then what situation would call for its use? The only reason I can think of on the top of my head is that you want to (if this is even viable) use the function to make a dynamic array. Personally I think I am wrong on that logic but I still can't see the reason of the point of using the const if you don't want to change the array when using it as a parameter.

Say you have an array of integers you want to do some calculations on and then return a scalar value. So you make a "CalculateValue" function which takes an array. You want to make sure that the array is not changed by the function, because side effects lead to bugs which are hard to debug, so you make it const.

It's really just clarification and safety.
Rannasha
Profile Blog Joined August 2010
Netherlands2398 Posts
Last Edited: 2013-10-16 14:40:03
October 16 2013 14:38 GMT
#7453
Since question 1 was already answered...

On October 16 2013 22:30 heroyi wrote:
two:
simple program but I am running into a roadblock. No, this is not a hw assignment. Besides, I just help on the control flow. The program question is you are making a program to reserve seats on a small airplane of 10 seats. If user types 1, then that is a first class seat (seats 1-5) while 2 is economy(seats 6-10). If someone reserves a seat than it is taken and if all the seats are taken for a class then you ask whether they want an empty seat in the other class.

I don't understand how one could check if the seat is taken and how would you check if all the seats are taken to prompt the user if they want the other class. Also, how would you check if all the seats are taken. I am stuck on how to initalize the array so that I can just check if seat is taken and if it isn't go reserve it and break from there. Keep in mind we have not gone over pointers yet. An example (of just the first half of loop as the other half would be the exact same copy other than it being 2 as for the other class):

printf("type one or two: ")
scanf("%d",&choice)

if(choice==1)
{???
if (array[i]!=1)
{
printf("first class seat number: %d", array[i])
array[i]=1
}
}
...


First, initialize and array and set all elements to 0 (we'll let 0 mean free and 1 mean reserved)

for (int i = 0; i < 10; i++)
{
seats[i] = 0;
}


Now, when someone picks first class, we need to check whether any of seats 1 through 5 (so 0 to 4 in the array as array-indices are zero-based in C) are free. If we find a free seat, we'll set it to reserved. Similarly for second class. If a class is full, we want to check the other class for free seats. Easiest is to make a function:

int firstFreeSeat(int class)
{
for (int i = 5 * (class - 1); i < 5 * class; i++)
{
if (seats[i] == 0) return i;
}
return -1;
}

This function returns the seat-index of the first free seat in the class or -1 if nothing is free. So now we use this function:

int freeSeat = firstFreeSeat(choice);

if (freeSeat == -1)
{
printf("No free seats in selected class. Try other class? (1 = yes, 0 = no)");
scanf("%d", &choice2);
if (choice2 != 1) return;
int freeSeat2 = firstFreeSeat(3 - choice); // Turns 1 into 2 and vice versa.
if (freeSeat2 == -1)
{
printf("No seats available! :-(");
}
else
{
seats[freeSeat2] = 1;
printf("Seat reserved, but not in your favourite class!");
}
}
else
{
seats[freeSeat] = 1;
printf("Seat reserved in your favourite class!");
}
Such flammable little insects!
heroyi
Profile Blog Joined March 2009
United States1064 Posts
Last Edited: 2013-10-16 18:33:29
October 16 2013 18:09 GMT
#7454
Appreciate the answers, guys. Yea, I figured for two using functions would be a lot easier but couldn't think of them in components.
wat wat in my pants
scudst0rm
Profile Joined May 2010
Canada1149 Posts
October 16 2013 18:22 GMT
#7455
On October 17 2013 03:09 heroyi wrote:
+ Show Spoiler +
Appreciate the answers, guys. Yea, I figured for two using functions would be a lot easier but couldn't think of them in components.

Just got out of a quiz in the class and a bit confused with the questioning:
It pertains to arrays (again) with writing a fragment that add values in array together if we had an array a, lens represented the number of elements, and int k that was guaranteed to hold values between 0 through lens-1. So:


int arraysum(int a[], size_t lens, int k)
{...}

I understand how to solve it by utilizing a for loop or using recursion (again not trying to be a chump here). My problem is when trying to write the number of elements for an array why is it that you would want to use for(int i=0;K<lens-1;i++ (for loop)

or (recursion method/base case)

if(k==lens-1)
return K

I mean what if K does start at zero. Why should it be lens-1 instead of going: for(int i=0;i<lens;i++)? The reason i am somewhat baffled was because the instructor stated that in order to the recursion you would need a holder (thus the int k) but without it you could do it just by the for loop method (making lens being the size of your array). So why would I have to compensate the elements with lens-1 i.e why not 0 to lens?



An array of size N is indexed by 0 to (N-1)

i.e. an array of size 4 has the indexes 0,1,2,3
You're like a one ranger army comin' at me...
heroyi
Profile Blog Joined March 2009
United States1064 Posts
October 16 2013 18:34 GMT
#7456
On October 17 2013 03:22 scudst0rm wrote:
Show nested quote +
On October 17 2013 03:09 heroyi wrote:
+ Show Spoiler +
Appreciate the answers, guys. Yea, I figured for two using functions would be a lot easier but couldn't think of them in components.

Just got out of a quiz in the class and a bit confused with the questioning:
It pertains to arrays (again) with writing a fragment that add values in array together if we had an array a, lens represented the number of elements, and int k that was guaranteed to hold values between 0 through lens-1. So:


int arraysum(int a[], size_t lens, int k)
{...}

I understand how to solve it by utilizing a for loop or using recursion (again not trying to be a chump here). My problem is when trying to write the number of elements for an array why is it that you would want to use for(int i=0;K<lens-1;i++ (for loop)

or (recursion method/base case)

if(k==lens-1)
return K

I mean what if K does start at zero. Why should it be lens-1 instead of going: for(int i=0;i<lens;i++)? The reason i am somewhat baffled was because the instructor stated that in order to the recursion you would need a holder (thus the int k) but without it you could do it just by the for loop method (making lens being the size of your array). So why would I have to compensate the elements with lens-1 i.e why not 0 to lens?



An array of size N is indexed by 0 to (N-1)

i.e. an array of size 4 has the indexes 0,1,2,3

A misunderstanding on my part it seems. Ty for the speedy response though
wat wat in my pants
Geiko
Profile Blog Joined June 2010
France1959 Posts
October 16 2013 21:15 GMT
#7457
Hey guys, currently on Matlab and I'm trying to to write a function which returns a matrix containing all possible combinations of n different integers amongst p integers (integers from 1 to p).

Now this would be easy if I could use lists, but matlab doesn't have a built-in list structure and it's hard to preallocate with reccursive functions. Any ideas for me ?
geiko.813 (EU)
NB
Profile Blog Joined February 2010
Netherlands12045 Posts
October 17 2013 02:44 GMT
#7458
On October 16 2013 22:30 heroyi wrote:
I has but two simple C questions

one: I understand what const array does (doesnt allow you to modify values in array) but if that is the case (when using arrays as a parameter) then what situation would call for its use? The only reason I can think of on the top of my head is that you want to (if this is even viable) use the function to make a dynamic array. Personally I think I am wrong on that logic but I still can't see the reason of the point of using the const if you don't want to change the array when using it as a parameter.

two:
simple program but I am running into a roadblock. No, this is not a hw assignment. Besides, I just help on the control flow. The program question is you are making a program to reserve seats on a small airplane of 10 seats. If user types 1, then that is a first class seat (seats 1-5) while 2 is economy(seats 6-10). If someone reserves a seat than it is taken and if all the seats are taken for a class then you ask whether they want an empty seat in the other class.

I don't understand how one could check if the seat is taken and how would you check if all the seats are taken to prompt the user if they want the other class. Also, how would you check if all the seats are taken. I am stuck on how to initalize the array so that I can just check if seat is taken and if it isn't go reserve it and break from there. Keep in mind we have not gone over pointers yet. An example (of just the first half of loop as the other half would be the exact same copy other than it being 2 as for the other class):

printf("type one or two: ")
scanf("%d",&choice)

if(choice==1)
{???
if (array[i]!=1)
{
printf("first class seat number: %d", array[i])
array[i]=1
}
}
...



1/ Constants are used as data holder. There will be important data that you dont want to modify while running. For example: I want a constant array of the first 200 prime numbers. To re calculated those would be a pain in the ass so a good solution would be just store them in 1 place for future access.
Another example would be to hold Initial value of programs. For example, a level(map) of a computer game is a constant. http://www.sfml-dev.org/tutorials/2.1/graphics-vertex-array.php scroll all the way down and you could see the array that representing the map right bellow.

2/ This sounds awfully like a hw assignment to me lol.... Im pretty sure most people here could just type down the solution for you within a minute but my advise is reading up and trying out examples that your instructor gave you. It will help you much better in the long run.
Im daed. Follow me @TL_NB
WolfintheSheep
Profile Joined June 2011
Canada14127 Posts
October 17 2013 03:11 GMT
#7459
On October 16 2013 22:30 heroyi wrote:
two:
simple program but I am running into a roadblock. No, this is not a hw assignment. Besides, I just help on the control flow. The program question is you are making a program to reserve seats on a small airplane of 10 seats. If user types 1, then that is a first class seat (seats 1-5) while 2 is economy(seats 6-10). If someone reserves a seat than it is taken and if all the seats are taken for a class then you ask whether they want an empty seat in the other class.

I don't understand how one could check if the seat is taken and how would you check if all the seats are taken to prompt the user if they want the other class. Also, how would you check if all the seats are taken. I am stuck on how to initalize the array so that I can just check if seat is taken and if it isn't go reserve it and break from there. Keep in mind we have not gone over pointers yet. An example (of just the first half of loop as the other half would be the exact same copy other than it being 2 as for the other class):

printf("type one or two: ")
scanf("%d",&choice)

if(choice==1)
{???
if (array[i]!=1)
{
printf("first class seat number: %d", array[i])
array[i]=1
}
}
...


A question here is why you're even bothering with an array. Unless you're specifically asked to use an array, or if there is a lot more expected functionality than what you're describing, then two counters with a range of 0-5 should do exactly what you need.
Average means I'm better than half of you.
obesechicken13
Profile Blog Joined July 2008
United States10467 Posts
Last Edited: 2013-10-17 04:12:53
October 17 2013 03:32 GMT
#7460
On October 17 2013 06:15 Geiko wrote:
Hey guys, currently on Matlab and I'm trying to to write a function which returns a matrix containing all possible combinations of n different integers amongst p integers (integers from 1 to p).

Now this would be easy if I could use lists, but matlab doesn't have a built-in list structure and it's hard to preallocate with reccursive functions. Any ideas for me ?

Matlab has arrays. Can't you concatenate with arrays?

Also matlab seems to have lists but it might be in the math toolbox.
http://www.mathworks.com/help/symbolic/mupad_ref/append.html

Whoa. Deja vu


-Matlab newb
I think in our modern age technology has evolved to become more addictive. The things that don't give us pleasure aren't used as much. Work was never meant to be fun, but doing it makes us happier in the long run.
Prev 1 371 372 373 374 375 1032 Next
Please log in or register to reply.
Live Events Refresh
Ladder Legends
15:00
Valedictorian Cup #1 Qualifier
SteadfastSC13
Liquipedia
WardiTV Map Contest Tou…
11:00
Group D
WardiTV1073
IndyStarCraft 303
Rex104
Liquipedia
[ Submit Event ]
Live Streams
Refresh
StarCraft 2
IndyStarCraft 303
LamboSC2 147
Rex 104
BRAT_OK 53
Codebar 25
EmSc Tv 16
SteadfastSC 13
StarCraft: Brood War
Britney 125755
Calm 4272
EffOrt 1654
Horang2 1574
Mini 506
ggaemo 504
BeSt 440
firebathero 258
PianO 141
Mind 139
[ Show more ]
Soulkey 103
Hyun 92
Sexy 81
Sea.KH 55
Killer 46
Movie 35
sSak 35
Sharp 32
Shinee 27
zelot 18
Rock 18
GoRush 17
yabsab 16
Hm[arnc] 14
Dewaltoss 10
Terrorterran 8
SilentControl 8
eros_byul 1
Dota 2
Gorgc7606
ODPixel62
League of Legends
Reynor62
Counter-Strike
fl0m6119
olofmeister3950
byalli448
Super Smash Bros
Mew2King171
Heroes of the Storm
Khaldor758
Liquid`Hasu358
Other Games
singsing1958
B2W.Neo1158
Beastyqt634
FrodaN491
mouzStarbuck185
XaKoH 185
Hui .180
KnowMe38
RotterdaM32
MindelVK8
Organizations
Dota 2
PGL Dota 2 - Main Stream14064
PGL Dota 2 - Secondary Stream1321
Other Games
BasetradeTV530
StarCraft 2
EmSc Tv 16
EmSc2Tv 16
Blizzard YouTube
StarCraft: Brood War
BSLTrovo
sctven
[ Show 18 non-featured ]
StarCraft 2
• EnkiAlexander 37
• Adnapsc2 26
• poizon28 25
• Shameless 23
• Kozan
• Migwel
• sooper7s
• AfreecaTV YouTube
• intothetv
• IndyKCrew
• LaughNgamezSOOP
StarCraft: Brood War
• STPLYoutube
• ZZZeroYoutube
• BSLYoutube
League of Legends
• Jankos2039
• Nemesis1477
• TFBlade1311
Other Games
• Shiphtur112
Upcoming Events
IPSL
29m
JDConan vs TBD
Aegong vs rasowy
BSL
3h 29m
StRyKeR vs rasowy
Artosis vs Aether
JDConan vs OyAji
Hawk vs izu
CranKy Ducklings
8h 29m
Replay Cast
17h 29m
Wardi Open
18h 29m
Afreeca Starleague
18h 29m
Bisu vs Ample
Jaedong vs Flash
Monday Night Weeklies
1d
RSL Revival
1d 10h
Afreeca Starleague
1d 18h
Barracks vs Leta
Royal vs Light
WardiTV Map Contest Tou…
1d 19h
[ Show More ]
RSL Revival
2 days
Replay Cast
3 days
The PondCast
3 days
KCM Race Survival
3 days
WardiTV Map Contest Tou…
3 days
Replay Cast
4 days
Escore
4 days
RSL Revival
5 days
WardiTV Map Contest Tou…
5 days
Ladder Legends
5 days
uThermal 2v2 Circuit
5 days
BSL
6 days
Sparkling Tuna Cup
6 days
WardiTV Map Contest Tou…
6 days
Ladder Legends
6 days
Liquipedia Results

Completed

Escore Tournament S2: W3
RSL Revival: Season 4
NationLESS Cup

Ongoing

BSL Season 22
ASL Season 21
CSL 2026 SPRING (S20)
IPSL Spring 2026
KCM Race Survival 2026 Season 2
StarCraft2 Community Team League 2026 Spring
WardiTV TLMC #16
Nations Cup 2026
IEM Rio 2026
PGL Bucharest 2026
Stake Ranked Episode 1
BLAST Open Spring 2026
ESL Pro League S23 Finals
ESL Pro League S23 Stage 1&2
PGL Cluj-Napoca 2026
IEM Kraków 2026

Upcoming

Escore Tournament S2: W4
Acropolis #4
BSL 22 Non-Korean Championship
CSLAN 4
Kung Fu Cup 2026 Grand Finals
HSC XXIX
uThermal 2v2 2026 Main Event
2026 GSL S2
RSL Revival: Season 5
2026 GSL S1
XSE Pro League 2026
IEM Cologne Major 2026
Stake Ranked Episode 2
CS Asia Championships 2026
IEM Atlanta 2026
Asian Champions League 2026
PGL Astana 2026
BLAST Rivals Spring 2026
TLPD

1. ByuN
2. TY
3. Dark
4. Solar
5. Stats
6. Nerchio
7. sOs
8. soO
9. INnoVation
10. Elazer
1. Rain
2. Flash
3. EffOrt
4. Last
5. Bisu
6. Soulkey
7. Mini
8. Sharp
Sidebar Settings...

Advertising | Privacy Policy | Terms Of Use | Contact Us

Original banner artwork: Jim Warren
The contents of this webpage are copyright © 2026 TLnet. All Rights Reserved.