Re: [Tutor] crashed with Runtime Error: NZEC (non-zero exit code)

2008-02-27 Thread Eric Brunson




Alan Gauld wrote:

  "bob gailer" [EMAIL PROTECTED] wrote

  
  

  i don't really understand that. you are trying to say that the 
tests
from the online judge are not "exactly good" ?
  

Yes that's exactly what I'm saying. At least one test case has a
non-decimal character.

  
  
Which actually makes it a very good test since thats
exactly the kind of thing you should be testing for :-)
A test suite that only checks valid data is a bad test.

  


That's fine if writing a test suite for production software, but from
the problem description: "There is a string containing only decimal
digit characters."

Testing for valid input seems to be outside the scope of the problem
definition. :-)




___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] crashed with Runtime Error: NZEC (non-zero exit code)

2008-02-27 Thread Andrei Petre
i'm  thinking the same way Eric do.

On Wed, Feb 27, 2008 at 11:18 PM, Eric Brunson [EMAIL PROTECTED] wrote:

  Alan Gauld wrote:

 bob gailer [EMAIL PROTECTED] [EMAIL PROTECTED] wrote



  i don't really understand that. you are trying to say that the
 tests
 from the online judge are not exactly good ?


  Yes that's exactly what I'm saying. At least one test case has a
 non-decimal character.


  Which actually makes it a very good test since thats
 exactly the kind of thing you should be testing for :-)
 A test suite that only checks valid data is a bad test.




 That's fine if writing a test suite for production software, but from the
 problem description:  There is a string containing only decimal digit
 characters.

 Testing for valid input seems to be outside the scope of the problem
 definition.  :-)



 ___
 Tutor maillist  -  Tutor@python.org
 http://mail.python.org/mailman/listinfo/tutor


___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] crashed with Runtime Error: NZEC (non-zero exit code)

2008-02-27 Thread Alan Gauld
Eric Brunson [EMAIL PROTECTED] wrote
 Alan Gauld wrote:

 Which actually makes it a very good test since thats
 exactly the kind of thing you should be testing for :-)

Note the smiley...

 A test suite that only checks valid data is a bad test.

 Testing for valid input seems to be outside the scope of the problem 
 definition.  :-)

As I note yours...

However, there is a bit of a serious point here too in that
users never ask for data validation (at least mine never do!)
they just expect it. So I still maintain that any test suite
no matter how basic should always cover some tests
for invalid input data.

Even well intentioned users will make mistakes and a program
that crashes on invalid input is not user friendly - even if the
only user is the author!

Alan G 


___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] crashed with Runtime Error: NZEC (non-zero exit code)

2008-02-27 Thread Eric Brunson
Alan Gauld wrote:
 Eric Brunson [EMAIL PROTECTED] wrote
   
 Alan Gauld wrote:
 

Glad we both noted the smileys.  :-)

 However, there is a bit of a serious point here too in that
 users never ask for data validation (at least mine never do!)
 they just expect it. So I still maintain that any test suite
 no matter how basic should always cover some tests
 for invalid input data.
   

Definitely a valid point.  I just spent twenty minutes this afternoon 
tracking down a problem in my own code where, because I was supplying 
the input from a database, I could count on converting the value to a 
float.  However, that didn't account for not finding a value at all.

 Even well intentioned users will make mistakes and a program
 that crashes on invalid input is not user friendly - even if the
 only user is the author!
   

Bingo.  :-)

Always a pleasure,
e.


___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] crashed with Runtime Error: NZEC (non-zero exit code)

2008-02-27 Thread bob gailer
This thread got started due to the DIV15 problem on the Sphere Online Judge.

This is almost a black box test environment. Submit a program. If it 
generates the expected output you get accepted. The other results are 
 compilation error, time limit exceeded,  runtime error (followed 
by (SIGSEGV), (SIGABRT), (other), (NZEC)), or wrong answer. If the 
program did not exceed the time limit you also get the execution time. 
(Some problems give problem-specific results but that does not apply to 
the DIV15 problem)

In looking over the status list of submitted programs I noted cases 
where the results were 100, 102. I wonder what that means and how it 
was generated

So there is a (limited) way to get information out of a program, and 
that is to use time.sleep() to control the execution time. But that 
costs one program submission for each thing one might want to test. 
That's how I determined there was a bad character in the input.

So now I imagine creating an automated program submitter, so I could 
create a large number of test cases and an automated way to read the 
execution times off the results page. Eventually one might garner enough 
information.

Of course that might get the attention of the site operators and lead to 
a change in how things are run to discourage automated testing.

-- 
Bob Gailer
919-636-4239 Chapel Hill, NC

___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] crashed with Runtime Error: NZEC (non-zero exit code)

2008-02-26 Thread bob gailer
Andrei Petre wrote:
 https://www.spoj.pl/problems/DIV15/
I wrote my own version and submitted it. I got NZEC also.

The evidence pointed to a character in the test data other than 0123456789.

So I contrived a way to test for this and found that to be true. I don't 
know what the character is or which test case it is in but there is at 
least one bad character, and it is  chr(32) (i.e. a control character).

After revising my program to eliminate these bad characters I now get 
wrong answer. So now I revise my algorithm.

-- 
Bob Gailer
919-636-4239 Chapel Hill, NC

___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] crashed with Runtime Error: NZEC (non-zero exit code)

2008-02-26 Thread bob gailer
I will share my algorithm just for the heck of it and to see if you see 
any problem.

Underlying theory:
  Divisible by 15 == divisible by 3 and divisible by 5
  If a number is divisible by 3 any rearrangement of its digits is also 
divisible by 3.
  Therefore to get the largest number, put the digits in descending order.
  If the number is not divisible by 3 it can be made divisible by 3 by 
removing one or 2 non-multiple-of-3 digits
  To be divisible by 5 the rightmost digit must be 0 or 5. If it is 
neither then a 5 must be moved from the interior to the end.
   
s = the test case input

If there are no '0's and no '5's  in s then impossible.

Convert s (string) to a list, sort it, reverse it. If rightmost digit is 
not '0' or '5', remove a '5' from the list
(we will append it at checkout)

On a parallel path:

i = int(s)  # make numeric
r = i % 3 # get modulo
if r == 0 # divisible by 3 (regardless of the order of the digits)
  proceed to checkout
else
  attempt to remove one or two digits to bring the modulo to 0
  if possible remove just 1 digit (the lower the better) (the candidates 
are, for r ==1-1,4,7  r==2-2,5,8)
  otherwise if possible remove 2 digits (the lower the better) (the 
candidates are, for r ==2-1,4,7  r==1-2,5,8)
  otherwise impossible

checkout:
  if we removed a '5' from the list, append it
  join and print the list

-- 
Bob Gailer
919-636-4239 Chapel Hill, NC

___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] crashed with Runtime Error: NZEC (non-zero exit code)

2008-02-26 Thread bob gailer
Note I cc: [EMAIL PROTECTED] Please do so also so the other tutors can 
follow the discussion.

Andrei Petre wrote:
 the theory seems just like mine :)

 your way to implement it looks fine ( although it supports some 
 optimization :))

 But:

 - i don't understand :
  i = int(s)
  where s = the test case input (= a LIST ??)
s is a string

   you should summs up the elements of the list
In the pursuit of performance I chose int(s) as being potentially a lot 
faster than looping over all the chars, applying int() to each and summing.

 - it's not very clear in your implementation what happens with the 
 case : 815. try it
I get 15. However 875 gives a wrong answer! Turns out that if the 
rightmost digit is not 0 I must remove a 5 even if that is the rightmost 
digit!

Even after fixing that I still get wrong answer!

 and in one of your posts, you said:

 The evidence pointed to a character in the test data other than 
 0123456789.

 So I contrived a way to test for this and found that to be true. I don't
 know what the character is or which test case it is in but there is at
 least one bad character, and it is  chr(32) (i.e. a control character).
 i don't understand , in your

 i don't really understand that. you are trying to say that the tests 
 from the online judge are not exactly good ?
Yes that's exactly what I'm saying. At least one test case has a 
non-decimal character.
  

-- 
Bob Gailer
919-636-4239 Chapel Hill, NC

___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] crashed with Runtime Error: NZEC (non-zero exit code)

2008-02-26 Thread Alan Gauld

bob gailer [EMAIL PROTECTED] wrote

 i don't really understand that. you are trying to say that the 
 tests
 from the online judge are not exactly good ?
 Yes that's exactly what I'm saying. At least one test case has a
 non-decimal character.

Which actually makes it a very good test since thats
exactly the kind of thing you should be testing for :-)
A test suite that only checks valid data is a bad test.

Alan G. 


___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


[Tutor] crashed with Runtime Error: NZEC (non-zero exit code)

2008-02-24 Thread Andrei Petre
Hello,

I wrote a code for a problem and submitted to an online judge, a program
that runs my program against a set of predefined input data.

I wrote it for exercise my python writing. In don't want to discuss the
algorithm here!

I dare to ask for help because the answer was : crashed with Runtime Error:
NZEC (non-zero exit code). I heard that is a general error for most
interpreters and elsewhere that NZEC error code has to do with exceptions.

So, i'm seeking for a possible problem with the coding, not with the
algorithm.

Here, the code. (l also attached it in a file)
Using characters of the string, the program should construct the maximum
number which divides by fifteen without remainder.

example

*Input:*
1
02041

*Output:*
4200

[code]
import sys

def write(number): # assamble the number
# assure the 5 divisibility
if number[0] != 0:
number[0] -= 1
last_d = 0
else:
number[5] -= 1
last_d = 5

zero = True
for i in reversed(range(1,10)):
 for j in range(digits[i]):
 sys.stdout.write(i)
 zero = False

# leading zeroes should be omitted
if zero == False:
for i in range(digits[0]):
sys.stdout.write(0)

print last_d

def remove_item(d,item):
if type(item) != list:
d[item] -= 1
else:
d[item[0]] -= 1
d[item[1]] -= 1

def case5(d,item):
# return True if i try to remove the only five that assure the
divisibility with 5
return item == 5 and d[0] == 0 and d[item] == 1

def exist(d,item):
found = False
if type(item) != list:
if d[item] != 0 and case5(d,item) == False:
found = True
else:
p1 = d[item[0]] != 0 and case5(d,d[item[0]]) == False
d[item[0]] -= 1
p2 = d[item[1]] != 0 and case5(d,d[item[1]]) == False
d[item[0]] += 1
if p1 == True and p2 == True:
found = True
return found

def remove(d, mult):
found = False
for item in mult:
if exist(d,item) == True:
remove_item(d,item)
found = True
break
if found == False:
d = []
return d

def remove_all(digits,rest):
# if the number is the form 3k+1, i try to remove one 3k+1 digit or two
3k+2 digits
# if the number is the form 3k+2, i try to remove one 3k+2 digit or two
3k+2 digits
one = [1,4,7,[2,2],[2,5],[2,8],[5,5],[5,8],[8,8]]
two = [2,5,8,[1,1],[1,4],[1,7],[4,4],[4,7],[7,7]]
if rest == 1:
d = remove(digits, one)
else:
d = remove(digits, two)
return d

def resolve(digits):
suma = 0
for i in range(10):
suma += i*digits[i]
rest = suma % 3
if rest != 0: # if it's not divisible with 3 i try to remove some digits
digits = remove_all(digits,rest)
return digits

t = int(raw_input())
for tt in range(t):
line = raw_input()
digits = [0]*10
# counts the frequence of digits in the string
for i in range(len(line)):
digits[int(line[i])] += 1
# if it's not divisible with 5
if digits[0] == 0 and digits[5] == 0:
print(impossible)
else:
number = resolve(digits)
if(number == []):
print(impossible)
else:
write(number)
[/code]


Any alternatives for the personal rambling(if it's a wrong way to do it, of
course):

L = [1,2,[3,4],[5,5]]
for item in L:
   if type(item) == list:
 print L[item[0]], L[item[1]]
   else:
 print L[item]

Thanks,

Andrei
import sys

def write(number): # assamble the number
# assure the 5 divisibility
if number[0] != 0:
number[0] -= 1
last_d = 0
else:
number[5] -= 1
last_d = 5

zero = True
for i in reversed(range(1,10)):
 for j in range(digits[i]):
 sys.stdout.write(i)
 zero = False
 
# leading zeroes should be omitted 
if zero == False:
for i in range(digits[0]):
sys.stdout.write(0)

print last_d

def remove_item(d,item):
if type(item) != list:
d[item] -= 1
else:
d[item[0]] -= 1
d[item[1]] -= 1

def case5(d,item):
# return True if i try to remove the only five that assure the divisibility 
with 5
return item == 5 and d[0] == 0 and d[item] == 1

def exist(d,item):
found = False
if type(item) != list:
if d[item] != 0 and case5(d,item) == False:
found = True
else:
p1 = d[item[0]] != 0 and case5(d,d[item[0]]) == False
d[item[0]] -= 1
p2 = d[item[1]] != 0 and case5(d,d[item[1]]) == False
d[item[0]] += 1
if p1 == True and p2 == True:
found = True
return found

def remove(d, mult):
found = False
for item in mult:
if exist(d,item) == True:
remove_item(d,item)
found = True
break
if found == False:
d = []
return d   

Re: [Tutor] crashed with Runtime Error: NZEC (non-zero exit code)

2008-02-24 Thread bob gailer
Andrei Petre wrote:
 Hello,

 I wrote a code for a problem and submitted to an online judge, a 
 program that runs my program against a set of predefined input data.
Did you run the code yourself? It would appear that you did not.

Before submitting to an online judge run the code on your own computer. 
Can you do that? Do you know how?

When you run it you will discover an error. Fix that and try again.

[snip]

-- 
Bob Gailer
919-636-4239 Chapel Hill, NC

___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] crashed with Runtime Error: NZEC (non-zero exit code) WAIT!!!

2008-02-24 Thread Bob Gailer
Hold the phone! Ignore previous email. Working...
-- 
Bob Gailer
919-636-4239 Chapel Hill, NC


___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] crashed with Runtime Error: NZEC (non-zero exit code)

2008-02-24 Thread Bob Gailer
OK I maintain what I wrote earlier:

Did you run the code yourself? It would appear that you did not.

Before submitting to an online judge run the code on your own computer.
Can you do that? Do you know how?

When you run it you will discover an error. Fix that and try again.

[snip]

-- 
Bob Gailer
919-636-4239 Chapel Hill, NC


___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor