Coding Contest - August 13, 2011

From syn2cat - HackerSpace.lu
Revision as of 21:15, 13 August 2011 by Gunstick (Talk | contribs)

Jump to: navigation, search
Note: this article is about a passed event.
Add your Event
Event.png
Coding Contest - August 13, 2011
Demonstrate your coding skills
Weareinnovative.png
Type of Event: Event
From: 2011/08/13 03:00:00 PM
Till: 2011/08/13 06:00:00 PM
Recurring: no
Organizer: syn2cat
Cost: 0 EUR0 $
0 £
0 CHF
Mandatory registration:


Attendees: Kwisatz, prometheus, SteveClement, Gunstick, Azunix
Log-in to RSVP
Contact Person(s): Destructive (mail)
Keywords:
Location
Where: Hackerspace, Strassen (11, rue du Cimetière, L-8018 Strassen, Luxembourg)
Map:
Loading map...
Tools
QrCode: QR-e8b183c5e5d2f76abb8515c0e4239e2a.png
Add to your calendar: Download … further results
Alternate picture: None
Announce globally: no
In this contest you have to solve problems of algorithmic nature with different degrees of difficulty. You can use the programming language you like.

"File:" cannot be used as a page name in this wiki.



The goal of this contest is not to find the best coder, but to enjoy coding together and to motivate others to start coding. If you can write a "hello world" program in any language, you are welcome. There will be certainly someone to help you to solve the tasks.

We will use the following example problem to make us familiar with the contest system.


Contents

Problem

Mr. Foo has to determine if his students have passed the year. As he has many students which have written many tests, he can't use his calculator, because it would take him too long. He knows that you are a skilled hacker, so he has asked you to make a program to automate his task.

He has S students. Each student has written N tests. The test scores ranges from 0 to 60 (both inclusive). A student has passed his year if he has an average score of more or equal to 30. The average is not rounded.


Input

You are given an input file. The first line consists of 2 integers: the number of students S (1 <= S <= 1000) and the number of tests N (1 <= N <= 1000). S lines follow, which consists of N integers, representing the scores of a student.


Output

You have to create an output file which contains one line per student. Each containing 'PASSED' if he has passed his year, otherwise 'FAILED'.


Input example

4 2
29 30
30 30
50 60
0 58

Output example

FAILED
PASSED
PASSED
FAILED

Solutions

bash

kwisatz@arbre:~/coding/bash% bash sba.sh i
FAILED
PASSED
PASSED
FAILED
kwisatz@arbre:~/coding/bash% wc -c sba.sh
128 sba.sh
kwisatz@arbre:~/coding/bash% cat sba.sh
tail -n+2 $1|while read i;do k=0;s=0;for j in $i;do((++k));((s=s+j));done;[[ $s -ge $((30*k)) ]]&&echo PASSED||echo FAILED;done

php

jedi@test:~/work/coding$ php foo.php
FAILED
PASSED
PASSED
FAILED
jedi@test:~/work/coding$ wc -c foo.php
116 foo.php
jedi@test:~/work/coding$ cat foo.php
<?$h=file('i',2);$i=1;while($h[$i]) echo(((array_sum($a=explode(' ',$h[$i++]))/count($a))>=30)?PASSED:FAILED)."\n";

awk

gunstick@manion:~$ awk -f 1.awk test.txt 
FAILED
PASSED
PASSED
FAILED
gunstick@manion:~$ wc -c 1.awk 
61 1.awk
gunstick@manion:~$ cat 1.awk
NR>1{s=i=0;for(;i<NF;)s+=$++i;print s/i<30?"FAILED":"PASSED"}

perl

gunstick@manion:~/contest$ perl foo.pl foo1.in 
FAILED
PASSED
PASSED
FAILED
gunsick@manion:~/contest$ wc -c foo.pl 
92 foo.pl
gunstick@manion:~/contest$ cat foo.pl

Invalid language.

You need to specify a language like this: <source lang="html4strict">...</source>

Supported languages for syntax highlighting:

4cs, 6502acme, 6502kickass, 6502tasm, 68000devpac, abap, actionscript, actionscript3, ada, algol68, apache, applescript, apt_sources, asm, asp, autoconf, autohotkey, autoit, avisynth, awk, bascomavr, bash, basic4gl, bf, bibtex, blitzbasic, bnf, boo, c, c_loadrunner, c_mac, caddcl, cadlisp, cfdg, cfm, chaiscript, cil, clojure, cmake, cobol, coffeescript, cpp, cpp-qt, csharp, css, cuesheet, d, dcs, delphi, diff, div, dos, dot, e, ecmascript, eiffel, email, epc, erlang, euphoria, f1, falcon, fo, fortran, freebasic, fsharp, gambas, gdb, genero, genie, gettext, glsl, gml, gnuplot, go, groovy, gwbasic, haskell, hicest, hq9plus, html4strict, html5, icon, idl, ini, inno, intercal, io, j, java, java5, javascript, jquery, kixtart, klonec, klonecpp, latex, lb, lisp, llvm, locobasic, logtalk, lolcode, lotusformulas, lotusscript, lscript, lsl2, lua, m68k, magiksf, make, mapbasic, matlab, mirc, mmix, modula2, modula3, mpasm, mxml, mysql, newlisp, nsis, oberon2, objc, objeck, ocaml, ocaml-brief, oobas, oracle11, oracle8, oxygene, oz, pascal, pcre, per, perl, perl6, pf, php, php-brief, pic16, pike, pixelbender, pli, plsql, postgresql, povray, powerbuilder, powershell, proftpd, progress, prolog, properties, providex, purebasic, pycon, python, q, qbasic, rails, rebol, reg, robots, rpmspec, rsplus, ruby, sas, scala, scheme, scilab, sdlbasic, smalltalk, smarty, sql, systemverilog, tcl, teraterm, text, thinbasic, tsql, typoscript, unicon, uscript, vala, vb, vbnet, verilog, vhdl, vim, visualfoxpro, visualprolog, whitespace, whois, winbatch, xbasic, xml, xorg_conf, xpp, yaml, z80, zxbasic


($n=<>)=~s/^\d//;while(<>){$s=$u=0;$u=map{$s+=$_}split;print $s/$u<30?"FAILED\n":"PASSED\n"}

python

# CodingContest - Help Mister Foo
# No focus on getting a short code
 
rfile = open("marks.txt")
wfile = open("results.txt",'w')
 
students, tests = rfile.readline().split(" ")
 
for students in rfile:
  values = students.rstrip("\n").split(" ")
  if (sum(int(x) for x in values)) / float(tests) < 30:
    wfile.write("Failed!\n")
  else:
    wfile.write("Passed!\n")
 
rfile.close()
wfile.close()

---

Host:08-13-2011 user$ python3 Help_Mister_Foo.py 
Host:08-13-2011 user$ cat results.txt 
Failed!
Passed!
Passed!
Failed!
Host:08-13-2011 user$ wc -c Help_Mister_Foo.py 
     358 Help_Mister_Foo.py
Personal tools
Namespaces

Variants
Actions
Navigation
syn2cat
Hackerspace
Activities
Initiatives
Community
Tools
Tools