Sponsored Content
Top Forums Shell Programming and Scripting How to write program that find winner who choose the smallest number. UNIX process? Post 302998567 by dantesma on Sunday 4th of June 2017 05:22:06 AM
Old 06-04-2017
How to write program that find winner who choose the smallest number. UNIX process?

In the game of “Unique”, multiple players privately choose an integer. They then reveal
their choice. The winner is the player who chose the smallest unique number. The
game is considered a draw if no unique integer was chosen.
You would write a program that simulate such a game according to the followings
1. The parent process fork player (child) processes (up to maximum of 10
players). It then waits for each of the child processes to return an integer.
2. The players (child processes) will randomly pick an integer between 1 to 5, and
return the choices to the parent.
3. Parent process determines the winner based on the choice returned by the
players (child processes). Parent process then print out the winner’s PID and
inform all child processes to terminate, before it terminates. If it is a draw, parent
process shall inform all the child processes (players) to choose another integer.
4. Repeat steps 2 and 3 as many times as required until a winner can be
determined.

Example of output:

Code:
$ ./game 5
Game starts with 5 players
Player 3312 choose 4
Player 3314 choose 3
Player 3313 choose 2
Player 3315 choose 1
Player 3316 choose 5
Player 3315 win!

Please help me, to write a code because I am totally new in shell programming


Moderator's Comments:
Mod Comment Please use CODE tags as required by forum rules!

Last edited by RudiC; 06-04-2017 at 07:08 AM.. Reason: Added CODE tags.
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Write a shell program to find the sum of alternate digits in a given 5-digit number

Hi Can any one please post the answer for the above program.................. (4 Replies)
Discussion started by: banta
4 Replies

2. Shell Programming and Scripting

checking the smallest and largest number

Hi All, My script is reading a log file line by line log file is like ; 19:40:22 :INFO Total time taken to Service External Request---115ms 19:40:25 DEBUG : Batch processed libdaemon.x86_64 0-0.10-5.el5 - u 19:40:22 INFO Total time taken to Service External Request---20ms 19:40:24... (4 Replies)
Discussion started by: subin_bala
4 Replies

3. UNIX for Dummies Questions & Answers

How to print largest and smallest number.

Hey. This is pretty easy stuff but I'm learning the basics of Unix at the moment so keep that in mind. I have to: 1) Write a C-shell script to monitor user activity on the server for 13 minutes. 2) Then print the smallest and largest number of users during these 13 minutes. I have this: 1)... (2 Replies)
Discussion started by: amp10388
2 Replies

4. UNIX for Dummies Questions & Answers

Find what process on port number

Hi, I am on a Sun Solaris and I want to find out which process is allocated on a certain port. How can I do that? BR Andreas (4 Replies)
Discussion started by: mr_andrew
4 Replies

5. Shell Programming and Scripting

Find port number being used by a given process id

Unix gurus, I have a requirement wherein I want to find the port number for a given process id. Is it possible? If so how? TIA, Regards, Praveen (3 Replies)
Discussion started by: sunpraveen
3 Replies

6. Shell Programming and Scripting

Shell Script to Kill Process(number of process) Unix/Solaris

Hi Experts, we do have a shell script for Unix Solaris, which will kill all the process manullay, it used to work in my previous env, but now it is throwing this error.. could some one please help me to resolve it This is how we execute the script (and this is the requirement) ... (2 Replies)
Discussion started by: jonnyvic
2 Replies

7. Programming

Help with find highest and smallest number in a file with c

Input file: #data_1 AGDG #data_2 ADG #data_3 ASDDG DG #data_4 A Desired result: Highest 7 Slowest 1 code that I try but failed to archive my goal :( #include <stdio.h> (2 Replies)
Discussion started by: cpp_beginner
2 Replies

8. Shell Programming and Scripting

Print smallest negative number with corresponding index from a column

considering the following table: ID col1 col2 col3 col4 1 -16.06801249 13.49785832 -56.57087607 -27.00500526 2 -1.53315720 0.71731735 -42.03602078 -39.78554623 3 -1.53315190 0.71731587 -42.03601548 ... (3 Replies)
Discussion started by: Birda
3 Replies

9. Shell Programming and Scripting

Problem to print out record got smallest number in specific column

Hi, Anybody know how to print out the record that shown smallest number among column 3 and column 4 Case 1 Input : 37170 37196 77 51 37174 37195 73 52 37174 37194 73 53 Case 1 Output : 37170 37196 77 51 Case 2 Input : 469613 469660 73 ... (4 Replies)
Discussion started by: cpp_beginner
4 Replies

10. Shell Programming and Scripting

Problem facing to compare different column and print out record with smallest number

Hi, Input file 1 : 37170 37196 77 51 37174 37195 73 52 37174 37194 73 53 Desired Output file 1 : 37170 37196 77 51 Input file 2 : 37174 37195 73 0 37170 37196 77 0 Desired Output file 2 : 37174 37195 73 0 (1 Reply)
Discussion started by: cpp_beginner
1 Replies
omega(6)							   Games Manual 							  omega(6)

NAME
omega - a hack-style game with quests. SYNOPSIS
omega [save file] DESCRIPTION
omega is a complex rogue-style game of dungeon exploration. Unlike other such games, there are a number of ways to "win", depending on various actions taken during play. The ways you can get your name on the hiscore board include becoming the highest ranked head of a guild, sect, college, etc., as well as gaining the most points figured from possessions and experience. The game (via the oracle) may impose some structure on your exploration, but you need not follow all of the oracle's advice. There *is* a "total winner" status, by the way. If the save file is not specified, omega gives the player the choice of generating a random character, or playing themselves, doing a short quiz to determine an approximation of their abilities. If the save file is given, omega will restore that save file, and if successful, the save file is deleted. Note that some installations of omega compress the save file, using either compress(1) or gzip(1) - if this is the case, and you have a save file that is uncompressed (such files are generated by omega if it receives a signal during play, for exam- ple), you can compress it (with compress(1) or gzip(1)) and remove the .Z or .gz extension. Alternatively, you may simply run with the uncompressed save file - this will not affect the game in any way, but takes more disk space between games. omega offers a richness of playing detail that goes beyond a simple game like rogue. However, the majority of gameplay is very similar to rogue, hack, ultrarogue, larn, and other such games. The player is represented by the highlighted "@" symbol, objects and terrain features are represented by non-alphabetic symbols, monsters are represented by the various upper and lower case letters, and other humans are rep- resented by a non-highlighted "@". omega currently consists of a countryside in which are sited a city, various villages, several dungeons, and some "special" sites, such as the temples of the various priesthoods. The game starts in the city of Rampart, where all the guilds have headquarters. As a dungeon is explored, all generated levels are saved in memory. However, only one dungeon is "remembered" at a time, so if you enter two dungeons, the first will be forgotten (it will be regenerated should you wish to enter it again). However, if a dungeon is "completed", this fact will be remembered, basically meaning that the unique monster at the bottom will not be regenerated if you've killed it already. SEE ALSO
compress(1), gzip(1), nethack(6) AUTHOR
Laurence Brothers omega(6)
All times are GMT -4. The time now is 03:38 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy