Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Open sidebar
machine_learning
skython
Commits
6106b3bf
Commit
6106b3bf
authored
Jul 31, 2015
by
Trevor Cappallo
Browse files
add timer
parent
2a43a300
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
23 additions
and
6 deletions
+23
-6
skython.py
skython.py
+23
-6
No files found.
skython.py
View file @
6106b3bf
import
random
import
copy
import
time
MAGIC_NUMBER
=
-
12345
MAX_PROG_SIZE
=
100
...
...
@@ -23,6 +23,7 @@ ENABLED = [
'PEEK'
,
'SKIP'
,
'LAND'
,
'LOR'
,
'IFDO'
,
'IFF'
,
'NOT'
,
'MOD'
,
]
ENABLED
=
ENABLED_FIB
TIMEOUT
=
250
def
make_program
(
length
):
...
...
@@ -156,12 +157,15 @@ def run_program(prog, model_in, model_out, timeout=TIMEOUT, trace=False):
timeout
=
total
=
redundant
=
successes
=
counter
=
degen
=
exact
=
length
=
0
lower_bound
,
upper_bound
=
5
,
8
lower_bound
,
upper_bound
=
5
,
5
model_in
=
[]
model_out
=
[
1
,
1
,
2
,
3
,
5
,
8
,
13
]
#model_out = [0, 1, 2, 3, 4, 5]
wins
=
0
wins_needed
=
100
solutions
=
set
()
time_start
=
time
.
time
()
while
(
True
):
prog
=
make_program
(
random
.
randint
(
lower_bound
,
upper_bound
))
output
=
[
MAGIC_NUMBER
]
+
[
0
]
*
99
...
...
@@ -203,6 +207,19 @@ while (True):
break
if
match
==
len
(
model_out
):
run_program
(
prog
,
model_in
,
model_out
,
trace
=
True
)
print
"---VICTORY--- total ="
,
total
break
wins
+=
1
pretty_prog
=
" "
.
join
([
INSTRUCTIONS
[
op
]
for
op
in
prog
])
solutions
.
add
(
pretty_prog
)
if
wins
==
wins_needed
:
time_end
=
time
.
time
()
time_elapsed
=
time_end
-
time_start
#run_program(prog, model_in, model_out, trace=True)
print
"---VICTORY---"
print
"total ="
,
total
if
wins
>
1
:
print
"average ="
,
total
/
wins
print
"mean solution time: {:.2f} s"
.
format
(
time_elapsed
)
print
"
\n
{} solutions:"
.
format
(
len
(
solutions
))
for
prog
in
solutions
:
print
prog
break
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment