Advertisement
tzot

run.sh - quick run a Project Euler problem###.py script

Feb 22nd, 2012
96
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 1.39 KB | None | 0 0
  1. if [ "$1" = -d ]
  2. then
  3.     seconds=$2
  4.     shift 2
  5. else
  6.     seconds=
  7. fi
  8. problem=problem$1
  9. grep -F 'model name' /proc/cpuinfo | head -1 | cut -d: -f2
  10. if taskset -c 0 true 2>/dev/null
  11. then
  12.     cmd='taskset -c 0 python2.7'
  13. else
  14.     cmd=python2.7
  15. fi
  16. exec $cmd -O -c "
  17. import sys, eulerlib, $problem
  18. $problem.eulerlib= eulerlib
  19. try:
  20.    test_argument, test_result= $problem.__test__
  21. except AttributeError:
  22.    print 'No test data.'
  23.    success= True
  24. else:
  25.    test_run_result= $problem.main(test_argument)
  26.    print 'Expected', test_result, 'got', test_run_result
  27.    if test_run_result == test_result:
  28.    print 'No test data.'
  29.    success= True
  30. else:
  31.    test_run_result= $problem.main(test_argument)
  32.    print 'Expected', test_result, 'got', test_run_result
  33.    if test_run_result == test_result:
  34.        print 'Test succeeds, proceeding with run.'
  35.        success= True
  36.    else:
  37.        print 'Test fails!'
  38.        success= False
  39. if success:
  40.    time0= eulerlib.cpu_used()
  41.    result= Ellipsis
  42.    eulerlib.only_one_minute($seconds)
  43.    try:
  44.        result= $problem.main()
  45.    except SystemExit:
  46.        pass
  47.    except KeyboardInterrupt:
  48.        print 'Interrupted'
  49.    except MemoryError:
  50.        print 'Memory error'
  51.    else:
  52.        print 'Answer to Project Euler problem $1:', result
  53.    time1= eulerlib.cpu_used()
  54.    print 'Time used:', time1 - time0, 'seconds'"
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement