Skip to content

Commit

Permalink
programming puzzles
Browse files Browse the repository at this point in the history
  • Loading branch information
bigos committed Jan 31, 2014
1 parent 97ce143 commit 59ff36a
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 0 deletions.
17 changes: 17 additions & 0 deletions Lisp/Puzzles/sum-squares-diff.lisp
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
(defun sum-squares (s e)
(loop for x from s to e
sum (expt x 2)))

(defun square-sum (s e)
(expt (loop for x from s to e
sum x) 2))

(defparameter *prs* '(11 7 5 3 2 1 ))


(defun more-prs ()
(loop for x from (+ 2 (car *prs*)) by 2
until (>= (length *prs*) 10002)
do
(unless (divisors x)
(push x *prs*))))
18 changes: 18 additions & 0 deletions Ruby/Codility/Lesson-4/max-product-of-three.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
def solution(a)
n = a.size
res = -1000 ^ 3
for p in 0 .. (n-3)
for q in (p+1) .. (n-2)
for r in (q+1) .. (n-1)
if ((0 <= p) and (p < q) and (q < r) and (r < n))
v = (a[p] * a[q] * a[r])
res = v if v > res
#puts "p#{p}* q#{q}* r#{r}= #{a[p] * a[q] * a[r]} "
end
end
end
end
res
end

p solution [-3,1,2,-2,5,6]
14 changes: 14 additions & 0 deletions Ruby/commas.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
def commas(num)
str=num.to_s.reverse
res = ''
for x in 0 .. (str.size-1)
res << str[x]
if (((x+1) % 3) == 0) and x < (str.size-1)
res << ','
end
end
res.reverse
end

p commas(1000000)
p commas(999999)

0 comments on commit 59ff36a

Please sign in to comment.