• Log InLog In
  • Register
Liquid`
Team Liquid Liquipedia
EDT 23:46
CEST 05:46
KST 12:46
  • 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
Serral wins HomeStory Cup 296Serral wins Maestros of the Game 243ByuL, and the Limitations of Standard Play3Team Liquid Map Contest #22: Results and Winners7Code S Season 2 (2026): RO4 and Finals Preview12
Community News
BSL Season 22 Full Overview & Conclusion7BSL Season 22 Full Overview & Conclusion7Weekly Cups (June 29-July 5): Solar Doubles0MC vs IdrA, Boxer vs Nal_rA to be Legacy Matches @ BlizzCon445.0.16 Hotfix (June 30) - Balance + Bug Fixes40
StarCraft 2
General
Serral wins HomeStory Cup 29 Serral wins Maestros of the Game 2 Reynor: GSL Loss Wasn't About Preparation Format 5.0.16 patch for SC2 goes live (8 worker start) What is your PC setup in 2026 for SCBW/SC2 ?
Tourneys
GSL CK #5 Race War WardiTV Summer Cup 2026 RSL Revival: Season 6 - Qualifiers and Main Event HomeStory Cup 29 Vespene Cup #1 — $300+ USD, July 10
Strategy
[G] Having the right mentality to improve
Custom Maps
New Map Maker - Looking for Advice - Love or Hate Work In Progress Melee Maps [D]RTS in all its shapes and glory <3
External Content
The PondCast: SC2 News & Results Mutation # 534 Burning Evacuation Mutation # 533 Die Together Mutation # 532 Nuclear Family
Brood War
General
Pros Debate: Zerg Unfairly Nerfed? (ASL S22 map) BSL Season 22 Full Overview & Conclusion BGH Auto Balance -> http://bghmmr.eu/ BW General Discussion ASL22 General Discussion
Tourneys
[ASL22] Wildcard Qualifier IPSL Spring 2026 Top 4! [Megathread] Daily Proleagues CSLAN 4 is Coming!
Strategy
Fighting Spirit mining rates Simple Questions, Simple Answers Creating a full chart of Zerg builds Relatively freeroll strategies
Other Games
General Games
Stormgate/Frost Giant Megathread General RTS Discussion Thread Path of Exile Summer Games Done Quick 2026! Nintendo Switch Thread
Dota 2
Looking for a Dota Mentor Official 'what is Dota anymore' discussion
League of Legends
Heroes of the Storm
Simple Questions, Simple Answers Heroes of the Storm 2.0
Hearthstone
Deck construction bug
TL Mafia
NeO.D_StephenKing vs This Guy From 1 Million Dance TL Mafia Community Thread TL Mafia Power Rank Vanilla Mini Mafia
Community
General
US Politics Mega-thread Russo-Ukrainian War Thread UK Politics Mega-thread YouTube Thread Canadian Politics Mega-thread
Fan Clubs
The IdrA Fan Club The HerO Fan Club!
Media & Entertainment
Movie Discussion! Anime Discussion Thread Series you have seen recently...
Sports
2024 - 2026 Football Thread McBoner: A hockey love story Tennis[sport] Formula 1 Discussion TeamLiquid Health and Fitness Initiative For 2023
World Cup 2022
Tech Support
Simple Questions Simple Answers FPS when play League Of Legend on laptop How to clean a TTe Thermaltake keyboard?
TL Community
The Automated Ban List
Blogs
Major Shifts in the Gaming I…
TrAiDoS
An Exploration of th…
waywardstrategy
Gauntlet SC2: A Retrospectiv…
Ctone23
ramps on octagon
StaticNine
Funny Nicknames
LUCKY_NOOB
Evil Gacha Games and the…
ffswowsucks
StarCraft improvement
iopq
Customize Sidebar...

Website Feedback

Closed Threads



Active: 5287 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
Portugal3304 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
France2012 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
Replay Cast
00:00
GSL CK #5 - Day 2
CranKy Ducklings135
EnkiAlexander 66
Liquipedia
[ Submit Event ]
Live Streams
Refresh
StarCraft 2
WinterStarcraft624
NeuroSwarm 217
RuFF_SC2 170
oGsTOP 144
StarCraft: Brood War
Rain 7323
GuemChi 2825
Bale 13
Terrorterran 10
Dota 2
canceldota201
Counter-Strike
summit1g9222
tarik_tv2460
taco 446
Other Games
JimRising 550
C9.Mang0415
Maynarde141
Nina85
Organizations
Other Games
gamesdonequick2280
BasetradeTV220
StarCraft 2
Blizzard YouTube
StarCraft: Brood War
BSLTrovo
[ Show 14 non-featured ]
StarCraft 2
• practicex 15
• AfreecaTV YouTube
• intothetv
• Kozan
• IndyKCrew
• LaughNgamezSOOP
• Migwel
• sooper7s
StarCraft: Brood War
• Azhi_Dahaki33
• BSLYoutube
• STPLYoutube
• ZZZeroYoutube
League of Legends
• Rush749
• Stunt289
Upcoming Events
WardiTV Weekly
7h 14m
The PondCast
1d 6h
Replay Cast
2 days
CrankTV Team League
2 days
Replay Cast
3 days
CrankTV Team League
3 days
Replay Cast
3 days
RSL Revival
4 days
Clem vs Lambo
Scarlett vs Cure
CranKy Ducklings
4 days
IPSL
4 days
Dragon vs Hawk
[ Show More ]
RSL Revival
5 days
Classic vs Trap
herO vs SHIN
Sparkling Tuna Cup
5 days
IPSL
5 days
Bonyth vs Ret
WardiTV Weekly
6 days
Monday Night Weeklies
6 days
Liquipedia Results

Completed

YSL S3
HSC XXIX
Eternal Conflict S2 E2

Ongoing

IPSL Spring 2026
Acropolis #4
CSL 2026 Summer (S21)
RSL Revival: Season 6
CranK Gathers Season 4: BW vs SC2 Team League
SCTL 2026 Spring
XSE Pro League 2026
IEM Cologne Major 2026
Stake Ranked Episode 2
CS Asia Championships 2026
Asian Champions League 2026
IEM Atlanta 2026
PGL Astana 2026
BLAST Rivals Spring 2026

Upcoming

Escore Tournament S3: W3
ASL S22 SEASON OPEN Day 1
Escore Tournament S3: W4
ASL S22 SEASON OPEN Day 2
Escore Tournament S3: W5
CSLAN 4
Blizzard Classic Cup 2026
HSC XXX
SC4ALL II: StarCraft II
Kung Fu Cup 2026 Grand Finals
Light Tournament 2026
Eternal Conflict S2 Finale
Eternal Conflict S2 E3
Logitech G Connect 2026
StarSeries Fall 2026
FISSURE Playground #5
BLAST Open Fall 2026
Esports World Cup 2026
BLAST Bounty Summer 2026
BLAST Bounty Summer Qual
Stake Ranked Episode 3
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.