euler-manager 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +21 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +22 -0
- data/README.md +37 -0
- data/Rakefile +1 -0
- data/bin/euler +145 -0
- data/data/answers.yml +456 -0
- data/data/problems/1.yml +7 -0
- data/data/problems/10.yml +8 -0
- data/data/problems/100.yml +13 -0
- data/data/problems/101.yml +49 -0
- data/data/problems/102.yml +16 -0
- data/data/problems/103.yml +26 -0
- data/data/problems/104.yml +15 -0
- data/data/problems/105.yml +21 -0
- data/data/problems/106.yml +19 -0
- data/data/problems/107.yml +20 -0
- data/data/problems/108.yml +32 -0
- data/data/problems/109.yml +33 -0
- data/data/problems/11.yml +33 -0
- data/data/problems/110.yml +19 -0
- data/data/problems/111.yml +21 -0
- data/data/problems/112.yml +15 -0
- data/data/problems/113.yml +13 -0
- data/data/problems/114.yml +106 -0
- data/data/problems/115.yml +17 -0
- data/data/problems/116.yml +76 -0
- data/data/problems/117.yml +82 -0
- data/data/problems/118.yml +9 -0
- data/data/problems/119.yml +11 -0
- data/data/problems/12.yml +13 -0
- data/data/problems/120.yml +17 -0
- data/data/problems/121.yml +15 -0
- data/data/problems/122.yml +42 -0
- data/data/problems/123.yml +13 -0
- data/data/problems/124.yml +58 -0
- data/data/problems/125.yml +12 -0
- data/data/problems/126.yml +17 -0
- data/data/problems/127.yml +31 -0
- data/data/problems/128.yml +18 -0
- data/data/problems/129.yml +12 -0
- data/data/problems/13.yml +6 -0
- data/data/problems/130.yml +19 -0
- data/data/problems/131.yml +12 -0
- data/data/problems/132.yml +12 -0
- data/data/problems/133.yml +13 -0
- data/data/problems/134.yml +19 -0
- data/data/problems/135.yml +20 -0
- data/data/problems/136.yml +17 -0
- data/data/problems/137.yml +36 -0
- data/data/problems/138.yml +20 -0
- data/data/problems/139.yml +15 -0
- data/data/problems/14.yml +28 -0
- data/data/problems/140.yml +29 -0
- data/data/problems/141.yml +14 -0
- data/data/problems/142.yml +14 -0
- data/data/problems/143.yml +20 -0
- data/data/problems/144.yml +30 -0
- data/data/problems/145.yml +11 -0
- data/data/problems/146.yml +9 -0
- data/data/problems/147.yml +14 -0
- data/data/problems/148.yml +11 -0
- data/data/problems/149.yml +41 -0
- data/data/problems/15.yml +11 -0
- data/data/problems/150.yml +34 -0
- data/data/problems/151.yml +19 -0
- data/data/problems/152.yml +12 -0
- data/data/problems/153.yml +57 -0
- data/data/problems/154.yml +16 -0
- data/data/problems/155.yml +22 -0
- data/data/problems/156.yml +27 -0
- data/data/problems/157.yml +34 -0
- data/data/problems/158.yml +19 -0
- data/data/problems/159.yml +29 -0
- data/data/problems/16.yml +6 -0
- data/data/problems/160.yml +8 -0
- data/data/problems/161.yml +15 -0
- data/data/problems/162.yml +15 -0
- data/data/problems/163.yml +19 -0
- data/data/problems/164.yml +8 -0
- data/data/problems/165.yml +32 -0
- data/data/problems/166.yml +15 -0
- data/data/problems/167.yml +17 -0
- data/data/problems/168.yml +13 -0
- data/data/problems/169.yml +10 -0
- data/data/problems/17.yml +11 -0
- data/data/problems/170.yml +16 -0
- data/data/problems/171.yml +13 -0
- data/data/problems/172.yml +6 -0
- data/data/problems/173.yml +12 -0
- data/data/problems/174.yml +20 -0
- data/data/problems/175.yml +21 -0
- data/data/problems/176.yml +9 -0
- data/data/problems/177.yml +16 -0
- data/data/problems/178.yml +9 -0
- data/data/problems/179.yml +10 -0
- data/data/problems/18.yml +21 -0
- data/data/problems/180.yml +34 -0
- data/data/problems/181.yml +7 -0
- data/data/problems/182.yml +35 -0
- data/data/problems/183.yml +27 -0
- data/data/problems/184.yml +18 -0
- data/data/problems/185.yml +22 -0
- data/data/problems/186.yml +28 -0
- data/data/problems/187.yml +16 -0
- data/data/problems/188.yml +10 -0
- data/data/problems/189.yml +15 -0
- data/data/problems/19.yml +12 -0
- data/data/problems/190.yml +13 -0
- data/data/problems/191.yml +15 -0
- data/data/problems/192.yml +27 -0
- data/data/problems/193.yml +7 -0
- data/data/problems/194.yml +18 -0
- data/data/problems/195.yml +13 -0
- data/data/problems/196.yml +25 -0
- data/data/problems/197.yml +16 -0
- data/data/problems/198.yml +21 -0
- data/data/problems/199.yml +14 -0
- data/data/problems/2.yml +10 -0
- data/data/problems/20.yml +22 -0
- data/data/problems/200.yml +12 -0
- data/data/problems/201.yml +20 -0
- data/data/problems/202.yml +14 -0
- data/data/problems/203.yml +21 -0
- data/data/problems/204.yml +11 -0
- data/data/problems/205.yml +10 -0
- data/data/problems/206.yml +6 -0
- data/data/problems/207.yml +20 -0
- data/data/problems/208.yml +12 -0
- data/data/problems/209.yml +27 -0
- data/data/problems/21.yml +13 -0
- data/data/problems/210.yml +10 -0
- data/data/problems/211.yml +11 -0
- data/data/problems/212.yml +41 -0
- data/data/problems/213.yml +11 -0
- data/data/problems/214.yml +15 -0
- data/data/problems/215.yml +18 -0
- data/data/problems/216.yml +14 -0
- data/data/problems/217.yml +27 -0
- data/data/problems/218.yml +14 -0
- data/data/problems/219.yml +19 -0
- data/data/problems/22.yml +13 -0
- data/data/problems/220.yml +24 -0
- data/data/problems/221.yml +20 -0
- data/data/problems/222.yml +7 -0
- data/data/problems/223.yml +12 -0
- data/data/problems/224.yml +12 -0
- data/data/problems/225.yml +11 -0
- data/data/problems/226.yml +16 -0
- data/data/problems/227.yml +13 -0
- data/data/problems/228.yml +23 -0
- data/data/problems/229.yml +30 -0
- data/data/problems/23.yml +19 -0
- data/data/problems/230.yml +23 -0
- data/data/problems/231.yml +16 -0
- data/data/problems/232.yml +14 -0
- data/data/problems/233.yml +10 -0
- data/data/problems/234.yml +23 -0
- data/data/problems/235.yml +9 -0
- data/data/problems/236.yml +32 -0
- data/data/problems/237.yml +13 -0
- data/data/problems/238.yml +42 -0
- data/data/problems/239.yml +9 -0
- data/data/problems/24.yml +10 -0
- data/data/problems/240.yml +11 -0
- data/data/problems/241.yml +17 -0
- data/data/problems/242.yml +16 -0
- data/data/problems/243.yml +19 -0
- data/data/problems/244.yml +32 -0
- data/data/problems/245.yml +36 -0
- data/data/problems/246.yml +17 -0
- data/data/problems/247.yml +21 -0
- data/data/problems/248.yml +6 -0
- data/data/problems/249.yml +7 -0
- data/data/problems/25.yml +15 -0
- data/data/problems/250.yml +7 -0
- data/data/problems/251.yml +13 -0
- data/data/problems/252.yml +31 -0
- data/data/problems/253.yml +36 -0
- data/data/problems/254.yml +21 -0
- data/data/problems/255.yml +59 -0
- data/data/problems/256.yml +43 -0
- data/data/problems/257.yml +18 -0
- data/data/problems/258.yml +13 -0
- data/data/problems/259.yml +16 -0
- data/data/problems/26.yml +11 -0
- data/data/problems/260.yml +30 -0
- data/data/problems/261.yml +19 -0
- data/data/problems/262.yml +20 -0
- data/data/problems/263.yml +19 -0
- data/data/problems/264.yml +20 -0
- data/data/problems/265.yml +16 -0
- data/data/problems/266.yml +10 -0
- data/data/problems/267.yml +14 -0
- data/data/problems/268.yml +8 -0
- data/data/problems/269.yml +15 -0
- data/data/problems/27.yml +25 -0
- data/data/problems/270.yml +17 -0
- data/data/problems/271.yml +13 -0
- data/data/problems/272.yml +15 -0
- data/data/problems/273.yml +21 -0
- data/data/problems/274.yml +23 -0
- data/data/problems/275.yml +19 -0
- data/data/problems/276.yml +11 -0
- data/data/problems/277.yml +24 -0
- data/data/problems/278.yml +32 -0
- data/data/problems/279.yml +6 -0
- data/data/problems/28.yml +17 -0
- data/data/problems/280.yml +13 -0
- data/data/problems/281.yml +17 -0
- data/data/problems/282.yml +10 -0
- data/data/problems/283.yml +11 -0
- data/data/problems/284.yml +22 -0
- data/data/problems/285.yml +17 -0
- data/data/problems/286.yml +12 -0
- data/data/problems/287.yml +36 -0
- data/data/problems/288.yml +15 -0
- data/data/problems/289.yml +19 -0
- data/data/problems/29.yml +24 -0
- data/data/problems/290.yml +8 -0
- data/data/problems/291.yml +10 -0
- data/data/problems/292.yml +13 -0
- data/data/problems/293.yml +15 -0
- data/data/problems/294.yml +10 -0
- data/data/problems/295.yml +26 -0
- data/data/problems/296.yml +15 -0
- data/data/problems/297.yml +19 -0
- data/data/problems/298.yml +46 -0
- data/data/problems/299.yml +31 -0
- data/data/problems/3.yml +7 -0
- data/data/problems/30.yml +12 -0
- data/data/problems/300.yml +24 -0
- data/data/problems/301.yml +25 -0
- data/data/problems/302.yml +18 -0
- data/data/problems/303.yml +11 -0
- data/data/problems/304.yml +19 -0
- data/data/problems/305.yml +14 -0
- data/data/problems/306.yml +29 -0
- data/data/problems/307.yml +12 -0
- data/data/problems/308.yml +34 -0
- data/data/problems/309.yml +17 -0
- data/data/problems/31.yml +18 -0
- data/data/problems/310.yml +19 -0
- data/data/problems/311.yml +21 -0
- data/data/problems/312.yml +15 -0
- data/data/problems/313.yml +17 -0
- data/data/problems/314.yml +29 -0
- data/data/problems/315.yml +49 -0
- data/data/problems/316.yml +25 -0
- data/data/problems/317.yml +11 -0
- data/data/problems/318.yml +61 -0
- data/data/problems/319.yml +23 -0
- data/data/problems/32.yml +14 -0
- data/data/problems/320.yml +12 -0
- data/data/problems/321.yml +18 -0
- data/data/problems/322.yml +12 -0
- data/data/problems/323.yml +19 -0
- data/data/problems/324.yml +17 -0
- data/data/problems/325.yml +25 -0
- data/data/problems/326.yml +12 -0
- data/data/problems/327.yml +39 -0
- data/data/problems/328.yml +36 -0
- data/data/problems/329.yml +17 -0
- data/data/problems/33.yml +13 -0
- data/data/problems/330.yml +40 -0
- data/data/problems/331.yml +28 -0
- data/data/problems/332.yml +16 -0
- data/data/problems/333.yml +25 -0
- data/data/problems/334.yml +39 -0
- data/data/problems/335.yml +16 -0
- data/data/problems/336.yml +24 -0
- data/data/problems/337.yml +15 -0
- data/data/problems/338.yml +41 -0
- data/data/problems/339.yml +17 -0
- data/data/problems/34.yml +7 -0
- data/data/problems/340.yml +14 -0
- data/data/problems/341.yml +18 -0
- data/data/problems/342.yml +17 -0
- data/data/problems/343.yml +29 -0
- data/data/problems/344.yml +21 -0
- data/data/problems/345.yml +26 -0
- data/data/problems/346.yml +11 -0
- data/data/problems/347.yml +16 -0
- data/data/problems/348.yml +12 -0
- data/data/problems/349.yml +13 -0
- data/data/problems/35.yml +8 -0
- data/data/problems/350.yml +18 -0
- data/data/problems/351.yml +13 -0
- data/data/problems/352.yml +49 -0
- data/data/problems/353.yml +25 -0
- data/data/problems/354.yml +16 -0
- data/data/problems/355.yml +8 -0
- data/data/problems/356.yml +10 -0
- data/data/problems/357.yml +9 -0
- data/data/problems/358.yml +31 -0
- data/data/problems/359.yml +26 -0
- data/data/problems/36.yml +8 -0
- data/data/problems/360.yml +12 -0
- data/data/problems/361.yml +20 -0
- data/data/problems/362.yml +32 -0
- data/data/problems/363.yml +33 -0
- data/data/problems/364.yml +15 -0
- data/data/problems/365.yml +17 -0
- data/data/problems/366.yml +26 -0
- data/data/problems/367.yml +20 -0
- data/data/problems/368.yml +39 -0
- data/data/problems/369.yml +15 -0
- data/data/problems/37.yml +10 -0
- data/data/problems/370.yml +16 -0
- data/data/problems/371.yml +13 -0
- data/data/problems/372.yml +16 -0
- data/data/problems/373.yml +10 -0
- data/data/problems/374.yml +25 -0
- data/data/problems/375.yml +23 -0
- data/data/problems/376.yml +25 -0
- data/data/problems/377.yml +11 -0
- data/data/problems/378.yml +15 -0
- data/data/problems/379.yml +15 -0
- data/data/problems/38.yml +18 -0
- data/data/problems/380.yml +22 -0
- data/data/problems/381.yml +21 -0
- data/data/problems/382.yml +23 -0
- data/data/problems/383.yml +13 -0
- data/data/problems/384.yml +28 -0
- data/data/problems/385.yml +22 -0
- data/data/problems/386.yml +16 -0
- data/data/problems/387.yml +19 -0
- data/data/problems/388.yml +12 -0
- data/data/problems/389.yml +12 -0
- data/data/problems/39.yml +10 -0
- data/data/problems/390.yml +18 -0
- data/data/problems/391.yml +29 -0
- data/data/problems/392.yml +22 -0
- data/data/problems/393.yml +12 -0
- data/data/problems/394.yml +22 -0
- data/data/problems/395.yml +19 -0
- data/data/problems/396.yml +28 -0
- data/data/problems/397.yml +20 -0
- data/data/problems/398.yml +13 -0
- data/data/problems/399.yml +22 -0
- data/data/problems/4.yml +8 -0
- data/data/problems/40.yml +18 -0
- data/data/problems/400.yml +18 -0
- data/data/problems/401.yml +11 -0
- data/data/problems/402.yml +25 -0
- data/data/problems/403.yml +19 -0
- data/data/problems/404.yml +21 -0
- data/data/problems/405.yml +15 -0
- data/data/problems/406.yml +46 -0
- data/data/problems/407.yml +20 -0
- data/data/problems/408.yml +14 -0
- data/data/problems/409.yml +12 -0
- data/data/problems/41.yml +8 -0
- data/data/problems/410.yml +19 -0
- data/data/problems/411.yml +23 -0
- data/data/problems/412.yml +19 -0
- data/data/problems/413.yml +13 -0
- data/data/problems/414.yml +40 -0
- data/data/problems/415.yml +19 -0
- data/data/problems/416.yml +13 -0
- data/data/problems/417.yml +21 -0
- data/data/problems/418.yml +17 -0
- data/data/problems/419.yml +22 -0
- data/data/problems/42.yml +14 -0
- data/data/problems/420.yml +13 -0
- data/data/problems/421.yml +29 -0
- data/data/problems/422.yml +22 -0
- data/data/problems/423.yml +22 -0
- data/data/problems/424.yml +37 -0
- data/data/problems/425.yml +16 -0
- data/data/problems/426.yml +29 -0
- data/data/problems/427.yml +18 -0
- data/data/problems/428.yml +32 -0
- data/data/problems/429.yml +10 -0
- data/data/problems/43.yml +17 -0
- data/data/problems/430.yml +20 -0
- data/data/problems/431.yml +33 -0
- data/data/problems/432.yml +13 -0
- data/data/problems/433.yml +18 -0
- data/data/problems/434.yml +32 -0
- data/data/problems/435.yml +21 -0
- data/data/problems/436.yml +21 -0
- data/data/problems/437.yml +22 -0
- data/data/problems/438.yml +29 -0
- data/data/problems/439.yml +17 -0
- data/data/problems/44.yml +16 -0
- data/data/problems/440.yml +21 -0
- data/data/problems/441.yml +23 -0
- data/data/problems/442.yml +9 -0
- data/data/problems/443.yml +13 -0
- data/data/problems/444.yml +28 -0
- data/data/problems/445.yml +37 -0
- data/data/problems/446.yml +29 -0
- data/data/problems/447.yml +31 -0
- data/data/problems/448.yml +14 -0
- data/data/problems/449.yml +17 -0
- data/data/problems/45.yml +15 -0
- data/data/problems/450.yml +26 -0
- data/data/problems/451.yml +15 -0
- data/data/problems/452.yml +8 -0
- data/data/problems/453.yml +16 -0
- data/data/problems/454.yml +17 -0
- data/data/problems/455.yml +16 -0
- data/data/problems/456.yml +15 -0
- data/data/problems/46.yml +18 -0
- data/data/problems/47.yml +21 -0
- data/data/problems/48.yml +7 -0
- data/data/problems/49.yml +10 -0
- data/data/problems/5.yml +8 -0
- data/data/problems/50.yml +10 -0
- data/data/problems/51.yml +15 -0
- data/data/problems/52.yml +8 -0
- data/data/problems/53.yml +28 -0
- data/data/problems/54.yml +43 -0
- data/data/problems/55.yml +21 -0
- data/data/problems/56.yml +11 -0
- data/data/problems/57.yml +15 -0
- data/data/problems/58.yml +22 -0
- data/data/problems/59.yml +23 -0
- data/data/problems/6.yml +13 -0
- data/data/problems/60.yml +10 -0
- data/data/problems/61.yml +30 -0
- data/data/problems/62.yml +9 -0
- data/data/problems/63.yml +7 -0
- data/data/problems/64.yml +130 -0
- data/data/problems/65.yml +62 -0
- data/data/problems/66.yml +27 -0
- data/data/problems/67.yml +17 -0
- data/data/problems/68.yml +23 -0
- data/data/problems/69.yml +14 -0
- data/data/problems/7.yml +6 -0
- data/data/problems/70.yml +16 -0
- data/data/problems/71.yml +17 -0
- data/data/problems/72.yml +16 -0
- data/data/problems/73.yml +16 -0
- data/data/problems/74.yml +41 -0
- data/data/problems/75.yml +16 -0
- data/data/problems/76.yml +8 -0
- data/data/problems/77.yml +8 -0
- data/data/problems/78.yml +12 -0
- data/data/problems/79.yml +11 -0
- data/data/problems/8.yml +6 -0
- data/data/problems/80.yml +11 -0
- data/data/problems/81.yml +19 -0
- data/data/problems/82.yml +19 -0
- data/data/problems/83.yml +23 -0
- data/data/problems/84.yml +63 -0
- data/data/problems/85.yml +9 -0
- data/data/problems/86.yml +15 -0
- data/data/problems/87.yml +12 -0
- data/data/problems/88.yml +53 -0
- data/data/problems/89.yml +18 -0
- data/data/problems/9.yml +13 -0
- data/data/problems/90.yml +23 -0
- data/data/problems/91.yml +19 -0
- data/data/problems/92.yml +29 -0
- data/data/problems/93.yml +21 -0
- data/data/problems/94.yml +11 -0
- data/data/problems/95.yml +23 -0
- data/data/problems/96.yml +46 -0
- data/data/problems/97.yml +14 -0
- data/data/problems/98.yml +16 -0
- data/data/problems/99.yml +16 -0
- data/euler-manager.gemspec +31 -0
- data/euler-manager.sublime-project +12 -0
- data/example/1/README.md +6 -0
- data/example/1/ruby/1.rb +5 -0
- data/example/1/scala/1.scala +9 -0
- data/example/2/README.md +9 -0
- data/example/2/python/2.py +5 -0
- data/example/2/python/euler.py +0 -0
- data/example/Eulerfile.rb +87 -0
- data/example/README.md +26 -0
- data/example/lib/euler.py +0 -0
- data/example/lib/euler.rb +0 -0
- data/example/lib/euler.scala +5 -0
- data/lib/euler.rb +190 -0
- data/lib/euler/errors.rb +7 -0
- data/lib/euler/languages.rb +12 -0
- data/lib/euler/languages/coffeescript.rb +25 -0
- data/lib/euler/languages/javascript.rb +25 -0
- data/lib/euler/languages/python.rb +27 -0
- data/lib/euler/languages/ruby.rb +25 -0
- data/lib/euler/languages/scala.rb +27 -0
- data/lib/euler/languages/templates/coffeescript.coffee +5 -0
- data/lib/euler/languages/templates/javascript.js +5 -0
- data/lib/euler/languages/templates/python.py +5 -0
- data/lib/euler/languages/templates/ruby.rb +5 -0
- data/lib/euler/languages/templates/scala.scala +9 -0
- data/lib/euler/problem.rb +60 -0
- data/lib/euler/solution.rb +98 -0
- data/lib/euler/version.rb +3 -0
- data/scripts/update_problems +68 -0
- data/spec/euler/problem_spec.rb +5 -0
- data/spec/euler/solution_spec.rb +69 -0
- data/spec/euler_spec.rb +27 -0
- data/spec/spec_helper.rb +3 -0
- metadata +644 -0
File without changes
|
@@ -0,0 +1,87 @@
|
|
1
|
+
# The Eulerfile.rb has user specific configuration.
|
2
|
+
#
|
3
|
+
# The location of the answers file and problems directory are both configurable.
|
4
|
+
# Additionally the strategy used to assign solutions directories, to create
|
5
|
+
# those directories, and to parse the directory the the +euler+ command is being
|
6
|
+
# ran from are all also configurable. See below for an example configuration.
|
7
|
+
|
8
|
+
Euler.config do |config|
|
9
|
+
|
10
|
+
data_dir = "#{File.dirname(__FILE__)}/../data"
|
11
|
+
|
12
|
+
config.answers_file "#{data_dir}/answers.yml"
|
13
|
+
config.problems_dir "#{data_dir}/problems"
|
14
|
+
|
15
|
+
# The +directory_strategy+ is a Proc which returns the directory assigned to a
|
16
|
+
# a given solution.
|
17
|
+
config.directory_strategy lambda { |solution|
|
18
|
+
"#{Euler.root}/#{solution.problem_id}/#{solution.language}"
|
19
|
+
}
|
20
|
+
|
21
|
+
# The +create_directory_strategy+ is a Proc which is ran to create directories
|
22
|
+
# for solutions and anything else that is required to initialize a solution.
|
23
|
+
# By default a +README.md+ file is created at the root of the problem with the
|
24
|
+
# problem's name and description.
|
25
|
+
config.create_directory_strategy lambda { |solution|
|
26
|
+
problem = solution.problem
|
27
|
+
dir = solution.dir
|
28
|
+
|
29
|
+
FileUtils.mkdir_p(dir)
|
30
|
+
readme_path = "#{dir}/../README.md"
|
31
|
+
if not File.exists?(readme_path) then File.open(readme_path, 'w') do |f|
|
32
|
+
f.write("# [#{problem.name}](#{problem.url})\n\n#{problem.content}")
|
33
|
+
end end
|
34
|
+
}
|
35
|
+
|
36
|
+
# Attempts to parse a directory for the +problem_id+ and +language+. Returns
|
37
|
+
# a an array where the first element is the problem id and the second element
|
38
|
+
# is the language.
|
39
|
+
config.directory_parse_strategy lambda { |dir|
|
40
|
+
problem_id = (Regexp.new("#{Euler.root}/(\\d+)").match(dir) || [])[1]
|
41
|
+
language = (Regexp.new("#{Euler.root}/\\d+/(.+)").match(dir) || [])[1]
|
42
|
+
|
43
|
+
[problem_id, language]
|
44
|
+
}
|
45
|
+
|
46
|
+
# Returns every solution done so far.
|
47
|
+
config.all_solutions_strategy lambda {
|
48
|
+
Dir["#{Euler.root}/*"].select { |f|
|
49
|
+
File.directory?(f) and /\/\d+$/ === f
|
50
|
+
}.map { |problem_dir|
|
51
|
+
Dir["#{problem_dir}/*"].map { |solution_dir|
|
52
|
+
if File.directory?(solution_dir)
|
53
|
+
args = Euler.parse_params_from_directory(solution_dir)
|
54
|
+
Euler::Solution.new(*args)
|
55
|
+
else
|
56
|
+
nil
|
57
|
+
end
|
58
|
+
}
|
59
|
+
}.flatten.compact
|
60
|
+
}
|
61
|
+
|
62
|
+
end
|
63
|
+
|
64
|
+
# It can also register or language classes which are used to initialize and run
|
65
|
+
# problems.
|
66
|
+
|
67
|
+
Euler.register_language('python', Class.new do
|
68
|
+
|
69
|
+
# The run method must return the result of running the solution.
|
70
|
+
def run solution
|
71
|
+
`python #{solution.dir}/#{solution.problem_id}.py`
|
72
|
+
end
|
73
|
+
|
74
|
+
# The init method is used to do any extra initialization for a solution. This
|
75
|
+
# method is not required
|
76
|
+
#
|
77
|
+
# This example symlinks lib/euler.py into the solution's directory and then
|
78
|
+
# writes a base file into the directory.
|
79
|
+
def init solution
|
80
|
+
FileUtils.symlink("#{Euler.root}/lib/euler.py", "#{solution.dir}/euler.py")
|
81
|
+
|
82
|
+
File.open("#{solution.dir}/#{solution.problem_id}.py", 'w') do |f|
|
83
|
+
f.write("import euler\n\nanswer = 0\n\nprint(answer)\n")
|
84
|
+
end
|
85
|
+
end
|
86
|
+
|
87
|
+
end)
|
data/example/README.md
ADDED
@@ -0,0 +1,26 @@
|
|
1
|
+
# Euler Manager Example
|
2
|
+
|
3
|
+
## Eulerfile
|
4
|
+
|
5
|
+
The root of your project Euler solutions needs to have an `Eulerfile.rb`.
|
6
|
+
|
7
|
+
In this file you can configure the locations of Euler manager's data, the
|
8
|
+
strategies it uses to manage and parse directories and register languages.
|
9
|
+
|
10
|
+
Euler manager uses some pretty sensible defaults and comes with a number of
|
11
|
+
languages already configured. Its likely you will be able to get by with having
|
12
|
+
your `Eulerfile.rb` be blank.
|
13
|
+
|
14
|
+
## Directory Structure
|
15
|
+
|
16
|
+
By default Euler manager creates solution directories with the top directory
|
17
|
+
being the ID of the problem and the child directory being the language of the
|
18
|
+
solution.
|
19
|
+
|
20
|
+
Also by default Euler manger creates a `README.md` file in the problem directory
|
21
|
+
with the problem's name and description.
|
22
|
+
|
23
|
+
### /lib
|
24
|
+
|
25
|
+
Its recommended to have a `lib` directory where you can store common functions
|
26
|
+
in the languages you're solving problems in.
|
File without changes
|
File without changes
|
data/lib/euler.rb
ADDED
@@ -0,0 +1,190 @@
|
|
1
|
+
require 'fileutils'
|
2
|
+
require 'ostruct'
|
3
|
+
|
4
|
+
require_relative 'euler/version'
|
5
|
+
|
6
|
+
require_relative 'euler/errors'
|
7
|
+
require_relative 'euler/problem'
|
8
|
+
require_relative 'euler/solution'
|
9
|
+
|
10
|
+
module Euler
|
11
|
+
|
12
|
+
# This class holds the Euler module's configuration.
|
13
|
+
|
14
|
+
class ConfigOptions
|
15
|
+
|
16
|
+
# Initialize an empty OpenStruct to hold configuration options
|
17
|
+
def initialize
|
18
|
+
@config = OpenStruct.new
|
19
|
+
end
|
20
|
+
|
21
|
+
# To set a config option call the corresponding method with an argument.
|
22
|
+
# To retrieve a config option call the corresponding method without an argument.
|
23
|
+
def method_missing method, *args, &block
|
24
|
+
if args.empty?
|
25
|
+
@config.send(method)
|
26
|
+
else
|
27
|
+
@config.send("#{method}=", args.first)
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
end
|
32
|
+
|
33
|
+
class << self
|
34
|
+
|
35
|
+
@@config_options = Euler::ConfigOptions.new
|
36
|
+
@@languages = Hash.new
|
37
|
+
|
38
|
+
# Yields config_options to a block. Used to configure the Euler module.
|
39
|
+
def config
|
40
|
+
yield @@config_options
|
41
|
+
end
|
42
|
+
|
43
|
+
# Register a language by calling this method with the languages name and the
|
44
|
+
# class for that language. To unregister a language call this method
|
45
|
+
# without a second argument.
|
46
|
+
#
|
47
|
+
# Language classes require a +run+ method which accepts an +Euler::Solution+
|
48
|
+
# and returns the result of running the solution. Optionally language
|
49
|
+
# classes can also have an +init+ method which also accepts a solution. The
|
50
|
+
# +init+ method does any extra steps required in initializing an empty
|
51
|
+
# solution.
|
52
|
+
def register_language language_name, language = nil
|
53
|
+
language_string = language_name.to_s
|
54
|
+
@@languages[language_string.to_s] = language
|
55
|
+
end
|
56
|
+
|
57
|
+
# Unregisters a language
|
58
|
+
def unregister_language language_name
|
59
|
+
register_language(language_name)
|
60
|
+
end
|
61
|
+
|
62
|
+
# Returns an instance of a registered language class.
|
63
|
+
#
|
64
|
+
# @throws Euler::LanguageNotRegisteredError if the language asked for has
|
65
|
+
# not already been registered.
|
66
|
+
def get_language language_name
|
67
|
+
language_string = language_name.to_s
|
68
|
+
if @@languages[language_string].nil?
|
69
|
+
raise Euler::LanguageNotRegisteredError.new "#{language_string} has not been registered."
|
70
|
+
else
|
71
|
+
@@languages[language_string].new
|
72
|
+
end
|
73
|
+
end
|
74
|
+
|
75
|
+
# Returns configuration options. If the configuration option is a +Proc+
|
76
|
+
# then this method will call it with the arguments passed to this method and
|
77
|
+
# return the result.
|
78
|
+
def method_missing method, *args, &block
|
79
|
+
temp = @@config_options.send method
|
80
|
+
if temp.is_a?(Proc)
|
81
|
+
temp.call *args
|
82
|
+
else
|
83
|
+
temp
|
84
|
+
end
|
85
|
+
end
|
86
|
+
|
87
|
+
# Returns the root directory of the current project.
|
88
|
+
def root
|
89
|
+
if @root.nil?
|
90
|
+
root = ENV['PWD']
|
91
|
+
until File.exists?("#{root}/Eulerfile.rb") || File.expand_path(root) == '/' do
|
92
|
+
root = File.dirname(root)
|
93
|
+
end
|
94
|
+
if not File.exists?("#{root}/Eulerfile.rb")
|
95
|
+
raise Euler::EulerFileNotFoundError.new "Unable to find an Eulerfile.rb in any of the parent directories."
|
96
|
+
end
|
97
|
+
@root = root
|
98
|
+
end
|
99
|
+
@root
|
100
|
+
end
|
101
|
+
|
102
|
+
def euler_file_path
|
103
|
+
"#{root}/Eulerfile.rb"
|
104
|
+
end
|
105
|
+
|
106
|
+
# Returns an array with the first element being the problem id and the
|
107
|
+
# second element being the language gotten from either the args passed in or
|
108
|
+
# by parsing the directory the command was ran from
|
109
|
+
def params_from_dir_or_args args
|
110
|
+
from_dir = parse_params_from_directory
|
111
|
+
[
|
112
|
+
args.shift || from_dir.shift,
|
113
|
+
args.shift || from_dir.shift
|
114
|
+
]
|
115
|
+
end
|
116
|
+
|
117
|
+
# Uses the +directory_parse_strategy+ to attempt to parse the problem id and
|
118
|
+
# language of the solution's directory the command was ran from.
|
119
|
+
def parse_params_from_directory dir = ENV['PWD']
|
120
|
+
self.directory_parse_strategy(dir)
|
121
|
+
end
|
122
|
+
|
123
|
+
end
|
124
|
+
|
125
|
+
end
|
126
|
+
|
127
|
+
# Initialize the Euler module's configuration to the default values.
|
128
|
+
Euler.config do |config|
|
129
|
+
|
130
|
+
data_dir = "#{File.dirname(__FILE__)}/../data"
|
131
|
+
|
132
|
+
config.answers_file "#{data_dir}/answers.yml"
|
133
|
+
config.problems_dir "#{data_dir}/problems"
|
134
|
+
|
135
|
+
# The +directory_strategy+ is a Proc which returns the directory assigned to a
|
136
|
+
# a given solution.
|
137
|
+
config.directory_strategy lambda { |solution|
|
138
|
+
"#{Euler.root}/#{solution.problem_id}/#{solution.language}"
|
139
|
+
}
|
140
|
+
|
141
|
+
# The +create_directory_strategy+ is a Proc which is ran to create directories
|
142
|
+
# for solutions and anything else that is required to initialize a solution.
|
143
|
+
# By default a +README.md+ file is created at the root of the problem with the
|
144
|
+
# problem's name and description.
|
145
|
+
config.create_directory_strategy lambda { |solution|
|
146
|
+
problem = solution.problem
|
147
|
+
dir = solution.dir
|
148
|
+
|
149
|
+
FileUtils.mkdir_p(dir)
|
150
|
+
readme_path = "#{dir}/../README.md"
|
151
|
+
if not File.exists?(readme_path) then File.open(readme_path, 'w') do |f|
|
152
|
+
f.write("# [#{problem.name}](#{problem.url})\n\n#{problem.content}")
|
153
|
+
end end
|
154
|
+
}
|
155
|
+
|
156
|
+
# Attempts to parse a directory for the +problem_id+ and +language+. Returns
|
157
|
+
# a an array where the first element is the problem id and the second element
|
158
|
+
# is the language.
|
159
|
+
config.directory_parse_strategy lambda { |dir|
|
160
|
+
problem_id = (Regexp.new("#{Euler.root}/(\\d+)").match(dir) || [])[1]
|
161
|
+
language = (Regexp.new("#{Euler.root}/\\d+/(.+)").match(dir) || [])[1]
|
162
|
+
|
163
|
+
[problem_id, language]
|
164
|
+
}
|
165
|
+
|
166
|
+
# Returns every solution done so far.
|
167
|
+
config.all_solutions_strategy lambda {
|
168
|
+
Dir["#{Euler.root}/*"].select { |f|
|
169
|
+
File.directory?(f) and /\/\d+$/ === f
|
170
|
+
}.map { |problem_dir|
|
171
|
+
Dir["#{problem_dir}/*"].map { |solution_dir|
|
172
|
+
if File.directory?(solution_dir)
|
173
|
+
args = Euler.parse_params_from_directory(solution_dir)
|
174
|
+
Euler::Solution.new(*args)
|
175
|
+
else
|
176
|
+
nil
|
177
|
+
end
|
178
|
+
}
|
179
|
+
}.flatten.compact
|
180
|
+
}
|
181
|
+
|
182
|
+
end
|
183
|
+
|
184
|
+
# Include the default language definitions.
|
185
|
+
require_relative 'euler/languages'
|
186
|
+
|
187
|
+
# Attempt to load user defined configuration
|
188
|
+
begin
|
189
|
+
require Euler.euler_file_path
|
190
|
+
rescue; end
|
data/lib/euler/errors.rb
ADDED
@@ -0,0 +1,25 @@
|
|
1
|
+
Euler.register_language('coffeescript', Class.new do
|
2
|
+
|
3
|
+
# Run the solution
|
4
|
+
def run solution
|
5
|
+
`coffee #{file_path(solution)}`
|
6
|
+
end
|
7
|
+
|
8
|
+
# Copy the template into the solution's directory
|
9
|
+
def init solution
|
10
|
+
FileUtils.cp(template_path, file_path(solution))
|
11
|
+
end
|
12
|
+
|
13
|
+
private
|
14
|
+
|
15
|
+
# Returns the path to the solution
|
16
|
+
def file_path solution
|
17
|
+
"#{solution.dir}/#{solution.problem.id}.coffee"
|
18
|
+
end
|
19
|
+
|
20
|
+
# Returns the path to the template
|
21
|
+
def template_path
|
22
|
+
"#{File.dirname(__FILE__)}/templates/coffeescript.coffee"
|
23
|
+
end
|
24
|
+
|
25
|
+
end)
|
@@ -0,0 +1,25 @@
|
|
1
|
+
Euler.register_language('javascript', Class.new do
|
2
|
+
|
3
|
+
# Run the solution
|
4
|
+
def run solution
|
5
|
+
`node #{file_path(solution)}`
|
6
|
+
end
|
7
|
+
|
8
|
+
# Copy the template into the solution's directory
|
9
|
+
def init solution
|
10
|
+
FileUtils.cp(template_path, file_path(solution))
|
11
|
+
end
|
12
|
+
|
13
|
+
private
|
14
|
+
|
15
|
+
# Returns the path to the solution
|
16
|
+
def file_path solution
|
17
|
+
"#{solution.dir}/#{solution.problem.id}.js"
|
18
|
+
end
|
19
|
+
|
20
|
+
# Returns the path to the template
|
21
|
+
def template_path
|
22
|
+
"#{File.dirname(__FILE__)}/templates/javascript.js"
|
23
|
+
end
|
24
|
+
|
25
|
+
end)
|
@@ -0,0 +1,27 @@
|
|
1
|
+
Euler.register_language('python', Class.new do
|
2
|
+
|
3
|
+
# Run the solution
|
4
|
+
def run solution
|
5
|
+
`python #{file_path(solution)}`
|
6
|
+
end
|
7
|
+
|
8
|
+
# Copy the template into the solution's directory
|
9
|
+
def init solution
|
10
|
+
FileUtils.symlink("#{Euler.root}/lib/euler.py", "#{solution.dir}/euler.py")
|
11
|
+
|
12
|
+
FileUtils.cp(template_path, file_path(solution))
|
13
|
+
end
|
14
|
+
|
15
|
+
private
|
16
|
+
|
17
|
+
# Returns the path to the solution
|
18
|
+
def file_path solution
|
19
|
+
"#{solution.dir}/#{solution.problem.id}.py"
|
20
|
+
end
|
21
|
+
|
22
|
+
# Returns the path to the template
|
23
|
+
def template_path
|
24
|
+
"#{File.dirname(__FILE__)}/templates/python.py"
|
25
|
+
end
|
26
|
+
|
27
|
+
end)
|
@@ -0,0 +1,25 @@
|
|
1
|
+
Euler.register_language('ruby', Class.new do
|
2
|
+
|
3
|
+
# Run the ruby solution
|
4
|
+
def run solution
|
5
|
+
`ruby #{file_path(solution)}`
|
6
|
+
end
|
7
|
+
|
8
|
+
# Copy the template into the solution's directory
|
9
|
+
def init solution
|
10
|
+
FileUtils.cp(template_path, file_path(solution))
|
11
|
+
end
|
12
|
+
|
13
|
+
private
|
14
|
+
|
15
|
+
# Returns the path to the solution
|
16
|
+
def file_path solution
|
17
|
+
"#{solution.dir}/#{solution.problem.id}.rb"
|
18
|
+
end
|
19
|
+
|
20
|
+
# Returns the path to the ruby template
|
21
|
+
def template_path
|
22
|
+
"#{File.dirname(__FILE__)}/templates/ruby.rb"
|
23
|
+
end
|
24
|
+
|
25
|
+
end)
|