from
__future__
import
division, generators, print_function, with_statement
r
__license__
=
r
try
:
from
d
import
sl, pr, pv
except
:
def
sl(
*
a,
*
*
o):
return
def
pr(
*
a,
*
*
o):
return
def
pv(
*
a,
*
*
o):
return
try
:
from
printobject
import
print_object
except
:
def
print_object(
*
a,
*
*
o):
return
0
try
:
from
intx
import
intx
except
:
intx
=
int
def
depth():
from
inspect
import
currentframe
d
=
-
2
f
=
currentframe()
while
'f_back'
in
dir
(f):
d
+
=
1
f
=
f.f_back
return
d
def
eprint(
*
a,
*
*
o):
if
'file'
not
in
o:
o[
'file'
]
=
stderr
f
=
o[
'file'
]
r
=
print
(
*
a,
*
*
o)
if
o
else
print
(
*
a)
f.flush()
return
r
def
nestloop(
sum
,xlist,limit,sss):
deep
=
depth()
-
1
xlist.append(
0
)
for
num
in
range
(
*
sss):
xlist[
-
1
]
=
num
sn
=
sum
+
num
if
sn
=
=
limit:
print
(
'{:>4d}:'
.
format
(deep),
' '
.join([
repr
(x)
for
x
in
xlist]))
stdout.flush()
break
if
sn>limit:
break
nestloop(sn,xlist,limit,sss)
xlist.pop(
-
1
)
return
def
main(args):
errors
=
0
cname
=
args.pop(
0
)
if
len
(args) >
4
:
return
'too many arguments - max 4 - '
\
'need: [ limit (8) [ start (1) [ last (start+1) [ step (1) ] ] ] ]'
names
=
(
'limit'
,
'start'
,
'last'
,
'step'
)
nums
=
[]
for
x,arg
in
enumerate
(args):
if
x >
3
:
eprint(
'argument'
,
repr
(
1
+
x),
'['
+
names[x]
+
']'
,
'is an extra argument'
)
errors
+
=
1
continue
try
:
n
=
intx(arg)
except
:
eprint(
'argument'
,
repr
(
1
+
x),
'['
+
names[x]
+
']'
,
'is'
,
'('
+
repr
(arg)
+
')'
,
'not a valid number'
)
errors
+
=
1
nums.append(n)
if
len
(nums)
=
=
0
: nums
+
=
[
15
,
3
,
5
,
1
]
if
len
(nums)
=
=
1
: nums
+
=
[
3
,
5
,
1
]
if
len
(nums)
=
=
2
: nums
+
=
[nums[
1
]
+
1
,
1
]
if
len
(nums)
=
=
3
: nums
+
=
[
1
]
limit, start, last, step
=
nums
print
(
'limit ='
,
repr
(limit))
print
(
'start ='
,
repr
(start))
print
(
' last ='
,
repr
(last))
print
(
' step ='
,
repr
(step))
stdout.flush()
if
errors:
return
'aborting due to '
+
repr
(errors)
+
' errors'
nestloop(
0
,[],limit,(start,last
+
1
,step))
return
0
if
__name__
=
=
'__main__'
:
from
sys
import
argv, stderr, stdout
if
bytes
=
=
str
:
BrokenPipeError, FileNotFoundError
=
IOError, OSError
try
:
result
=
main(argv)
except
BrokenPipeError:
result
=
99
except
KeyboardInterrupt:
stderr.flush()
print
()
result
=
98
stderr.flush()
stdout.flush()
if
result
is
0
or
result
is
None
or
result
is
True
:
exit(
0
)
if
result
is
1
or
result
is
False
:
exit(
1
)
if
isinstance
(result,
str
):
print
(result,
file
=
stderr)
exit(
2
)
try
:
exit(
int
(result))
except
ValueError:
print
(
str
(result),
file
=
stderr)
exit(
3
)
except
TypeError:
exit(
4
)