8
\$\begingroup\$

We've all seen the pictures captioned "How many squares are in this image? 98% will not get this right!" Well, here's your chance to laugh at that 98%.

Input

A rectangular block made of only 2 characters. In a general form, this is defined by m lines, each containing n characters.

Example:

0000xxx
00x00xx
00000xx
xxxxx0x

This can be represented as a newline-separated string, an array of strings, or a 2D array of characters. Any other input types should be suggested in the comments.

Output

The output will be an integer representing the total amount of squares represented individually by both characters (in pseudocode, num_squares(char1) + num_squares(char2))

A square is defined as a set of instances of the same character that fully outline a geometric square of side length at least 2. These squares need not be filled by the character that outlines it. The following examples illustrate this concept:

x0
0x    // no squares

xxx
x0x
xxx   // 1 square of side length 3

0000
0xx0
0xx0
0000  // 1 square of side length 2, 1 square of side length 4

Scoring

Your program will be scored by 2 criteria, in descending order of importance:

  • Number of characters in your code block that aren't part of a square, as defined above (you should aim to minimize this!) (Note: characters inside of a square are not automatically considered as part of that square) (Note 2: newlines do not count toward this score)
  • Number of bytes (you should aim to minimize this!)

The second criterion will act as a tie breaker for the first.

Challenge Rules

  • For the sake of flexibility, you may choose to use any 2 alphanumeric characters to replace the 0 and x from my examples, as long as they are not the same character.
  • Each line in the input rectangle must have the same length, and must not contain any character other than the 2 specified for your answer to the challenge (besides the newline character, if applicable)
  • Trivial squares (1x1 squares denoted by a single character) do not count toward the output. They suck.
  • Your program does not have to handle empty input, but it should handle cases where no squares are possible (when one of the dimensions of the input rectangle is 1)
  • You may also choose to specify that you are handling diagonally aligned squares if you relish the challenge. This would be added to the output specified in the challenge specs.

Example of this concept:

Input:

00x00
0x0x0
x000x
0x0x0
00x00

Output: 6 (1 diagonally aligned square of side length 3, 5 diagonally aligned squares of side length 2)

Test Cases

The following are some basic test cases that your program should match. The value in parentheses is the output should you choose to count diagonally aligned squares.

Input:

xxxx
x00x
x0xx
xxxx

Output: 2 (2)

Input:

x00000xxx0

Output: 0 (0)

Input:

xxx0x0x000xx0xx0
0x000x00x0x0xx00
00xx0xx00xx0000x
x0x0x0x0x00x0xxx
00xx0xxx00xxx0x0

Output: 0 (5)

Input:

0000
0000
0000
0000
0000
0000

Output: 26 (34)

Input:

xxx00
xx000

Output: 2 (2)

General rules

  • Standard rules apply for your answer, so you are allowed to use STDIN/STDOUT, functions/method with the proper parameters and return-type, full programs. Your call.
  • Default Loopholes are forbidden.
  • If possible, please add a link with a test for your code.
  • Adding an explanation for your answer is highly recommended.
  • Any questions/corrections/advice for me? Comment below! This is my first question, so I'm excited to learn as much from it as possible.
\$\endgroup\$
15
  • 2
    \$\begingroup\$ How does the number of squares in your code affect your score (I feel like having squares should reduce your score)? This should also be tagged code-challenge instead of code-golf because the scoring isn't just length. \$\endgroup\$ Sep 20, 2018 at 18:12
  • \$\begingroup\$ Scoring criteria is now primarily based on squares and ties are broken by byte count. Thanks for the feedback! \$\endgroup\$
    – TCFP
    Sep 20, 2018 at 18:21
  • 1
    \$\begingroup\$ Does that mean that some very lengthy code with \$N\$ squares beats any shorter code with less than \$N\$ squares? \$\endgroup\$
    – Arnauld
    Sep 20, 2018 at 19:27
  • 1
    \$\begingroup\$ Diagonal squares are not counted for scoring. I'd say nonrectangular code is fine, squares remain defined the same as in the specs. The rectangular specification for the input is mostly for simplicity's sake. \$\endgroup\$
    – TCFP
    Sep 20, 2018 at 20:56
  • 1
    \$\begingroup\$ Admittedly, I'm not as knowledgeable of esoteric languages like that. It's necessary to have a newline to even count something as a square to begin with, so I don't think it should count toward anyone's score. \$\endgroup\$
    – TCFP
    Sep 21, 2018 at 13:57

3 Answers 3

5
\$\begingroup\$

Perl, 0 characters not in squares (25430 bytes)

##((((((((((((((((((((((((((((((((((((((((((((((
##($$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$(
##($rrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrr$(
##($r,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,r$(
##($r,$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$,r$(
##($r,$cccccccccccccccccccccccccccccccccccc$,r$(
##($r,$c,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,c$,r$(
##($r,$c,@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@,c$,r$(
##($r,$c,@aaaaaaaaaaaaaaaaaaaaaaaaaaaaaa@,c$,r$(
##($r,$c,@a))))))))))))))))))))))))))))a@,c$,r$(
##($r,$c,@a)==========================)a@,c$,r$(
##($r,$c,@a)=@@@@@@@@@@@@@@@@@@@@@@@@=)a@,c$,r$(
##($r,$c,@a)=@AAAAAAAAAAAAAAAAAAAAAA@=)a@,c$,r$(
##($r,$c,@a)=@ARRRRRRRRRRRRRRRRRRRRA@=)a@,c$,r$(
##($r,$c,@a)=@ARGGGGGGGGGGGGGGGGGGRA@=)a@,c$,r$(
##($r,$c,@a)=@ARGVVVVVVVVVVVVVVVVGRA@=)a@,c$,r$(
##($r,$c,@a)=@ARGV;;;;;;;;;;;;;;VGRA@=)a@,c$,r$(
##($r,$c,@a)=@ARGV;<<<<<<<<<<<<;VGRA@=)a@,c$,r$(
##($r,$c,@a)=@ARGV;<<<<<<<<<<<<;VGRA@=)a@,c$,r$(
##($r,$c,@a)=@ARGV;<<''''''''<<;VGRA@=)a@,c$,r$(
##($r,$c,@a)=@ARGV;<<''''''''<<;VGRA@=)a@,c$,r$(
##($r,$c,@a)=@ARGV;<<'';;;;''<<;VGRA@=)a@,c$,r$(
  ($r,$c,@a)=@ARGV;<<'';##;''<<;VGRA@=)a@,c$,r$(
  ($r,$c,@a)=@ARGV;<<'';##;''<<;VGRA@=)a@,c$,r$(
##($r,$c,@a)=@ARGV;<<'';;;;''<<;VGRA@=)a@,c$,r$(
##($r,$c,@a)=@ARGV;<<''''''''<<;VGRA@=)a@,c$,r$(
##($r,$c,@a)=@ARGV;<<''''''''<<;VGRA@=)a@,c$,r$(
##($r,$c,@a)=@ARGV;<<<<<<<<<<<<;VGRA@=)a@,c$,r$(
##($r,$c,@a)=@ARGV;<<<<<<<<<<<<;VGRA@=)a@,c$,r$(
##($r,$c,@a)=@ARGV;;;;;;;;;;;;;;VGRA@=)a@,c$,r$(
##($r,$c,@a)=@ARGVVVVVVVVVVVVVVVVGRA@=)a@,c$,r$(
##($r,$c,@a)=@ARGGGGGGGGGGGGGGGGGGRA@=)a@,c$,r$(
##($r,$c,@a)=@ARRRRRRRRRRRRRRRRRRRRA@=)a@,c$,r$(
##($r,$c,@a)=@AAAAAAAAAAAAAAAAAAAAAA@=)a@,c$,r$(
##($r,$c,@a)=@@@@@@@@@@@@@@@@@@@@@@@@=)a@,c$,r$(
##($r,$c,@a)==========================)a@,c$,r$(
##($r,$c,@a))))))))))))))))))))))))))))a@,c$,r$(
##($r,$c,@aaaaaaaaaaaaaaaaaaaaaaaaaaaaaa@,c$,r$(
##($r,$c,@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@,c$,r$(
##($r,$c,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,c$,r$(
##($r,$cccccccccccccccccccccccccccccccccccc$,r$(
##($r,$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$,r$(
##($r,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,r$(
##($rrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrr$(
##($$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$(
##((((((((((((((((((((((((((((((((((((((((((((((

##ffffffffffffffffffffffffffffffffffffffffff
##foooooooooooooooooooooooooooooooooooooooof
##forrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrof
##for$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$rof
##for$yyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyy$rof
##for$y((((((((((((((((((((((((((((((((y$rof
##for$y(000000000000000000000000000000(y$rof
##for$y(0............................0(y$rof
##for$y(0............................0(y$rof
##for$y(0..$$$$$$$$$$$$$$$$$$$$$$$$..0(y$rof
##for$y(0..$rrrrrrrrrrrrrrrrrrrrrr$..0(y$rof
##for$y(0..$r--------------------r$..0(y$rof
##for$y(0..$r-111111111111111111-r$..0(y$rof
##for$y(0..$r-1))))))))))))))))1-r$..0(y$rof
##for$y(0..$r-1){{{{{{{{{{{{{{)1-r$..0(y$rof
##for$y(0..$r-1){<<<<<<<<<<<<{)1-r$..0(y$rof
##for$y(0..$r-1){<<<<<<<<<<<<{)1-r$..0(y$rof
##for$y(0..$r-1){<<''''''''<<{)1-r$..0(y$rof
##for$y(0..$r-1){<<''''''''<<{)1-r$..0(y$rof
##for$y(0..$r-1){<<'';;;;''<<{)1-r$..0(y$rof
  for$y(0..$r-1){<<'';##;''<<{)1-r$..0(y$rof
  for$y(0..$r-1){<<'';##;''<<{)1-r$..0(y$rof
##for$y(0..$r-1){<<'';;;;''<<{)1-r$..0(y$rof
##for$y(0..$r-1){<<''''''''<<{)1-r$..0(y$rof
##for$y(0..$r-1){<<''''''''<<{)1-r$..0(y$rof
##for$y(0..$r-1){<<<<<<<<<<<<{)1-r$..0(y$rof
##for$y(0..$r-1){<<<<<<<<<<<<{)1-r$..0(y$rof
##for$y(0..$r-1){{{{{{{{{{{{{{)1-r$..0(y$rof
##for$y(0..$r-1))))))))))))))))1-r$..0(y$rof
##for$y(0..$r-111111111111111111-r$..0(y$rof
##for$y(0..$r--------------------r$..0(y$rof
##for$y(0..$rrrrrrrrrrrrrrrrrrrrrr$..0(y$rof
##for$y(0..$$$$$$$$$$$$$$$$$$$$$$$$..0(y$rof
##for$y(0............................0(y$rof
##for$y(0............................0(y$rof
##for$y(000000000000000000000000000000(y$rof
##for$y((((((((((((((((((((((((((((((((y$rof
##for$yyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyy$rof
##for$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$rof
##forrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrof
##foooooooooooooooooooooooooooooooooooooooof
##ffffffffffffffffffffffffffffffffffffffffff

##ffffffffffffffffffffffffffffffffffffffffff
##foooooooooooooooooooooooooooooooooooooooof
##forrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrof
##for$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$rof
##for$xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx$rof
##for$x((((((((((((((((((((((((((((((((x$rof
##for$x(000000000000000000000000000000(x$rof
##for$x(0............................0(x$rof
##for$x(0............................0(x$rof
##for$x(0..$$$$$$$$$$$$$$$$$$$$$$$$..0(x$rof
##for$x(0..$cccccccccccccccccccccc$..0(x$rof
##for$x(0..$c--------------------c$..0(x$rof
##for$x(0..$c-111111111111111111-c$..0(x$rof
##for$x(0..$c-1))))))))))))))))1-c$..0(x$rof
##for$x(0..$c-1){{{{{{{{{{{{{{)1-c$..0(x$rof
##for$x(0..$c-1){<<<<<<<<<<<<{)1-c$..0(x$rof
##for$x(0..$c-1){<<<<<<<<<<<<{)1-c$..0(x$rof
##for$x(0..$c-1){<<''''''''<<{)1-c$..0(x$rof
##for$x(0..$c-1){<<''''''''<<{)1-c$..0(x$rof
##for$x(0..$c-1){<<'';;;;''<<{)1-c$..0(x$rof
  for$x(0..$c-1){<<'';##;''<<{)1-c$..0(x$rof
  for$x(0..$c-1){<<'';##;''<<{)1-c$..0(x$rof
##for$x(0..$c-1){<<'';;;;''<<{)1-c$..0(x$rof
##for$x(0..$c-1){<<''''''''<<{)1-c$..0(x$rof
##for$x(0..$c-1){<<''''''''<<{)1-c$..0(x$rof
##for$x(0..$c-1){<<<<<<<<<<<<{)1-c$..0(x$rof
##for$x(0..$c-1){<<<<<<<<<<<<{)1-c$..0(x$rof
##for$x(0..$c-1){{{{{{{{{{{{{{)1-c$..0(x$rof
##for$x(0..$c-1))))))))))))))))1-c$..0(x$rof
##for$x(0..$c-111111111111111111-c$..0(x$rof
##for$x(0..$c--------------------c$..0(x$rof
##for$x(0..$cccccccccccccccccccccc$..0(x$rof
##for$x(0..$$$$$$$$$$$$$$$$$$$$$$$$..0(x$rof
##for$x(0............................0(x$rof
##for$x(0............................0(x$rof
##for$x(000000000000000000000000000000(x$rof
##for$x((((((((((((((((((((((((((((((((x$rof
##for$xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx$rof
##for$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$rof
##forrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrof
##foooooooooooooooooooooooooooooooooooooooof
##ffffffffffffffffffffffffffffffffffffffffff

##ffffffffffffffffffffffffffffffffffffffffffffffff
##foooooooooooooooooooooooooooooooooooooooooooooof
##forrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrof
##for$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$rof
##for$ssssssssssssssssssssssssssssssssssssssss$rof
##for$s((((((((((((((((((((((((((((((((((((((s$rof
##for$s(111111111111111111111111111111111111(s$rof
##for$s(1..................................1(s$rof
##for$s(1..................................1(s$rof
##for$s(1..$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$..1(s$rof
##for$s(1..$cccccccccccccccccccccccccccc$..1(s$rof
##for$s(1..$c--------------------------c$..1(s$rof
##for$s(1..$c-$$$$$$$$$$$$$$$$$$$$$$$$-c$..1(s$rof
##for$s(1..$c-$xxxxxxxxxxxxxxxxxxxxxx$-c$..1(s$rof
##for$s(1..$c-$x--------------------x$-c$..1(s$rof
##for$s(1..$c-$x-111111111111111111-x$-c$..1(s$rof
##for$s(1..$c-$x-1))))))))))))))))1-x$-c$..1(s$rof
##for$s(1..$c-$x-1){{{{{{{{{{{{{{)1-x$-c$..1(s$rof
##for$s(1..$c-$x-1){<<<<<<<<<<<<{)1-x$-c$..1(s$rof
##for$s(1..$c-$x-1){<<<<<<<<<<<<{)1-x$-c$..1(s$rof
##for$s(1..$c-$x-1){<<''''''''<<{)1-x$-c$..1(s$rof
##for$s(1..$c-$x-1){<<''''''''<<{)1-x$-c$..1(s$rof
##for$s(1..$c-$x-1){<<'';;;;''<<{)1-x$-c$..1(s$rof
  for$s(1..$c-$x-1){<<'';##;''<<{)1-x$-c$..1(s$rof
  for$s(1..$c-$x-1){<<'';##;''<<{)1-x$-c$..1(s$rof
##for$s(1..$c-$x-1){<<'';;;;''<<{)1-x$-c$..1(s$rof
##for$s(1..$c-$x-1){<<''''''''<<{)1-x$-c$..1(s$rof
##for$s(1..$c-$x-1){<<''''''''<<{)1-x$-c$..1(s$rof
##for$s(1..$c-$x-1){<<<<<<<<<<<<{)1-x$-c$..1(s$rof
##for$s(1..$c-$x-1){<<<<<<<<<<<<{)1-x$-c$..1(s$rof
##for$s(1..$c-$x-1){{{{{{{{{{{{{{)1-x$-c$..1(s$rof
##for$s(1..$c-$x-1))))))))))))))))1-x$-c$..1(s$rof
##for$s(1..$c-$x-111111111111111111-x$-c$..1(s$rof
##for$s(1..$c-$x--------------------x$-c$..1(s$rof
##for$s(1..$c-$xxxxxxxxxxxxxxxxxxxxxx$-c$..1(s$rof
##for$s(1..$c-$$$$$$$$$$$$$$$$$$$$$$$$-c$..1(s$rof
##for$s(1..$c--------------------------c$..1(s$rof
##for$s(1..$cccccccccccccccccccccccccccc$..1(s$rof
##for$s(1..$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$..1(s$rof
##for$s(1..................................1(s$rof
##for$s(1..................................1(s$rof
##for$s(111111111111111111111111111111111111(s$rof
##for$s((((((((((((((((((((((((((((((((((((((s$rof
##for$ssssssssssssssssssssssssssssssssssssssss$rof
##for$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$rof
##forrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrof
##foooooooooooooooooooooooooooooooooooooooooooooof
##ffffffffffffffffffffffffffffffffffffffffffffffff

##$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$
##$mmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmm$
##$m========================================================m$
##$m=$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$=m$
##$m=$aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa$=m$
##$m=$a[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[a$=m$
##$m=$a[$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$[a$=m$
##$m=$a[$oooooooooooooooooooooooooooooooooooooooooooooo$[a$=m$
##$m=$a[$o============================================o$[a$=m$
##$m=$a[$o=$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$=o$[a$=m$
##$m=$a[$o=$cccccccccccccccccccccccccccccccccccccccc$=o$[a$=m$
##$m=$a[$o=$c**************************************c$=o$[a$=m$
##$m=$a[$o=$c*$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$*c$=o$[a$=m$
##$m=$a[$o=$c*$yyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyy$*c$=o$[a$=m$
##$m=$a[$o=$c*$y++++++++++++++++++++++++++++++++y$*c$=o$[a$=m$
##$m=$a[$o=$c*$y+$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$+y$*c$=o$[a$=m$
##$m=$a[$o=$c*$y+$xxxxxxxxxxxxxxxxxxxxxxxxxxxx$+y$*c$=o$[a$=m$
##$m=$a[$o=$c*$y+$x]]]]]]]]]]]]]]]]]]]]]]]]]]x$+y$*c$=o$[a$=m$
##$m=$a[$o=$c*$y+$x];;;;;;;;;;;;;;;;;;;;;;;;]x$+y$*c$=o$[a$=m$
##$m=$a[$o=$c*$y+$x];$$$$$$$$$$$$$$$$$$$$$$;]x$+y$*c$=o$[a$=m$
##$m=$a[$o=$c*$y+$x];$kkkkkkkkkkkkkkkkkkkk$;]x$+y$*c$=o$[a$=m$
##$m=$a[$o=$c*$y+$x];$k==================k$;]x$+y$*c$=o$[a$=m$
##$m=$a[$o=$c*$y+$x];$k=0000000000000000=k$;]x$+y$*c$=o$[a$=m$
##$m=$a[$o=$c*$y+$x];$k=0;;;;;;;;;;;;;;0=k$;]x$+y$*c$=o$[a$=m$
##$m=$a[$o=$c*$y+$x];$k=0;<<<<<<<<<<<<;0=k$;]x$+y$*c$=o$[a$=m$
##$m=$a[$o=$c*$y+$x];$k=0;<<<<<<<<<<<<;0=k$;]x$+y$*c$=o$[a$=m$
##$m=$a[$o=$c*$y+$x];$k=0;<<''''''''<<;0=k$;]x$+y$*c$=o$[a$=m$
##$m=$a[$o=$c*$y+$x];$k=0;<<''''''''<<;0=k$;]x$+y$*c$=o$[a$=m$
##$m=$a[$o=$c*$y+$x];$k=0;<<'';;;;''<<;0=k$;]x$+y$*c$=o$[a$=m$
  $m=$a[$o=$c*$y+$x];$k=0;<<'';##;''<<;0=k$;]x$+y$*c$=o$[a$=m$
  $m=$a[$o=$c*$y+$x];$k=0;<<'';##;''<<;0=k$;]x$+y$*c$=o$[a$=m$
##$m=$a[$o=$c*$y+$x];$k=0;<<'';;;;''<<;0=k$;]x$+y$*c$=o$[a$=m$
##$m=$a[$o=$c*$y+$x];$k=0;<<''''''''<<;0=k$;]x$+y$*c$=o$[a$=m$
##$m=$a[$o=$c*$y+$x];$k=0;<<''''''''<<;0=k$;]x$+y$*c$=o$[a$=m$
##$m=$a[$o=$c*$y+$x];$k=0;<<<<<<<<<<<<;0=k$;]x$+y$*c$=o$[a$=m$
##$m=$a[$o=$c*$y+$x];$k=0;<<<<<<<<<<<<;0=k$;]x$+y$*c$=o$[a$=m$
##$m=$a[$o=$c*$y+$x];$k=0;;;;;;;;;;;;;;0=k$;]x$+y$*c$=o$[a$=m$
##$m=$a[$o=$c*$y+$x];$k=0000000000000000=k$;]x$+y$*c$=o$[a$=m$
##$m=$a[$o=$c*$y+$x];$k==================k$;]x$+y$*c$=o$[a$=m$
##$m=$a[$o=$c*$y+$x];$kkkkkkkkkkkkkkkkkkkk$;]x$+y$*c$=o$[a$=m$
##$m=$a[$o=$c*$y+$x];$$$$$$$$$$$$$$$$$$$$$$;]x$+y$*c$=o$[a$=m$
##$m=$a[$o=$c*$y+$x];;;;;;;;;;;;;;;;;;;;;;;;]x$+y$*c$=o$[a$=m$
##$m=$a[$o=$c*$y+$x]]]]]]]]]]]]]]]]]]]]]]]]]]x$+y$*c$=o$[a$=m$
##$m=$a[$o=$c*$y+$xxxxxxxxxxxxxxxxxxxxxxxxxxxx$+y$*c$=o$[a$=m$
##$m=$a[$o=$c*$y+$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$+y$*c$=o$[a$=m$
##$m=$a[$o=$c*$y++++++++++++++++++++++++++++++++y$*c$=o$[a$=m$
##$m=$a[$o=$c*$yyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyy$*c$=o$[a$=m$
##$m=$a[$o=$c*$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$*c$=o$[a$=m$
##$m=$a[$o=$c**************************************c$=o$[a$=m$
##$m=$a[$o=$cccccccccccccccccccccccccccccccccccccccc$=o$[a$=m$
##$m=$a[$o=$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$=o$[a$=m$
##$m=$a[$o============================================o$[a$=m$
##$m=$a[$oooooooooooooooooooooooooooooooooooooooooooooo$[a$=m$
##$m=$a[$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$[a$=m$
##$m=$a[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[a$=m$
##$m=$aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa$=m$
##$m=$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$=m$
##$m========================================================m$
##$mmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmm$
##$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$

##ffffffffffffffffffffffffffffffffffffff
##foooooooooooooooooooooooooooooooooooof
##forrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrof
##for$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$rof
##for$tttttttttttttttttttttttttttttt$rof
##for$t((((((((((((((((((((((((((((t$rof
##for$t(11111111111111111111111111(t$rof
##for$t(1........................1(t$rof
##for$t(1........................1(t$rof
##for$t(1..$$$$$$$$$$$$$$$$$$$$..1(t$rof
##for$t(1..$ssssssssssssssssss$..1(t$rof
##for$t(1..$s))))))))))))))))s$..1(t$rof
##for$t(1..$s){{{{{{{{{{{{{{)s$..1(t$rof
##for$t(1..$s){<<<<<<<<<<<<{)s$..1(t$rof
##for$t(1..$s){<<<<<<<<<<<<{)s$..1(t$rof
##for$t(1..$s){<<''''''''<<{)s$..1(t$rof
##for$t(1..$s){<<''''''''<<{)s$..1(t$rof
##for$t(1..$s){<<'';;;;''<<{)s$..1(t$rof
  for$t(1..$s){<<'';##;''<<{)s$..1(t$rof
  for$t(1..$s){<<'';##;''<<{)s$..1(t$rof
##for$t(1..$s){<<'';;;;''<<{)s$..1(t$rof
##for$t(1..$s){<<''''''''<<{)s$..1(t$rof
##for$t(1..$s){<<''''''''<<{)s$..1(t$rof
##for$t(1..$s){<<<<<<<<<<<<{)s$..1(t$rof
##for$t(1..$s){<<<<<<<<<<<<{)s$..1(t$rof
##for$t(1..$s){{{{{{{{{{{{{{)s$..1(t$rof
##for$t(1..$s))))))))))))))))s$..1(t$rof
##for$t(1..$ssssssssssssssssss$..1(t$rof
##for$t(1..$$$$$$$$$$$$$$$$$$$$..1(t$rof
##for$t(1........................1(t$rof
##for$t(1........................1(t$rof
##for$t(11111111111111111111111111(t$rof
##for$t((((((((((((((((((((((((((((t$rof
##for$tttttttttttttttttttttttttttttt$rof
##for$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$rof
##forrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrof
##foooooooooooooooooooooooooooooooooooof
##ffffffffffffffffffffffffffffffffffffff

##ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff
##foooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooof
##forrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrof
##for((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((rof
##for($$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$(rof
##for($tttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttt$(rof
##for($t,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,t$(rof
##for($t,$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$,t$(rof
##for($t,$cccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc$,t$(rof
##for($t,$c**********************************************************c$,t$(rof
##for($t,$c*$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$*c$,t$(rof
##for($t,$c*$tttttttttttttttttttttttttttttttttttttttttttttttttttttt$*c$,t$(rof
##for($t,$c*$t,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,t$*c$,t$(rof
##for($t,$c*$t,$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$,t$*c$,t$(rof
##for($t,$c*$t,$tttttttttttttttttttttttttttttttttttttttttttttttt$,t$*c$,t$(rof
##for($t,$c*$t,$t++++++++++++++++++++++++++++++++++++++++++++++t$,t$*c$,t$(rof
##for($t,$c*$t,$t+$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$+t$,t$*c$,t$(rof
##for($t,$c*$t,$t+$cccccccccccccccccccccccccccccccccccccccccc$+t$,t$*c$,t$(rof
##for($t,$c*$t,$t+$c****************************************c$+t$,t$*c$,t$(rof
##for($t,$c*$t,$t+$c*$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$*c$+t$,t$*c$,t$(rof
##for($t,$c*$t,$t+$c*$ssssssssssssssssssssssssssssssssssss$*c$+t$,t$*c$,t$(rof
##for($t,$c*$t,$t+$c*$s,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,s$*c$+t$,t$*c$,t$(rof
##for($t,$c*$t,$t+$c*$s,$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$,s$*c$+t$,t$*c$,t$(rof
##for($t,$c*$t,$t+$c*$s,$cccccccccccccccccccccccccccccc$,s$*c$+t$,t$*c$,t$(rof
##for($t,$c*$t,$t+$c*$s,$c****************************c$,s$*c$+t$,t$*c$,t$(rof
##for($t,$c*$t,$t+$c*$s,$c*$$$$$$$$$$$$$$$$$$$$$$$$$$*c$,s$*c$+t$,t$*c$,t$(rof
##for($t,$c*$t,$t+$c*$s,$c*$tttttttttttttttttttttttt$*c$,s$*c$+t$,t$*c$,t$(rof
##for($t,$c*$t,$t+$c*$s,$c*$t++++++++++++++++++++++t$*c$,s$*c$+t$,t$*c$,t$(rof
##for($t,$c*$t,$t+$c*$s,$c*$t+$$$$$$$$$$$$$$$$$$$$+t$*c$,s$*c$+t$,t$*c$,t$(rof
##for($t,$c*$t,$t+$c*$s,$c*$t+$ssssssssssssssssss$+t$*c$,s$*c$+t$,t$*c$,t$(rof
##for($t,$c*$t,$t+$c*$s,$c*$t+$s))))))))))))))))s$+t$*c$,s$*c$+t$,t$*c$,t$(rof
##for($t,$c*$t,$t+$c*$s,$c*$t+$s){{{{{{{{{{{{{{)s$+t$*c$,s$*c$+t$,t$*c$,t$(rof
##for($t,$c*$t,$t+$c*$s,$c*$t+$s){<<<<<<<<<<<<{)s$+t$*c$,s$*c$+t$,t$*c$,t$(rof
##for($t,$c*$t,$t+$c*$s,$c*$t+$s){<<<<<<<<<<<<{)s$+t$*c$,s$*c$+t$,t$*c$,t$(rof
##for($t,$c*$t,$t+$c*$s,$c*$t+$s){<<''''''''<<{)s$+t$*c$,s$*c$+t$,t$*c$,t$(rof
##for($t,$c*$t,$t+$c*$s,$c*$t+$s){<<''''''''<<{)s$+t$*c$,s$*c$+t$,t$*c$,t$(rof
##for($t,$c*$t,$t+$c*$s,$c*$t+$s){<<'';;;;''<<{)s$+t$*c$,s$*c$+t$,t$*c$,t$(rof
  for($t,$c*$t,$t+$c*$s,$c*$t+$s){<<'';##;''<<{)s$+t$*c$,s$*c$+t$,t$*c$,t$(rof
  for($t,$c*$t,$t+$c*$s,$c*$t+$s){<<'';##;''<<{)s$+t$*c$,s$*c$+t$,t$*c$,t$(rof
##for($t,$c*$t,$t+$c*$s,$c*$t+$s){<<'';;;;''<<{)s$+t$*c$,s$*c$+t$,t$*c$,t$(rof
##for($t,$c*$t,$t+$c*$s,$c*$t+$s){<<''''''''<<{)s$+t$*c$,s$*c$+t$,t$*c$,t$(rof
##for($t,$c*$t,$t+$c*$s,$c*$t+$s){<<''''''''<<{)s$+t$*c$,s$*c$+t$,t$*c$,t$(rof
##for($t,$c*$t,$t+$c*$s,$c*$t+$s){<<<<<<<<<<<<{)s$+t$*c$,s$*c$+t$,t$*c$,t$(rof
##for($t,$c*$t,$t+$c*$s,$c*$t+$s){<<<<<<<<<<<<{)s$+t$*c$,s$*c$+t$,t$*c$,t$(rof
##for($t,$c*$t,$t+$c*$s,$c*$t+$s){{{{{{{{{{{{{{)s$+t$*c$,s$*c$+t$,t$*c$,t$(rof
##for($t,$c*$t,$t+$c*$s,$c*$t+$s))))))))))))))))s$+t$*c$,s$*c$+t$,t$*c$,t$(rof
##for($t,$c*$t,$t+$c*$s,$c*$t+$ssssssssssssssssss$+t$*c$,s$*c$+t$,t$*c$,t$(rof
##for($t,$c*$t,$t+$c*$s,$c*$t+$$$$$$$$$$$$$$$$$$$$+t$*c$,s$*c$+t$,t$*c$,t$(rof
##for($t,$c*$t,$t+$c*$s,$c*$t++++++++++++++++++++++t$*c$,s$*c$+t$,t$*c$,t$(rof
##for($t,$c*$t,$t+$c*$s,$c*$tttttttttttttttttttttttt$*c$,s$*c$+t$,t$*c$,t$(rof
##for($t,$c*$t,$t+$c*$s,$c*$$$$$$$$$$$$$$$$$$$$$$$$$$*c$,s$*c$+t$,t$*c$,t$(rof
##for($t,$c*$t,$t+$c*$s,$c****************************c$,s$*c$+t$,t$*c$,t$(rof
##for($t,$c*$t,$t+$c*$s,$cccccccccccccccccccccccccccccc$,s$*c$+t$,t$*c$,t$(rof
##for($t,$c*$t,$t+$c*$s,$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$,s$*c$+t$,t$*c$,t$(rof
##for($t,$c*$t,$t+$c*$s,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,s$*c$+t$,t$*c$,t$(rof
##for($t,$c*$t,$t+$c*$ssssssssssssssssssssssssssssssssssss$*c$+t$,t$*c$,t$(rof
##for($t,$c*$t,$t+$c*$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$*c$+t$,t$*c$,t$(rof
##for($t,$c*$t,$t+$c****************************************c$+t$,t$*c$,t$(rof
##for($t,$c*$t,$t+$cccccccccccccccccccccccccccccccccccccccccc$+t$,t$*c$,t$(rof
##for($t,$c*$t,$t+$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$+t$,t$*c$,t$(rof
##for($t,$c*$t,$t++++++++++++++++++++++++++++++++++++++++++++++t$,t$*c$,t$(rof
##for($t,$c*$t,$tttttttttttttttttttttttttttttttttttttttttttttttt$,t$*c$,t$(rof
##for($t,$c*$t,$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$,t$*c$,t$(rof
##for($t,$c*$t,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,t$*c$,t$(rof
##for($t,$c*$tttttttttttttttttttttttttttttttttttttttttttttttttttttt$*c$,t$(rof
##for($t,$c*$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$*c$,t$(rof
##for($t,$c**********************************************************c$,t$(rof
##for($t,$cccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc$,t$(rof
##for($t,$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$,t$(rof
##for($t,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,t$(rof
##for($tttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttt$(rof
##for($$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$(rof
##for((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((rof
##forrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrof
##foooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooof
##ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff

##$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$
##$kkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkk$
##$k++++++++++++++++++++++++++++++++++++++++++++k$
##$k+==========================================+k$
##$k+=$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$=+k$
##$k+=$aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa$=+k$
##$k+=$a[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[a$=+k$
##$k+=$a[$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$[a$=+k$
##$k+=$a[$oooooooooooooooooooooooooooooooo$[a$=+k$
##$k+=$a[$o++++++++++++++++++++++++++++++o$[a$=+k$
##$k+=$a[$o+$$$$$$$$$$$$$$$$$$$$$$$$$$$$+o$[a$=+k$
##$k+=$a[$o+$__________________________$+o$[a$=+k$
##$k+=$a[$o+$_]]]]]]]]]]]]]]]]]]]]]]]]_$+o$[a$=+k$
##$k+=$a[$o+$_]eeeeeeeeeeeeeeeeeeeeee]_$+o$[a$=+k$
##$k+=$a[$o+$_]eqqqqqqqqqqqqqqqqqqqqe]_$+o$[a$=+k$
##$k+=$a[$o+$_]eq$$$$$$$$$$$$$$$$$$qe]_$+o$[a$=+k$
##$k+=$a[$o+$_]eq$mmmmmmmmmmmmmmmm$qe]_$+o$[a$=+k$
##$k+=$a[$o+$_]eq$m;;;;;;;;;;;;;;m$qe]_$+o$[a$=+k$
##$k+=$a[$o+$_]eq$m;<<<<<<<<<<<<;m$qe]_$+o$[a$=+k$
##$k+=$a[$o+$_]eq$m;<<<<<<<<<<<<;m$qe]_$+o$[a$=+k$
##$k+=$a[$o+$_]eq$m;<<''''''''<<;m$qe]_$+o$[a$=+k$
##$k+=$a[$o+$_]eq$m;<<''''''''<<;m$qe]_$+o$[a$=+k$
##$k+=$a[$o+$_]eq$m;<<'';;;;''<<;m$qe]_$+o$[a$=+k$
  $k+=$a[$o+$_]eq$m;<<'';##;''<<;m$qe]_$+o$[a$=+k$
  $k+=$a[$o+$_]eq$m;<<'';##;''<<;m$qe]_$+o$[a$=+k$
##$k+=$a[$o+$_]eq$m;<<'';;;;''<<;m$qe]_$+o$[a$=+k$
##$k+=$a[$o+$_]eq$m;<<''''''''<<;m$qe]_$+o$[a$=+k$
##$k+=$a[$o+$_]eq$m;<<''''''''<<;m$qe]_$+o$[a$=+k$
##$k+=$a[$o+$_]eq$m;<<<<<<<<<<<<;m$qe]_$+o$[a$=+k$
##$k+=$a[$o+$_]eq$m;<<<<<<<<<<<<;m$qe]_$+o$[a$=+k$
##$k+=$a[$o+$_]eq$m;;;;;;;;;;;;;;m$qe]_$+o$[a$=+k$
##$k+=$a[$o+$_]eq$mmmmmmmmmmmmmmmm$qe]_$+o$[a$=+k$
##$k+=$a[$o+$_]eq$$$$$$$$$$$$$$$$$$qe]_$+o$[a$=+k$
##$k+=$a[$o+$_]eqqqqqqqqqqqqqqqqqqqqe]_$+o$[a$=+k$
##$k+=$a[$o+$_]eeeeeeeeeeeeeeeeeeeeee]_$+o$[a$=+k$
##$k+=$a[$o+$_]]]]]]]]]]]]]]]]]]]]]]]]_$+o$[a$=+k$
##$k+=$a[$o+$__________________________$+o$[a$=+k$
##$k+=$a[$o+$$$$$$$$$$$$$$$$$$$$$$$$$$$$+o$[a$=+k$
##$k+=$a[$o++++++++++++++++++++++++++++++o$[a$=+k$
##$k+=$a[$oooooooooooooooooooooooooooooooo$[a$=+k$
##$k+=$a[$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$[a$=+k$
##$k+=$a[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[a$=+k$
##$k+=$aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa$=+k$
##$k+=$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$=+k$
##$k+==========================================+k$
##$k++++++++++++++++++++++++++++++++++++++++++++k$
##$kkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkk$
##$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$

##}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}
##}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}
##}}$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$}}
##}}$nnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnn$}}
##}}$n++++++++++++++++++++++++++++++++++n$}}
##}}$n+================================+n$}}
##}}$n+=$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$=+n$}}
##}}$n+=$kkkkkkkkkkkkkkkkkkkkkkkkkkkk$=+n$}}
##}}$n+=$k==========================k$=+n$}}
##}}$n+=$k==========================k$=+n$}}
##}}$n+=$k==4444444444444444444444==k$=+n$}}
##}}$n+=$k==4********************4==k$=+n$}}
##}}$n+=$k==4*$$$$$$$$$$$$$$$$$$*4==k$=+n$}}
##}}$n+=$k==4*$ssssssssssssssss$*4==k$=+n$}}
##}}$n+=$k==4*$s;;;;;;;;;;;;;;s$*4==k$=+n$}}
##}}$n+=$k==4*$s;<<<<<<<<<<<<;s$*4==k$=+n$}}
##}}$n+=$k==4*$s;<<<<<<<<<<<<;s$*4==k$=+n$}}
##}}$n+=$k==4*$s;<<''''''''<<;s$*4==k$=+n$}}
##}}$n+=$k==4*$s;<<''''''''<<;s$*4==k$=+n$}}
##}}$n+=$k==4*$s;<<'';;;;''<<;s$*4==k$=+n$}}
  }}$n+=$k==4*$s;<<'';##;''<<;s$*4==k$=+n$}}
  }}$n+=$k==4*$s;<<'';##;''<<;s$*4==k$=+n$}}
##}}$n+=$k==4*$s;<<'';;;;''<<;s$*4==k$=+n$}}
##}}$n+=$k==4*$s;<<''''''''<<;s$*4==k$=+n$}}
##}}$n+=$k==4*$s;<<''''''''<<;s$*4==k$=+n$}}
##}}$n+=$k==4*$s;<<<<<<<<<<<<;s$*4==k$=+n$}}
##}}$n+=$k==4*$s;<<<<<<<<<<<<;s$*4==k$=+n$}}
##}}$n+=$k==4*$s;;;;;;;;;;;;;;s$*4==k$=+n$}}
##}}$n+=$k==4*$ssssssssssssssss$*4==k$=+n$}}
##}}$n+=$k==4*$$$$$$$$$$$$$$$$$$*4==k$=+n$}}
##}}$n+=$k==4********************4==k$=+n$}}
##}}$n+=$k==4444444444444444444444==k$=+n$}}
##}}$n+=$k==========================k$=+n$}}
##}}$n+=$k==========================k$=+n$}}
##}}$n+=$kkkkkkkkkkkkkkkkkkkkkkkkkkkk$=+n$}}
##}}$n+=$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$=+n$}}
##}}$n+================================+n$}}
##}}$n++++++++++++++++++++++++++++++++++n$}}
##}}$nnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnn$}}
##}}$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$}}
##}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}
##}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}

##}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}
##}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}
##}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}
##}}}pppppppppppppppppppppppppppp}}}
##}}}prrrrrrrrrrrrrrrrrrrrrrrrrrp}}}
##}}}priiiiiiiiiiiiiiiiiiiiiiiirp}}}
##}}}prinnnnnnnnnnnnnnnnnnnnnnirp}}}
##}}}printtttttttttttttttttttnirp}}}
##}}}print$$$$$$$$$$$$$$$$$$tnirp}}}
##}}}print$nnnnnnnnnnnnnnnn$tnirp}}}
##}}}print$n;;;;;;;;;;;;;;n$tnirp}}}
##}}}print$n;<<<<<<<<<<<<;n$tnirp}}}
##}}}print$n;<<<<<<<<<<<<;n$tnirp}}}
##}}}print$n;<<''''''''<<;n$tnirp}}}
##}}}print$n;<<''''''''<<;n$tnirp}}}
##}}}print$n;<<'';;;;''<<;n$tnirp}}}
  }}}print$n;<<'';##;''<<;n$tnirp}}}
  }}}print$n;<<'';##;''<<;n$tnirp}}}
##}}}print$n;<<'';;;;''<<;n$tnirp}}}
##}}}print$n;<<''''''''<<;n$tnirp}}}
##}}}print$n;<<''''''''<<;n$tnirp}}}
##}}}print$n;<<<<<<<<<<<<;n$tnirp}}}
##}}}print$n;<<<<<<<<<<<<;n$tnirp}}}
##}}}print$n;;;;;;;;;;;;;;n$tnirp}}}
##}}}print$nnnnnnnnnnnnnnnn$tnirp}}}
##}}}print$$$$$$$$$$$$$$$$$$tnirp}}}
##}}}printtttttttttttttttttttnirp}}}
##}}}prinnnnnnnnnnnnnnnnnnnnnnirp}}}
##}}}priiiiiiiiiiiiiiiiiiiiiiiirp}}}
##}}}prrrrrrrrrrrrrrrrrrrrrrrrrrp}}}
##}}}pppppppppppppppppppppppppppp}}}
##}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}
##}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}
##}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}

As you can see, every single character is part of a square. The top half of each big square is commented out by line comments, and the bottom half (including the second non-commented line) is escaped by a big here-document beginning in the middle of the square (<<'';#) and ending at the empty line after the big square.

This program was automatically generated from the following program:

($r,$c,@a)=@ARGV;
for$y(0..$r-1){
for$x(0..$c-1){
for$s(1..$c-$x-1){
$m=$a[$o=$c*$y+$x];$k=0;
for$t(1..$s){
for($t,$c*$t,$t+$c*$s,$c*$t+$s){
$k+=$a[$o+$_]eq$m;
}}$n+=$k==4*$s;
}}}print$n;

Which is a program to solve the same challenge, but (very lightly) golfed for bytes and short line lengths, not for score.

It takes as inputs first the height and width of the rectangle, then the individual characters of the rectangle separated by spaces. Example usage: To solve the rectangle

xxxyy
xxyyy
xyyxx

you call the program like this: perl theprogram.pl 3 5 x x x y y x x y y y x y y x x

Anyway, by squaring the code like this, it should be possible to get down to score 0 or 2 with any programming language that has a one-line solution and a line comment character, by transforming the one-liner

one-liner

like this:

##ooooooooooooooooooooo
##onnnnnnnnnnnnnnnnnnno
##oneeeeeeeeeeeeeeeeeno
##one---------------eno
##one-lllllllllllll-eno
##one-liiiiiiiiiiil-eno
##one-linnnnnnnnnil-eno
##one-lineeeeeeenil-eno
##one-linerrrrrenil-eno
##one-liner###renil-eno
  one-liner###renil-eno
##one-liner###renil-eno
##one-linerrrrrenil-eno
##one-lineeeeeeenil-eno
##one-linnnnnnnnnil-eno
##one-liiiiiiiiiiil-eno
##one-lllllllllllll-eno
##one---------------eno
##oneeeeeeeeeeeeeeeeeno
##onnnnnnnnnnnnnnnnnnno
##ooooooooooooooooooooo

The only characters not part of a square are the two spaces. Depending on the language, there may also be ways to use clever multiline strings or comments (like Perl's here-docs) or some sort of redundant code to make those two space characters into a square.

As for getting the byte count low, my solution has a bunch of immediate improvements, and I'm sure there are also lots of other ways to refine this technique, but I don't have the patience for that; I just wanted to provide a demonstration so you guys can go wild with it.

\$\endgroup\$
2
  • \$\begingroup\$ Kudos for getting the first 0 score answer! \$\endgroup\$
    – TCFP
    Sep 21, 2018 at 17:25
  • \$\begingroup\$ Welcome to PPCG! Nice answer. A TIO link would be a welcome addition. \$\endgroup\$ Sep 29, 2018 at 13:31
2
\$\begingroup\$

MATL, 18 16 14 10 characters not in squares (92 103 111 127 bytes)

!!!ffqqqqQQQ%OOOOGGGxx44---@@&&lllxxTT  ~~~ ++||7 ss--~~~ssvvss
!!!ffqqqqQQQ"OOOOGGGxx44---@@&&lllxxTTYa~~~Z++||7Mss--~~~ssvvss

Input is a character matrix with characters + and -. Doesn't count diagonal squares.

Try it online!

Or verify all examples and test cases.

\$\endgroup\$
2
  • \$\begingroup\$ I'm counting the newline as an out-of-square-character. Wating for OP clarification \$\endgroup\$
    – Luis Mendo
    Sep 21, 2018 at 6:28
  • \$\begingroup\$ Commented on the main thread, made the edit: newlines do not count toward your score :) \$\endgroup\$
    – TCFP
    Sep 21, 2018 at 13:59
2
\$\begingroup\$

Jelly,  20 1917 1908  1905 bytes, Score  20  0





ẆẆẆẆẆẆẆẆẆẆẆẆẆẆẆẆẆẆẆẆẆẆẆẆẆẆẆẆẆẆẆẆẆẆẆẆẆẆẆẆẆẆẆ
ẆZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZẆ
ẆZṡṡṡṡṡṡṡṡṡṡṡṡṡṡṡṡṡṡṡṡṡṡṡṡṡṡṡṡṡṡṡṡṡṡṡṡṡṡṡZẆ
ẆZṡLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLṡZẆ
ẆZṡLƊƊƊƊƊƊƊƊƊƊƊƊƊƊƊƊƊƊƊƊƊƊƊƊƊƊƊƊƊƊƊƊƊƊƊLṡZẆ
ẆZṡLƊ€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€ƊLṡZẆ
ẆZṡLƊ€ẎẎẎẎẎẎẎẎẎẎẎẎẎẎẎẎẎẎẎẎẎẎẎẎẎẎẎẎẎẎẎ€ƊLṡZẆ
ẆZṡLƊ€ẎṖṖṖṖṖṖṖṖṖṖṖṖṖṖṖṖṖṖṖṖṖṖṖṖṖṖṖṖṖẎ€ƊLṡZẆ
ẆZṡLƊ€ẎṖƇƇƇƇƇƇƇƇƇƇƇƇƇƇƇƇƇƇƇƇƇƇƇƇƇƇƇṖẎ€ƊLṡZẆ
ẆZṡLƊ€ẎṖƇZZZZZZZZZZZZZZZZZZZZZZZZZƇṖẎ€ƊLṡZẆ
ẆZṡLƊ€ẎṖƇZUUUUUUUUUUUUUUUUUUUUUUUZƇṖẎ€ƊLṡZẆ
ẆZṡLƊ€ẎṖƇZU$$$$$$$$$$$$$$$$$$$$$UZƇṖẎ€ƊLṡZẆ
ẆZṡLƊ€ẎṖƇZU$ƬƬƬƬƬƬƬƬƬƬƬƬƬƬƬƬƬƬƬ$UZƇṖẎ€ƊLṡZẆ
ẆZṡLƊ€ẎṖƇZU$ƬḢḢḢḢḢḢḢḢḢḢḢḢḢḢḢḢḢƬ$UZƇṖẎ€ƊLṡZẆ
ẆZṡLƊ€ẎṖƇZU$ƬḢ€€€€€€€€€€€€€€€ḢƬ$UZƇṖẎ€ƊLṡZẆ
ẆZṡLƊ€ẎṖƇZU$ƬḢ€ẎẎẎẎẎẎẎẎẎẎẎẎẎ€ḢƬ$UZƇṖẎ€ƊLṡZẆ
ẆZṡLƊ€ẎṖƇZU$ƬḢ€ẎEEEEEEEEEEEẎ€ḢƬ$UZƇṖẎ€ƊLṡZẆ
ẆZṡLƊ€ẎṖƇZU$ƬḢ€ẎEƲƲƲƲƲƲƲƲƲEẎ€ḢƬ$UZƇṖẎ€ƊLṡZẆ
ẆZṡLƊ€ẎṖƇZU$ƬḢ€ẎEƲ€€€€€€€ƲEẎ€ḢƬ$UZƇṖẎ€ƊLṡZẆ
ẆZṡLƊ€ẎṖƇZU$ƬḢ€ẎEƲ€SSSSS€ƲEẎ€ḢƬ$UZƇṖẎ€ƊLṡZẆ
ẆZṡLƊ€ẎṖƇZU$ƬḢ€ẎEƲ€SqqqS€ƲEẎ€ḢƬ$UZƇṖẎ€ƊLṡZẆ
ẆZṡLƊ€ẎṖƇZU$ƬḢ€ẎEƲ€SqqqS€ƲEẎ€ḢƬ$UZƇṖẎ€ƊLṡZẆ
ẆZṡLƊ€ẎṖƇZU$ƬḢ€ẎEƲ€SqqqS€ƲEẎ€ḢƬ$UZƇṖẎ€ƊLṡZẆ
ẆZṡLƊ€ẎṖƇZU$ƬḢ€ẎEƲ€SSSSS€ƲEẎ€ḢƬ$UZƇṖẎ€ƊLṡZẆ
ẆZṡLƊ€ẎṖƇZU$ƬḢ€ẎEƲ€€€€€€€ƲEẎ€ḢƬ$UZƇṖẎ€ƊLṡZẆ
ẆZṡLƊ€ẎṖƇZU$ƬḢ€ẎEƲƲƲƲƲƲƲƲƲEẎ€ḢƬ$UZƇṖẎ€ƊLṡZẆ
ẆZṡLƊ€ẎṖƇZU$ƬḢ€ẎEEEEEEEEEEEẎ€ḢƬ$UZƇṖẎ€ƊLṡZẆ
ẆZṡLƊ€ẎṖƇZU$ƬḢ€ẎẎẎẎẎẎẎẎẎẎẎẎẎ€ḢƬ$UZƇṖẎ€ƊLṡZẆ
ẆZṡLƊ€ẎṖƇZU$ƬḢ€€€€€€€€€€€€€€€ḢƬ$UZƇṖẎ€ƊLṡZẆ
ẆZṡLƊ€ẎṖƇZU$ƬḢḢḢḢḢḢḢḢḢḢḢḢḢḢḢḢḢƬ$UZƇṖẎ€ƊLṡZẆ
ẆZṡLƊ€ẎṖƇZU$ƬƬƬƬƬƬƬƬƬƬƬƬƬƬƬƬƬƬƬ$UZƇṖẎ€ƊLṡZẆ
ẆZṡLƊ€ẎṖƇZU$$$$$$$$$$$$$$$$$$$$$UZƇṖẎ€ƊLṡZẆ
ẆZṡLƊ€ẎṖƇZUUUUUUUUUUUUUUUUUUUUUUUZƇṖẎ€ƊLṡZẆ
ẆZṡLƊ€ẎṖƇZZZZZZZZZZZZZZZZZZZZZZZZZƇṖẎ€ƊLṡZẆ
ẆZṡLƊ€ẎṖƇƇƇƇƇƇƇƇƇƇƇƇƇƇƇƇƇƇƇƇƇƇƇƇƇƇƇṖẎ€ƊLṡZẆ
ẆZṡLƊ€ẎṖṖṖṖṖṖṖṖṖṖṖṖṖṖṖṖṖṖṖṖṖṖṖṖṖṖṖṖṖẎ€ƊLṡZẆ
ẆZṡLƊ€ẎẎẎẎẎẎẎẎẎẎẎẎẎẎẎẎẎẎẎẎẎẎẎẎẎẎẎẎẎẎẎ€ƊLṡZẆ
ẆZṡLƊ€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€ƊLṡZẆ
ẆZṡLƊƊƊƊƊƊƊƊƊƊƊƊƊƊƊƊƊƊƊƊƊƊƊƊƊƊƊƊƊƊƊƊƊƊƊLṡZẆ
ẆZṡLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLṡZẆ
ẆZṡṡṡṡṡṡṡṡṡṡṡṡṡṡṡṡṡṡṡṡṡṡṡṡṡṡṡṡṡṡṡṡṡṡṡṡṡṡṡZẆ
ẆZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZẆ
ẆẆẆẆẆẆẆẆẆẆẆẆẆẆẆẆẆẆẆẆẆẆẆẆẆẆẆẆẆẆẆẆẆẆẆẆẆẆẆẆẆẆẆ
⁽⁽ĿĿ
⁽⁽ĿĿ

A full program taking a list of lists of . and + characters. (Works for any characters, even more than 2).

Try it online!

Any attempt to reduce score by introducing characters seems to just increase the score more. I guess the way to win this challenge is to find the right Lenguage!

Since Magma posted a very nice Perl solution scoring \$0\$ I decided to attempt similar using my \$20\$ byte solution:

ẆZṡLƊ€ẎṖƇZU$ƬḢ€ẎEƲ€S

But Jelly has no comment character, so a little extra creativity is required...

Jelly programs consist of "Links" - code separated by newline characters, pilcrow characters ( - interpreted as the same byte as newlines) or valid code-page characters lacking a defined behaviour (at present q is an example). The latter actually count as a Link each rather than a pure separator. Program execution starts at the bottom-right most Link, the "Main Link" (here ⁽⁽ĿĿ).

We can call any other Link as a single-argument function (a "monad") by it's \$1\$-indexed position in the rest of the Links of the program using the "quick" Ŀ. These Links are indexable in a modular fashion; so if there are \$n\$ of them then the \$n^\text{th}\$ is the same as the \$0^\text{th}\$ and the \$-m^\text{th}\$ is the same as the \$(-m\mod n)^\text{th}\$.

So the program above starts by executing ⁽⁽ĿĿ, where ⁽⁽Ŀ is a representation of \$-27150\$ so ⁽⁽ĿĿ calls the \$-27150^\text{th}\$ Link which, since there are \$60\$ Links (due to the extra lines and the central nine qs), is the \$30 ^\text{th}\$ Link, ẆZṡLƊ€ẎṖƇZU$ƬḢ€ẎEƲ€S, to the left of the middle row of the \$3\$-by-\$3\$ square of qs. This is called with an argument of the program input:

ẆZṡLƊ€ẎṖƇZU$ƬḢ€ẎEƲ€S - Link: list of lists of characters, lines
Ẇ                    - contiguous slices (i.e [[line1], [line2], ..., [lineN], [line1, line2], [line2, line3], ..., [lineN-1, lineN], [line1, line2, line3], ...., [lineN-2, lineN-1, lineN], ..., ..., lines])
     €               - for each (slice):
    Ɗ                -   last three links as a monad:
 Z                   -     transpose - i.e. get the columns of the slice
   L                 -     length - i.e. get the number of lines in the slice
  ṡ                  -     overlapping slices of given length - i.e. get slices of columns of same length as lines in the original slice ...filled squares of all sizes (including 1-by-1)
      Ẏ              - tighten - from a list of list of squares of each size to a single list of all squares
        Ƈ            - filter keep if this is truthy:
       Ṗ             -   pop (truthy for all but the 1-by-1 squares)
                  €  - for each (filled square)
                 Ʋ   -   last four links as a monad:
            Ƭ        -     collect up until results are no longer unique:
           $         -       last two links as a monad:
         Z           -         transpose  }
          U          -         upend      } - together a quarter rotation
             Ḣ€      -     head each - i.e. first row of each rotation
               Ẏ     -     tighten - i.e. get the entire perimeter (with repeated corners)
                E    -     all equal? (1 if so, 0 otherwise)
                   S - sum
\$\endgroup\$
6
  • \$\begingroup\$ I don't think this actually has a score of 0 since is really just a proxy for a newline. The program really looks more like this \$\endgroup\$
    – dylnan
    Sep 29, 2018 at 23:46
  • \$\begingroup\$ @dylnan - the OP talks about characters, not bytes - but the 9 s could be replaced with 9 qs or (s or whatever anyway (like I've said in the blurb). \$\endgroup\$ Sep 29, 2018 at 23:52
  • \$\begingroup\$ ...hmm doesn't seem to work with q like I thought it would :/ \$\endgroup\$ Sep 30, 2018 at 0:05
  • \$\begingroup\$ Changing the character changes which line ⁽⁽ĿĿ evaluates \$\endgroup\$
    – dylnan
    Sep 30, 2018 at 0:07
  • 1
    \$\begingroup\$ Woah, nice I didn't expect that to happen. <s>Is that because q is an unused byte? It works with u too which is also unused.</s> nevermind \$\endgroup\$
    – dylnan
    Sep 30, 2018 at 1:38

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.