Permalink
Browse files

python solution for 287

  • Loading branch information...
1 parent 9bf3299 commit 8bbe3c645dab54ad52af44371c79c168871b4e3a igorekbsu committed Apr 2, 2012
Showing with 44 additions and 27 deletions.
  1. +17 −0 250_299/src/task287/s287.py
  2. +27 −27 50_99/src/task89/Main89.java
@@ -0,0 +1,17 @@
+n = 2
+k = 2**(n - 1)
+
+def color(x,y):
+ return (x - k)**2 + (y - k)**2 <= k*k
+
+def f(x0, y0, x1, y1):
+ c0 = color(x0, y0)
+ if all( (color(x,y) == c0) for x,y in ((x0, y1 - 1), (x1 - 1, y0), (x1 - 1, y1 - 1)) ):return 2
+
+ xmid = (x0 + x1) // 2
+ ymid = (y0 + y1) // 2
+
+ return 1 + f(x0, y0, xmid, ymid) + f(x0, ymid, xmid, y1) + f(xmid, y0, x1, ymid) + f(xmid, ymid, x1, y1)
+
+print(1 + f(0, 0, k, k) + f(0, k, k, 2*k) + f(k, 0, 2*k, k) + f(k, k, 2*k, 2*k))
+
@@ -1,27 +1,27 @@
-package task89;
-
-import common.Watch;
-
-import java.io.IOException;
-import java.util.List;
-
-import static task89.Roman.toInteger;
-import static task89.Roman.toRoman;
-
-/**
- * @author Igor
- */
-public class Main89 {
- public static void main(String[] args) throws IOException {
- List<String> lines = common.Utils.readFile("../50_99/src/task89/roman.txt");
- int savings = 0;
- Watch.start();
- for (String line : lines) {
- int number = toInteger(line);
- String minimalForm = toRoman(number);
- savings += line.length() - minimalForm.length();
- }
- System.out.println(savings);
- Watch.stop();
- }
-}
+package task89;
+
+import common.Watch;
+
+import java.io.IOException;
+import java.util.List;
+
+import static task89.Roman.toInteger;
+import static task89.Roman.toRoman;
+
+/**
+ * @author Igor
+ */
+public class Main89 {
+ public static void main(String[] args) throws IOException {
+ List<String> lines = common.Utils.readFile("50_99/src/task89/roman.txt");
+ int savings = 0;
+ Watch.start();
+ for (String line : lines) {
+ int number = toInteger(line);
+ String minimalForm = toRoman(number);
+ savings += line.length() - minimalForm.length();
+ }
+ System.out.println(savings);
+ Watch.stop();
+ }
+}

0 comments on commit 8bbe3c6

Please sign in to comment.