Greed: Difference between revisions
Content added Content deleted
(added Raku programming solution) |
m (→{{header|Raku}}: small changes) |
||
Line 988: | Line 988: | ||
sub execute (\y,\x) { |
sub execute (\y,\x) { |
||
my \i = @board[Y+y;X+x]; |
my \i = $ = @board[Y+y;X+x]; |
||
if countSteps(i, x, y) { |
if countSteps(i, x, y) { |
||
score += i; |
score += i; |
||
@board[ Y ; X ] = ' ' ; |
@board[ Y + y*$_ ; X + x*$_ ] = ' ' for ^i; |
||
@board[ Y+=y ; X+=x ] = ' |
@board[ Y += y*i ; X += x*i ] = '@'; |
||
} |
} |
||
} |
} |
||
Line 998: | Line 998: | ||
sub countSteps(\i, \x, \y) { |
sub countSteps(\i, \x, \y) { |
||
my \tX = $ = X ; my \tY = $ = Y; |
my \tX = $ = X ; my \tY = $ = Y; |
||
for |
for ^i { |
||
tX += x; tY += y; |
tX += x; tY += y; |
||
return False if |
return False if tX < 0 or tY < 0 or tX ≥ w or tY ≥ h or @board[tY;tX] eq ' ' |
||
} |
} |
||
return True; |
return True; |
||
Line 1,028: | Line 1,028: | ||
when 'x' { execute( 1,-1) if X > 0 and Y < h } # South-West |
when 'x' { execute( 1,-1) if X > 0 and Y < h } # South-West |
||
when 'c' { execute( 1, 0) if Y < h } # South |
when 'c' { execute( 1, 0) if Y < h } # South |
||
when 'v' { execute( 1, 1) if X < w and Y < h } # South- |
when 'v' { execute( 1, 1) if X < w and Y < h } # South-East |
||
} |
} |
||
@board[Y;X] = '@'; |
|||
}</lang> |
}</lang> |
||