16 کامیت‌ها bf17ded31a ... e038894cb7

نویسنده SHA1 پیام تاریخ
  estelendur e038894cb7 Merge branch 'master' of notabug.org:estelendur/noodling 9 سال پیش
  esty 05db6909d7 Added some meat to matryoprimes 9 سال پیش
  esty aa62d075c3 Russian doll primes 9 سال پیش
  esty 12fa123de6 deleted swap file because inattentive 10 سال پیش
  estelendur b4459036d4 output screenshot added 10 سال پیش
  esty 8197f5c1be Merge branch 'master' of gitorious.org:estelendur/hw-from-ben 10 سال پیش
  esty 6ab410bf46 Python palindromes 10 سال پیش
  estelendur a61999f1f0 Futzing around 10 سال پیش
  esty 540362d52e Merge branch 'master' of gitorious.org:estelendur/hw-from-ben 10 سال پیش
  esty 9860f1f712 Added commenting advices 10 سال پیش
  estelendur c495719e2e First version of palindromes.hs 10 سال پیش
  esty 94f48cab7c Added port-learnings with directions and hint 10 سال پیش
  esty b95bfdafbb Fixed syntax issues 10 سال پیش
  esty e9b8f61545 Modified m-v-a.py's header commentsbecause vim folds 10 سال پیش
  esty f16ea29959 Created max-val-algos.py, wrote methodical and stepvary 10 سال پیش
  esty 181c33138a Made file, added Methodical algorithm 10 سال پیش
10فایلهای تغییر یافته به همراه151 افزوده شده و 0 حذف شده
  1. 3 0
      commenting.txt
  2. 22 0
      matryoprimes.py
  3. 23 0
      max-val-algos.md
  4. 42 0
      max_val_algos.py
  5. BIN
      max_val_algos.pyc
  6. 24 0
      palindromes.hs
  7. 37 0
      palindromes.py
  8. BIN
      palindromes.pyc
  9. BIN
      palout1.png
  10. 0 0
      port-learnings.md

+ 3 - 0
commenting.txt

@@ -0,0 +1,3 @@
+basics of this: explain high level goal of each logically seperate chunk of code or algorithm. Explain any confusing syntax. Explain use of unusual libraries. Try to list any assumptions that might be incorrect.
+if a variable or function's purpose isn't self explanitory, note what it is for in a comment.
+At the start of any (substantial) program, note what it is for and how to make it run. Also who wrote it, license, etc.

+ 22 - 0
matryoprimes.py

@@ -0,0 +1,22 @@
+# Find all the Russian Doll primes for a given base
+# Author: estelendur
+
+def isPrime(x):
+    # insert primality test here
+
+def encase(primes):
+    new = []
+    app = [1, 3, 7, 9]
+    for p in primes:
+        for a in app: 
+            i = p*10+a
+            if isPrime(i):
+                new.append(i)
+    if len(new) > 0:
+        return primes + encase(new)
+    else:
+        return 
+
+def dollPrimes():
+    oned = [2, 3, 5, 7]
+    return encase(oned)   

+ 23 - 0
max-val-algos.md

@@ -0,0 +1,23 @@
+<!--
+### Author: estelendur
+# Find the maximum value k of a function f(Xi) within a range [a,b]
+# Noodling around with psuedocode algorithms
+-->
+
+##The problem
+
+Find the maximum value of some function within a range. For the purposes of this problem, the function is f(X) where X = [x1, x2, ..., xn], its output is k, and each xi is in a range [ai, bi].
+
+###Methodical algorithm
+
+```
+for all xi:
+	set xi to rand(ai, bi)
+
+for i in (i,n):
+	vary xi in [ai, bi]:
+		if f(X) > currmax:
+			currmax = f(X)
+			top = xi
+	xi = top
+```

+ 42 - 0
max_val_algos.py

@@ -0,0 +1,42 @@
+### Author: estelendur
+# Find the maximum value k of a function f(X) where X = [x1,x2,...,xn]
+# Each xi in a range [ai,bi]
+# Uses shiftwidth=4 for tabs; foldmarker={{{,}}} for folds;
+
+import random
+
+### Methodical algorithm {{{
+# Find the highest value of f varying only x1, then x2, then...
+
+def methodical(f,x,ab,varyf,varyv):
+	# initialize each xi to rand(ai, bi)
+	for i in range(len(x)):
+		a = ab[i][0]
+		b = ab[i][1]
+		rand = random.random()
+		x[i] = (rand*(b-a)) + a
+	for i in range(len(x)):
+		x[i] = varyf(f,x,ab,i,varyv)
+	return f(x)
+### End Methodical }}}
+
+### Step-wise vary function {{{
+# Takes xi through its range in varyv steps of equal size
+# Vary functions: take function, x[], ab[], i, varyv
+
+def stepvary(f,x,ab,i,varyv):
+	a = ab[i][0]
+	b = ab[i][1]
+	step = (b-a)/varyv
+	currplace = a
+	currmax = f(x) # the current highest value of f
+	top = x[i] # the value of x[i] for which f is highest
+	while(currplace <= b):
+		x[i] = currplace
+		if f(x) > currmax:
+			currmax = f(x)
+			top = x[i]
+		currplace += step
+	return top
+### End Step-wise vary }}}
+

BIN
max_val_algos.pyc


+ 24 - 0
palindromes.hs

@@ -0,0 +1,24 @@
+-- Author: estelendur
+-- Given a base b and a number of digits n, how many palindromic integers?
+-- What proportion of possible integers are palindromes?
+-- Can we learn anything interesting from this?
+
+--half :: (Integral a) => a -> a
+--half x = ceiling(x/2)
+
+--pals :: (Integral a) => a -> a -> a
+pals n b = (b-1)*(b^(ceiling((n-1)/2))
+
+--num :: (Integral a) => a -> a -> a
+num n b = (b-1)*(b^(n-1))
+
+prop :: (Integral a) => a -> a -> Double
+prop n b = (pals n b)/(num n b)
+
+-- Find out the proportion of palindromes for all n, b up to nm, bm
+test :: (Integral a) => a -> a -> String
+test 1 1 = "1 digit in base 1 gives 1 palindrome\n"
+test n 1 = n ++ " digits in base 1 gives 1 palindrome\n"
+test 1 b = "1 digit in base " ++ b ++ " gives " ++ (b-1) ++ " palindromes\n"
+test nm bm = nm ++ " digits in base " ++ bm ++ " gives " ++ (prop nm bm)*100 ++ " percent palindromes\n" ++ (test (nm-1) bm) ++ (test nm (bm-1))
+

+ 37 - 0
palindromes.py

@@ -0,0 +1,37 @@
+# Author: estelendur
+# Given a base b and a number of digits n, how many palindromic integers?
+# What proportion of possible integers are palindromes?
+# Can we learn anything interesting from this?
+
+from math import *
+
+def half(x):
+    return ceil(float(x)/2)
+
+def pals(n, b):
+    return (b-1)*(b**(half(n-1)))
+
+def num(n, b):
+    return (b-1)*(b**(n-1))
+
+def prop (n, b):
+    return pals(n, b)/num(n, b)
+
+def testex(nm, bm):
+    if (nm==2 & bm==1):
+        return ""
+    elif (bm==1):
+        return ""
+    elif(nm==2):
+        return ""
+    else:
+        return (str(nm)+" digits in base "+str(bm)+" gives "+
+                str(floor(prop(nm,bm)*100))+" percent palindromes. "+
+                test(nm-1,bm)+test(nm,bm-1))
+
+def test(nm, b):
+    if(nm==2):
+        return ""
+    else:
+        return(str(nm)+" digits: "+str(prop(nm,b)*100)+" percent palindromes. "
+                +test(nm-1,b))

BIN
palindromes.pyc


BIN
palout1.png


+ 0 - 0
port-learnings.md


برخی فایل ها در این مقایسه diff نمایش داده نمی شوند زیرا تعداد فایل ها بسیار زیاد است