• Log InLog In
  • Register
Liquid`
Team Liquid Liquipedia
EDT 16:46
CEST 22:46
KST 05: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
[ASL20] Finals Preview: Arrival6TL.net Map Contest #21: Voting10[ASL20] Ro4 Preview: Descent11Team TLMC #5: Winners Announced!3[ASL20] Ro8 Preview Pt2: Holding On9
Community News
Merivale 8 Open - LAN - Stellar Fest0Chinese SC2 server to reopen; live all-star event in Hangzhou21Weekly Cups (Oct 13-19): Clem Goes for Four3BSL Team A vs Koreans - Sat-Sun 16:00 CET10Weekly Cups (Oct 6-12): Four star herO8
StarCraft 2
General
RotterdaM "Serral is the GOAT, and it's not close" Chinese SC2 server to reopen; live all-star event in Hangzhou The New Patch Killed Mech! Weekly Cups (Oct 13-19): Clem Goes for Four 5.0.15 Patch Balance Hotfix (2025-10-8)
Tourneys
Merivale 8 Open - LAN - Stellar Fest Tenacious Turtle Tussle RSL Season 3 Qualifier Links and Dates $1,200 WardiTV October (Oct 21st-31st) SC2's Safe House 2 - October 18 & 19
Strategy
Custom Maps
Map Editor closed ?
External Content
Mutation # 496 Endless Infection Mutation # 495 Rest In Peace Mutation # 494 Unstable Environment Mutation # 493 Quick Killers
Brood War
General
Is there anyway to get a private coach? BGH Auto Balance -> http://bghmmr.eu/ [ASL20] Finals Preview: Arrival BSL Team A vs Koreans - Sat-Sun 16:00 CET OGN to release AI-upscaled StarLeague from Feb 24
Tourneys
[ASL20] Grand Finals ASL final tickets help Small VOD Thread 2.0 [Megathread] Daily Proleagues
Strategy
Roaring Currents ASL final Simple Questions, Simple Answers Relatively freeroll strategies BW - ajfirecracker Strategy & Training
Other Games
General Games
General RTS Discussion Thread Stormgate/Frost Giant Megathread Nintendo Switch Thread Path of Exile Dawn of War IV
Dota 2
Official 'what is Dota anymore' discussion LiquidDota to reintegrate into TL.net
League of Legends
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
TL Mafia Community Thread SPIRED by.ASL Mafia {211640}
Community
General
Russo-Ukrainian War Thread US Politics Mega-thread Things Aren’t Peaceful in Palestine YouTube Thread The Chess Thread
Fan Clubs
White-Ra Fan Club The herO Fan Club!
Media & Entertainment
Anime Discussion Thread [Manga] One Piece Korean Music Discussion Series you have seen recently... Movie Discussion!
Sports
2024 - 2026 Football Thread MLB/Baseball 2023 TeamLiquid Health and Fitness Initiative For 2023 Formula 1 Discussion NBA General Discussion
World Cup 2022
Tech Support
SC2 Client Relocalization [Change SC2 Language] Linksys AE2500 USB WIFI keeps disconnecting Computer Build, Upgrade & Buying Resource Thread
TL Community
The Automated Ban List Recent Gifted Posts
Blogs
The Benefits Of Limited Comm…
TrAiDoS
Sabrina was soooo lame on S…
Peanutsc
Our Last Hope in th…
KrillinFromwales
Certified Crazy
Hildegard
Customize Sidebar...

Website Feedback

Closed Threads



Active: 1732 users

The Big Programming Thread - Page 876

Forum Index > General Forum
Post a Reply
Prev 1 874 875 876 877 878 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.
Deleted User 3420
Profile Blog Joined May 2003
24492 Posts
Last Edited: 2017-04-22 14:56:57
April 22 2017 14:55 GMT
#17501
does dup2 follow fork?

if I dup2 to change stdin to say, a file for input
and then fork

does the child process use the file for input or is it pointing to the original stdin?
it points to the file for input, right?

so like, since I am making a shell program where each command forks a child process,

so if a user wants input redirection on the first command, and inputs multiple commands at once (say with &&), I need to fork, then dup in the child process, and then fork the next command from the parent not the child? that will work? or do I need to set stdin back to file descriptor 1?

basically I can't remember what is and isn't shared among all processes

is it that the open file TABLE is shared among all processes, but each process has it's own open file descriptor?
Thaniri
Profile Blog Joined March 2011
1264 Posts
Last Edited: 2017-04-22 23:43:53
April 22 2017 23:28 GMT
#17502
In C#, how can one make a line full of dashes in the console?

I'm trying to get the dashes lines to be as wide as the numbers being printed without simply hardcoding a number of dashes:

http://i.imgur.com/JQ2NyPo.jpg

+ Show Spoiler +


static void Main(string[] args)
{
printEvenSquaresCubesLoop();
printEvenSquaresCubesRescursive(0, 20);
}

static void printEvenSquaresCubesLoop()
{
int numSum = 0;
int squareSum = 0;
int cubeSum = 0;

Console.WriteLine("{0, 10} {1, 10} {2, 10}"
, "number"
, "square"
, "cube");
Console.WriteLine("--------------------------------");

for (int i = 0; i <= 20; i = i + 2)
{
Console.WriteLine("{0, 10} {1, 10} {2, 10}"
, i
, i * i
, i * i * i);
numSum += i;
squareSum += i * i;
cubeSum += i * i * i;
}

Console.WriteLine("--------------------------------");
Console.WriteLine("{0, 10} {1, 10} {2, 10}"
, numSum
, squareSum
, cubeSum);
}

static int printEvenSquaresCubesRescursive(int input, int max)
{
if(input >= max)
{
Console.WriteLine("{0, 10} {1, 10} {2, 10}"
, input
, input * input
, input * input * input);
return input;
}
else
{
Console.WriteLine("{0, 10} {1, 10} {2, 10}"
, input
, input * input
, input * input * input);
return input * printEvenSquaresCubesRescursive(input + 2, 20);
}

}
}


edit: updated code cause the recursive solution is also not going to be formatted so nicely :D
Manit0u
Profile Blog Joined August 2004
Poland17397 Posts
Last Edited: 2017-04-23 01:11:36
April 23 2017 01:10 GMT
#17503
On April 23 2017 08:28 Thaniri wrote:
In C#, how can one make a line full of dashes in the console?

I'm trying to get the dashes lines to be as wide as the numbers being printed without simply hardcoding a number of dashes:



int len = 20;
string str = '';
char pad = '-';

Console.WriteLine(str.PadLeft(len, pad)); // might as well be PadRight...
Time is precious. Waste it wisely.
Thaniri
Profile Blog Joined March 2011
1264 Posts
Last Edited: 2017-04-23 01:37:16
April 23 2017 01:30 GMT
#17504
I thought of that solution, but a problem occurs if instead of 10 iterations, I have to do 100 or 1000 iterations. The dashed line won't match up with the new wider columns.

edit: An idea I had was similar to MySQL select last_insert_id(). I wanted to get the last thing sent to standard output, grab the length of that, and then print out the dashes as required. This wouldn't work unfortunately though since I'm being asked to have a dashed line before and after the columns of numbers.
Manit0u
Profile Blog Joined August 2004
Poland17397 Posts
Last Edited: 2017-04-23 01:46:04
April 23 2017 01:35 GMT
#17505
Does the dashed line have to match the longest line from all lines or from a single set?

You can simply calculate the padding dynamically (instead of directly writing to the output, save it to a string and pass it's length to the padding).


// outside of loop
int longest = 0;
String p = '';

// inside loop
String s = String.Format("{0, 10} {1, 10} {2, 10}", input, input * input, input * input * input);
longest = s.Length > longest ? s.Length : longest;

Console.WriteLine(s);

// outside of loop
Console.WriteLine(p.PadLeft(longest, '-');
Time is precious. Waste it wisely.
Thaniri
Profile Blog Joined March 2011
1264 Posts
Last Edited: 2017-04-23 01:46:02
April 23 2017 01:44 GMT
#17506
My question was dumb

The reason my question is stupid in the first place is that the right aligned formatting is clever enough to figure out that I'm right aligning integers and allocates enough spaces to fit the maximum integer size. In this case it is perfectly valid to hard code the length of my dashed lines because no matter how small or big my inputs are the width of the columns is the same.

Oh well, that's what I get for trying to be smart.

edit: Thanks for your demo. It does teach me about String formatting in c# :D
Manit0u
Profile Blog Joined August 2004
Poland17397 Posts
April 23 2017 01:46 GMT
#17507
Updated the demo
Time is precious. Waste it wisely.
Hanh
Profile Joined June 2016
146 Posts
April 23 2017 02:38 GMT
#17508
 
new string(pad, len)


should work too
Manit0u
Profile Blog Joined August 2004
Poland17397 Posts
April 25 2017 14:34 GMT
#17509
My brain is fried. I need help with SQL again.

Select from single table. Relevant columns: position, status.

Select row with lowest position where all rows with lower position have certain status.
Time is precious. Waste it wisely.
Acrofales
Profile Joined August 2010
Spain18098 Posts
Last Edited: 2017-04-25 14:46:27
April 25 2017 14:41 GMT
#17510
Maybe you're not clear, but wouldn't

SELECT id, MIN(position) FROM table WHERE status != <certain status> GROUP BY status;

do it?

E: actually, because you may have more statuses than just the "certain status" and others, this won't give you just one row.

So I guess:


SELECT TOP 1 id, position FROM table WHERE status != <certain status> ORDER BY position ASC;

BluzMan
Profile Blog Joined April 2006
Russian Federation4235 Posts
April 25 2017 16:17 GMT
#17511
On April 25 2017 23:34 Manit0u wrote:
My brain is fried. I need help with SQL again.

Select from single table. Relevant columns: position, status.

Select row with lowest position where all rows with lower position have certain status.

Are you sure it's not `highest`?
You want 20 good men, but you need a bad pussy.
Manit0u
Profile Blog Joined August 2004
Poland17397 Posts
Last Edited: 2017-04-25 17:17:15
April 25 2017 17:15 GMT
#17512
On April 26 2017 01:17 BluzMan wrote:
Show nested quote +
On April 25 2017 23:34 Manit0u wrote:
My brain is fried. I need help with SQL again.

Select from single table. Relevant columns: position, status.

Select row with lowest position where all rows with lower position have certain status.

Are you sure it's not `highest`?


Nono, it's for queueing stuff. To simplify it let's assume that you have some jobs that need to be performed in order. I need to grab the next job in order, assuming that all previous jobs have the "done" status. I shouldn't get any results if even one job is "in progress".

Does this make any sense?

Example:

Job 1: position 1, status "done"
Job 2: position 2, status "done"
Job 3: position 3, status "ready"
Job 4: position 4, status "ready"

Need to get Job 3.

Example 3:

Example:

Job 1: position 1, status "done"
Job 2: position 2, status "in progress"
Job 3: position 3, status "ready"
Job 4: position 4, status "ready"

Should get empty result.
Time is precious. Waste it wisely.
enigmaticcam
Profile Blog Joined October 2010
United States280 Posts
Last Edited: 2017-04-25 19:15:41
April 25 2017 18:58 GMT
#17513
On April 26 2017 02:15 Manit0u wrote:Nono, it's for queueing stuff. To simplify it let's assume that you have some jobs that need to be performed in order. I need to grab the next job in order, assuming that all previous jobs have the "done" status. I shouldn't get any results if even one job is "in progress".

Does this make any sense?

Example:

Job 1: position 1, status "done"
Job 2: position 2, status "done"
Job 3: position 3, status "ready"
Job 4: position 4, status "ready"

Need to get Job 3.

Example 3:

Example:

Job 1: position 1, status "done"
Job 2: position 2, status "in progress"
Job 3: position 3, status "ready"
Job 4: position 4, status "ready"

Should get empty result.

Here's my suggestion, assuming jobs are always processed in order:
select * 
from (
select top 1 job
from table
where status != "done"
order by job asc
) a
where status != 'in progress'


If for some reason there's a possibility jobs are processed out of order, you would have to factor that in this way:
select * 
from (
select top 1 job
from table
where status != "done"
order by job asc
) a
where (select count(job) from table where status = 'In Progress') = 0
slmw
Profile Blog Joined October 2010
Finland233 Posts
April 25 2017 19:09 GMT
#17514
Job 8 might be in progress while job 7 is ready. Your query would select job 7 but ignore the fact that job 8 is in progress.
tofucake
Profile Blog Joined October 2009
Hyrule19148 Posts
Last Edited: 2017-04-25 19:10:44
April 25 2017 19:10 GMT
#17515
that won't work though, that will just pull the first ready job even if there's one in progress

sniped :<
Liquipediaasante sana squash banana
enigmaticcam
Profile Blog Joined October 2010
United States280 Posts
April 25 2017 19:10 GMT
#17516
Yes, just edited. If your choice of which job to run is granted only by means of this query, than it works just fine. But if you have other processes that might decide to start a job, the second one is best.
tofucake
Profile Blog Joined October 2009
Hyrule19148 Posts
April 25 2017 19:22 GMT
#17517
MySQL/Maria doesn't have top, you'd have to do

SELECT * FROM (SELECT * FROM `jobs` WHERE `status` != "done" ORDER BY `id` ASC LIMIT 1) a
WHERE (SELECT COUNT(`id`) FROM `jobs` WHERE `status` = 'in progress') = 0
Liquipediaasante sana squash banana
Thaniri
Profile Blog Joined March 2011
1264 Posts
Last Edited: 2017-04-26 01:38:08
April 26 2017 01:36 GMT
#17518
Attempt:+ Show Spoiler +
This is not correct syntax:

select job from
(select job from table group by status where status != "in progress" order by status desc)
limit 1;

lets say the way ordering works is (alphabetically):
done = 0
in progress = 1
ready = 2

This should select the first ready job but does not give you an empty result set if an in progress is found.


Unless you have bandwidth problems, why don't you use a programming language to find out if the returned data set contains "in progress"

select job, position, status from table where job = whatever;

Then in the application layer you can iterate over your result set and make a decision as needed.

Hanh
Profile Joined June 2016
146 Posts
April 26 2017 03:00 GMT
#17519
In MySQL,


select * from jobs where status = 'ready' and not exists (select * from jobs
where status = 'in progress') order by position limit 1;

Thaniri
Profile Blog Joined March 2011
1264 Posts
April 26 2017 03:11 GMT
#17520
Damn I forgot about the 'not exists' clause.
Prev 1 874 875 876 877 878 1032 Next
Please log in or register to reply.
Live Events Refresh
Next event in 11h 14m
[ Submit Event ]
Live Streams
Refresh
StarCraft 2
White-Ra 151
SpeCial 143
ProTech88
Railgan 68
JuggernautJason5
StarCraft: Brood War
Britney 20452
Artosis 892
ZZZero.O 161
Dewaltoss 125
NaDa 8
Dota 2
syndereN357
capcasts77
LuMiX1
Counter-Strike
fl0m1633
Super Smash Bros
Mew2King51
Heroes of the Storm
Liquid`Hasu431
Khaldor290
Other Games
FrodaN2867
Grubby2305
Mlord525
Beastyqt523
summit1g413
shahzam300
Skadoodle202
KnowMe151
ViBE2
Organizations
Other Games
gamesdonequick885
StarCraft 2
Blizzard YouTube
StarCraft: Brood War
BSLTrovo
sctven
[ Show 15 non-featured ]
StarCraft 2
• printf 53
• HeavenSC 38
• AfreecaTV YouTube
• intothetv
• Kozan
• IndyKCrew
• LaughNgamezSOOP
• Migwel
• sooper7s
StarCraft: Brood War
• BSLYoutube
• STPLYoutube
• ZZZeroYoutube
Dota 2
• masondota21046
Other Games
• imaqtpie1340
• Shiphtur209
Upcoming Events
Afreeca Starleague
11h 14m
Snow vs Soma
Sparkling Tuna Cup
13h 14m
WardiTV Invitational
15h 14m
CrankTV Team League
16h 14m
BASILISK vs Streamerzone
Team Liquid vs Shopify Rebellion
Team Vitality vs Team Falcon
BSL Team A[vengers]
18h 14m
Gypsy vs nOOB
JDConan vs Scan
RSL Revival
20h 14m
Wardi Open
1d 15h
CrankTV Team League
1d 16h
Replay Cast
2 days
WardiTV Invitational
2 days
[ Show More ]
CrankTV Team League
2 days
Replay Cast
3 days
CrankTV Team League
3 days
Replay Cast
4 days
The PondCast
4 days
CrankTV Team League
4 days
Replay Cast
5 days
WardiTV Invitational
5 days
CrankTV Team League
5 days
Replay Cast
6 days
Liquipedia Results

Completed

Acropolis #4 - TS2
WardiTV TLMC #15
HCC Europe

Ongoing

BSL 21 Points
ASL Season 20
CSL 2025 AUTUMN (S18)
C-Race Season 1
IPSL Winter 2025-26
KCM Race Survival 2025 Season 4
EC S1
Thunderpick World Champ.
CS Asia Championships 2025
ESL Pro League S22
StarSeries Fall 2025
FISSURE Playground #2
BLAST Open Fall 2025
BLAST Open Fall Qual
Esports World Cup 2025
BLAST Bounty Fall 2025

Upcoming

SC4ALL: Brood War
BSL Season 21
BSL 21 Team A
BSL 21 Non-Korean Championship
RSL Offline Finals
RSL Revival: Season 3
Stellar Fest
SC4ALL: StarCraft II
CranK Gathers Season 2: SC II Pro Teams
eXTREMESLAND 2025
ESL Impact League Season 8
SL Budapest Major 2025
BLAST Rivals Fall 2025
IEM Chengdu 2025
PGL Masters Bucharest 2025
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 © 2025 TLnet. All Rights Reserved.