Welcome, Guest: Register On Nairaland / LOGIN! / Trending / Recent / NewStats: 3,194,443 members, 7,954,746 topics. Date: Saturday, 21 September 2024 at 08:24 AM |
Nairaland Forum / Science/Technology / Programming / An Insomniac's Puzzle For Programmers. (4985 Views)
Best Laptops & Desktop Computers For Programmers?? / Mini Web Application Coding Challenge For Programmers / .NET C#/VB.NET Project in the Pipeline for Programmers who may be interested (2) (3) (4)
An Insomniac's Puzzle For Programmers. by kodewrita(m): 5:26am On Aug 29, 2012 |
Ok, I rarely post but I couldnt sleep so I decided to pass on the misery by creating a programming puzzle. you have an exam hall represented as an array of 42 entries. you have 19 JSS1 students, 11 JSS2 students and 12 JSS3 students sitting for a midterm exam in 2 courses. For the first paper, all the JSS1 have exactly the same paper, all the JSS2 students too but 6 JSS3 have a different paper from the rest. For the second paper, the JSS1 students still share the same paper and everyone else share the same papers Please note there are 4 confirmed unrepentant cheaters among the JSS1 students who must not sit with each other. Write a program (In Any Language of Your Choosing) or just an algorithm that seats the students in the best possible way to minimize cheating. (If you dont mind too, Do join me in pondering this at 3am :-) ) 1 Like |
Re: An Insomniac's Puzzle For Programmers. by Nobody: 6:48am On Aug 29, 2012 |
who you give you the work? chai the person wicked o for the first paper, do you mean questions from jss1 papers= questions from jss2 papers or jss1 papers != jss2 papers but each class share same papers with it's members i cant work on this at the moment. |
Re: An Insomniac's Puzzle For Programmers. by lordZOUGA(m): 8:08am On Aug 29, 2012 |
I think using a stack like structure solves this problem... The knowledge that 6 JS3 students does not write a certain paper is irrelevant since their seats are not taken up by other students from other classes..... You have your container structure of type hall that should accept data types of JS1, JS2 and JS3 students... The stack structures of the JS students should be in such a way that whenever a student is collected, it the derefrences its content by 1... In C++, something like this class StudentStack{ int count; student someStudents[count]; student getStudent(){return someStudents[count--];} }; you just have to make sure that no student should seat beside his classmate and since JS1has the largest number of students, the seating arrangement shud be like this: JS2, JS1, JS3, JS1, JS2, JS1, JS3, JS1...... JS2, JS3, JS2, JS3... to add students to hall according to seating positions should be something like code: while(hall.seats < SEAT_COUNT){ if(hall.lastAppended() != JS1){ hall.append(js1stack.getStudent()); //other codes to append other students should follow } } I think this works 1 Like |
Re: An Insomniac's Puzzle For Programmers. by Afam4eva(m): 1:10pm On Aug 29, 2012 |
My brain is not functioning properly at the moment...i'll be back... |
Re: An Insomniac's Puzzle For Programmers. by masterpiecer(m): 1:10pm On Aug 29, 2012 |
although this thread is on front page, why is only a few folks veiwing it? veiwing this topic: lordZOUGA(m), gidiMonsta(m), slimdiggi, ikiller and 3 guest(s) |
Re: An Insomniac's Puzzle For Programmers. by mkmyers45(m): 1:14pm On Aug 29, 2012 |
masterpiecer: although this thread is on front page, why is only a few folks veiwing it? not many are interested in stuff like this... |
Re: An Insomniac's Puzzle For Programmers. by Sxsells: 1:15pm On Aug 29, 2012 |
You are on your own ooo 1 Like |
Re: An Insomniac's Puzzle For Programmers. by mkmyers45(m): 1:15pm On Aug 29, 2012 |
webdezzi: who you give you the work? chai the person wicked o will appreciate this clarification too... |
Re: An Insomniac's Puzzle For Programmers. by Afam4eva(m): 1:16pm On Aug 29, 2012 |
mkmyers45:Not everyone on nairaland is a programmer. 1 Like |
Re: An Insomniac's Puzzle For Programmers. by Shaunscot(m): 1:17pm On Aug 29, 2012 |
To get more viewers, just add Kim Kardashian or DBanj to the topic. 1 Like |
Re: An Insomniac's Puzzle For Programmers. by mkmyers45(m): 1:18pm On Aug 29, 2012 |
afam4eva: true... |
Re: An Insomniac's Puzzle For Programmers. by hammedkola(m): 1:18pm On Aug 29, 2012 |
Yes! exactly, using the stack like structure works well...but am busy at work to write it now, just wanna have a say..catch ya later |
Re: An Insomniac's Puzzle For Programmers. by Nobody: 1:19pm On Aug 29, 2012 |
masterpiecer: although this thread is on front page, why is only a few folks veiwing it?only few interested in programming. |
Re: An Insomniac's Puzzle For Programmers. by masterpiecer(m): 1:19pm On Aug 29, 2012 |
and where is all the programmers in the house? u guyz should come and detonate dis bomb o |
Re: An Insomniac's Puzzle For Programmers. by masterpiecer(m): 1:21pm On Aug 29, 2012 |
Shaunscot: To get more viewers, just add Kim Kardashian or DBanj to the topic. and tontoh dike |
Re: An Insomniac's Puzzle For Programmers. by ektbear: 1:26pm On Aug 29, 2012 |
1. Can I reseat students after the first exam? 2. Can you give an example of what you mean by minimize cheating? I.e., for a smaller problem (say with 6 students rather than 42), give two configurations and say which one is better (and ideally, what the "score" associated with each configuration is). 3. Do I know the identities of the cheating students? Are they the only ones who will cheat, or might others also? |
Re: An Insomniac's Puzzle For Programmers. by hammedkola(m): 1:27pm On Aug 29, 2012 |
masterpiecer: and where is all the programmers in the house? programmers by mouth or by brain |
Re: An Insomniac's Puzzle For Programmers. by freecocoa(f): 1:36pm On Aug 29, 2012 |
If you don't want them to cheat,here's what to do. Tell them to get their writing materials ready and make sure they ease themselves of urine, poo or whatever nature call, because no one will be allowed to go outside the hall after being screened in, search them to make sure they don't have any micro chips(expo) on them before letting them into the exam hall, let the students sit on separate seats with a reasonable distance from each other and get like 6 very mean supervisors to supervise them while they write the exams, no biggy. 3 Likes |
Re: An Insomniac's Puzzle For Programmers. by ektbear: 1:40pm On Aug 29, 2012 |
What score does the following configuration get: ZX_ZX_ZX_ZX_X_X_X_X_X_X_X_X_X_X_X_X_X_X_X_ where the Xs contain the locations of the JSS1 students, the first 4 Zs are say the first for JSS2 students, and the blanks take the remaining? Does it get a perfect score (i.e., no cheating possible)? Or do JSS1 students and JSS2 students possibly have the same exam, and thus for example the first ZX pair in the configuration can cheat? 1 Like |
Re: An Insomniac's Puzzle For Programmers. by DonaldGenes(m): 2:25pm On Aug 29, 2012 |
afam4eva: My brain is not functioning properly at the moment...i'll be back...if na woman thing u go sabi shey?u no dey take last nah...hahahhaha |
Re: An Insomniac's Puzzle For Programmers. by speedzojie: 2:43pm On Aug 29, 2012 |
irrespective of the paper the java code below will make sure no two student of the same class sits directly beside each other. String sitting[] = new String[40]; int count = 0; for (int i = 0; i < sitting.length; i++) { if(count <= 19) { if(count == 0) { sitting[i] = "JSS1"; }else if(count == 1) { sitting[i] = "JSS3"; } else { if("JSS1".equals(sitting[i - 1])) { if("JSS2".equals(sitting[i - 1])) { sitting[i] = "JSS3"; }else { sitting[i] = "JSS2"; } }else { if("JSS2".equals(sitting[i - 1])) { sitting[i] = "JSS3"; }else { sitting[i] = "JSS2"; } } } }else { if("JSS2".equals(sitting[i - 1])) { sitting[i] = "JSS3"; }else { sitting[i] = "JSS2"; } } count++; } holla for further clarification. 1 Like |
Re: An Insomniac's Puzzle For Programmers. by lordZOUGA(m): 2:57pm On Aug 29, 2012 |
lordZOUGA: I think using a stack like structure solves this problem...this approach still makes sense to me.... If The container "hall" increments itself anytime a student is added, You can even add 3 students in a loop code: while(hall.count != MAX_STUDENTS){ if(JS1students.isEmpty()){ hall.append(JS2student.getStudent()); hall.append(JS3student.getStudent()); }else{ hall.append(JS2student.getStudent()); hall.append(JS1student.getStudent()); hall.append(JS3student.getStudent()); hall.append(JS1student.getStudent()); //with the above code you can add all students in less number of loops.. } } |
Re: An Insomniac's Puzzle For Programmers. by freecocoa(f): 3:09pm On Aug 29, 2012 |
^Na wa o, this una stuff must be very boring sha, just looking at what you wrote is giving me serious migraine . 1 Like |
Re: An Insomniac's Puzzle For Programmers. by speedzojie: 3:14pm On Aug 29, 2012 |
@lordzouga from your code there's possibilty of having two jss1 students sit directly beside each other because you will run out of jss2 and jss3 students before the hall gets filled, a good approach will be arranging the first nineteen seats in the hall with a must jss1 and either jss2 or jss3 student, and you must start with a jss1 followed by a jss3 .This method will ensure that when we run out of jss1(seat 19) we will have exactly 7 jss2 and 7 jss3 student left that can be evenly distributed; as simulated by the java code i posted earlier on. 1 Like |
Re: An Insomniac's Puzzle For Programmers. by lordZOUGA(m): 3:27pm On Aug 29, 2012 |
freecocoa: ^Na wa o, this una stuff must be very boring sha, just looking at what you wrote is giving me serious migraine .really? Okay, here is an easy fix: drop your device.. Go to ur drug cabinet or store and get an aspirin and then take it.. Go to the refridgerator and get an ice pack and put it against your forehead... Then pick your device back up and continue staring at the code... Dem no born the migraine well if em come back... No, programming is not boring at all... Just frustrating atimes... 1 Like |
Re: An Insomniac's Puzzle For Programmers. by Javanian: 3:41pm On Aug 29, 2012 |
lordZOUGA:This should work..The puzzle is quite easy...just has some irrevelant constraints... |
Re: An Insomniac's Puzzle For Programmers. by lordZOUGA(m): 3:49pm On Aug 29, 2012 |
speedzojie: @lordzouga from your code there's possibilty of having two jss1 students sit directly beside each other because you will run out of jss2 and jss3 students before the hall gets filled, a good approach will be arranging the first nineteen seats in the hall with a must jss1 and either jss2 or jss3 student, and you must start with a jss1 followed by a jss3 .This method will ensure that when we run out of jss1(seat 19) we will have exactly 7 jss2 and 7 jss3 student left that can be evenly distributed; as simulated by the java code i posted earlier on.No sir, there is no way my algorithm runs out of jss2 and JSS3 students before JS1 students... jss1 = 19, jss2 = 11, jss3 = 12 I must run out of JSS1 students before I run out of JSS2 and JSS3 students. Infact, I should have 4 leftover Jss2 and jss3 students 11 + 12 = 23 23 - 19 = 4 that I then arranged again Please look carefully at the algorithm.. |
Re: An Insomniac's Puzzle For Programmers. by lordZOUGA(m): 3:51pm On Aug 29, 2012 |
Javanian:EXACTLY!! Even the 4 cheating students are irrelevant |
Re: An Insomniac's Puzzle For Programmers. by DualCore1: 5:41pm On Aug 29, 2012 |
The following information are ambigous and you should remove them from your calculations. 1. The number of courses 2. The classes JS1-JS3 3. The nature of the papers written. Just write a code to sit 42 people putting 4 particular people among them in different seat rows. Here's my solution below, it isn't pure but you can't blame me... time and headache. ==============
========= Live demo: http://sawyerrken.net/kodewrita/ P.S: This solution isn't scalable. 1 Like |
Re: An Insomniac's Puzzle For Programmers. by lordZOUGA(m): 5:56pm On Aug 29, 2012 |
^ not remotely scalable... |
Re: An Insomniac's Puzzle For Programmers. by AZeD1(m): 6:01pm On Aug 29, 2012 |
Dual Core: The following information are ambigous and you should remove them from your calculations.Good simple solution. |
Re: An Insomniac's Puzzle For Programmers. by AZeD1(m): 6:04pm On Aug 29, 2012 |
lordZOUGA:I think he just wants to make sure they don't seat together i.e the cheating students. |
Business Objects Connectivity To Oracle Rdb Database Issue / Complete Array Of Countries And Nigerian States [open Source] / Mathematics As Backbone Of Programming
(Go Up)
Sections: politics (1) business autos (1) jobs (1) career education (1) romance computers phones travel sports fashion health religion celebs tv-movies music-radio literature webmasters programming techmarket Links: (1) (2) (3) (4) (5) (6) (7) (8) (9) (10) Nairaland - Copyright © 2005 - 2024 Oluwaseun Osewa. All rights reserved. See How To Advertise. 143 |