Next dojo - Match 9th (Monday)

0 views
Skip to first unread message

Ivan Sanchez

unread,
Feb 25, 2009, 3:26:55 AM2/25/09
to coding-do...@googlegroups.com
Hi all,

As usual, we have to decide problem/language/session format for the
next dojo. Any suggestion?

I hope people who was present at the last session can give their
ideas based on the received feedback as well.

Cheers,
--
Ivan Sanchez
http://www.isanchez.net

andhapp

unread,
Mar 4, 2009, 5:42:53 AM3/4/09
to Coding Dojo London
Language: Ruby
We could pick a problem from Ruby Quiz Site (http://rubyquiz.com/).

Anuj

Ivan Sanchez

unread,
Mar 5, 2009, 1:56:15 AM3/5/09
to coding-do...@googlegroups.com
Works for me.

Do you have a specific problem in mind? I'd suggest an easy/medium
one if we're starting from scratch, or any in case someone wants to
bring some initial code to help us get started.

Ivan

andhapp

unread,
Mar 6, 2009, 12:14:27 AM3/6/09
to Coding Dojo London
Knights Travails - http://tinyurl.com/d5jg3al

What do you say people?

Anuj


On Mar 5, 6:56 am, Ivan Sanchez <s4nc...@gmail.com> wrote:
>   Works for me.
>
>   Do you have a specific problem in mind? I'd suggest an easy/medium
> one if we're starting from scratch, or any in case someone wants to
> bring some initial code to help us get started.
>
> Ivan
>

Ivan Sanchez

unread,
Mar 9, 2009, 7:13:18 AM3/9/09
to coding-do...@googlegroups.com
 For those having problems with tinyurl, the link is
http://rubyquiz.com/quiz27.html

 I liked the problem although I wouldn't even know how to start
solving it. Well, that's one of the reasons we attend the dojo, isn't
it?

 See you guys tonight

Ivan

MarisO

unread,
Mar 20, 2009, 10:30:41 PM3/20/09
to Coding Dojo London
// Here is my scala solution

package chessdojo

object Main extends Application {

// a8, b7, b6 could return [ c7 , b5 , d6 , b7 ]
val p = new Position("A8")
p.shortestPath(new Position("B7"), Set(new Position("B6")))

val p3 = new Position("A8")
p3.shortestPath(new Position("A5"), Set(new Position("B6")))

// Example 2: a8 , g6 , b6 , c7 would return nil
val p2 = new Position("A8")
p2.shortestPath(new Position("G6"), Set(new Position("B6"),new
Position("C7")))
}

class Solution {
var shortestPath = Integer.MAX_VALUE;
}

final class Position(xpos: Int,ypos: Int) {
val x=xpos
val y=ypos

def this(p: String) {
this(p.charAt(0)-64,p.charAt(1)-48)
}

def shortestPath(target: Position, forbidden : Set[Position]): List
[Position] = {
val l = search(target: Position, forbidden : Set[Position],
List(),new Solution())
print(this+" -> "+target+" : ")
l.foreach( (p:Position) => print(p+" "))
println
l
}

private def search(target: Position, forbidden : Set[Position],
visited : List[Position],s:Solution) : List
[Position] = {
if (this == target) {
s.shortestPath = visited.length
visited+this
} else if (s.shortestPath<visited.length) Nil
else {
val avail = availableMoves -- forbidden -- visited
if (avail.isEmpty) Nil else {
val l = for (p <- avail) yield p.search(target,
forbidden+this ,visited+this,s)
var t = List[Position]()
var size=Integer.MAX_VALUE
l.foreach( p => if (!p.isEmpty && p.length<size)
{t=p; size=p.size} )
t
}
}
}

private def availableMoves: Set[Position] = {
val pos = for (i <- Set((1,2),(2,1),(1,-2),(2,-1),
(-1,2),(-2,1),(-1,-2),(-2,-1))) yield
new Position(x+i._1,y+i._2)
pos.filter((p: Position)=> p.x>0 && p.y>0 && p.x<=8 && p.y<=8)
}

override def toString = (x+64).toChar +""+ (48+y).toChar

override def hashCode: Int = 41*x+y

override def equals(other: Any) = other match {
case that: Position => this.x == that.x && this.y == that.y
case _ => false
}
}

On Mar 9, 11:13 am, Ivan Sanchez <s4nc...@gmail.com> wrote:
>  For those having problems with tinyurl, the link ishttp://rubyquiz.com/quiz27.html
>
>  I liked the problem although I wouldn't even know how to start
> solving it. Well, that's one of the reasons we attend the dojo, isn't
> it?
>
>  See you guys tonight
>
> Ivan
>
> On Fri, Mar 6, 2009 at 5:14 AM, andhapp <dutta.a...@googlemail.com> wrote:
>
> > Knights Travails -http://tinyurl.com/d5jg3al
Reply all
Reply to author
Forward
0 new messages