File tree Expand file tree Collapse file tree 1 file changed +51
-0
lines changed Expand file tree Collapse file tree 1 file changed +51
-0
lines changed Original file line number Diff line number Diff line change 1+ import { assertEquals } from "https://deno.land/std@0.208.0/assert/assert_equals.ts" ;
2+
3+ Deno . test ( "Day 11: Cosmic Expansion" , async ( t ) => {
4+ await t . step (
5+ "rotate map" ,
6+ async ( t ) => {
7+ await t . step ( "rotateLeft()" , ( ) =>
8+ assertEquals (
9+ rotateLeft ( [
10+ `123` ,
11+ `456` ,
12+ ] ) ,
13+ [
14+ `36` ,
15+ `25` ,
16+ `14` ,
17+ ] ,
18+ ) ) ;
19+
20+ await t . step ( "rotateRight()" , ( ) =>
21+ assertEquals (
22+ rotateRight ( [
23+ `36` ,
24+ `25` ,
25+ `14` ,
26+ ] ) ,
27+ [
28+ `123` ,
29+ `456` ,
30+ ] ,
31+ ) ) ;
32+ } ,
33+ ) ;
34+ } ) ;
35+
36+ const rotateLeft = ( map : Array < string > ) : Array < string > => {
37+ const res : Array < Array < string > > = [ ] ;
38+ const w = map [ 0 ] . length ;
39+ for ( let col = 0 ; col < w ; col ++ ) {
40+ for ( let row = 0 ; row < map . length ; row ++ ) {
41+ const i = w - col - 1 ;
42+ if ( res [ i ] === undefined ) res [ i ] = [ ] ;
43+ res [ i ] [ row ] = map [ row ] [ col ] ;
44+ }
45+ }
46+
47+ return res . map ( ( row ) => row . join ( "" ) ) ;
48+ } ;
49+
50+ const rotateRight = ( map : Array < string > ) : Array < string > =>
51+ rotateLeft ( rotateLeft ( rotateLeft ( map ) ) ) ;
You can’t perform that action at this time.
0 commit comments