[Question]
  [
[Befunge](https://esolangs.org/wiki/Funge-98) is a 2-dimensional programming language, with an instruction pointer (IP).
In Befunge-98, the `;` character tells the IP to skip characters up until the next `;` (Let us call it skipping mode when the IP is skipping characters). Here is an example:
```
"This part is read into the stack" ; this part is not ; @
```
I would like to generate a `w` wide, `h` high comment outline for a Befunge-98 program. This means that an IP in normal mode (not in string mode nor in skipping mode) should enter the comment, skip over the comment and then exit in normal mode, no matter which row or column it arrives from. Additionally, the outline must be at most one character thick. That is, the bounding box of the entire comment (including outline) must be no more than `w+2` wide and no more than `h+2` high.
## Example
If `w = 5, h = 3` then a valid comment outline would be:
```
;;;;;;
;     ;
;     ;
;     ;
 ;;;;;;
```
Note that this would not be a valid comment outline:
```
;;;;;;;
;     ;
;     ;
;     ;
;;;;;;;
```
This is because in the first column, the IP would enter in normal mode, but exit in skipping mode, potentially skipping crucial code. (The same thing would happen in the 7th column, 1st row and 5th row)
This is not valid either:
```
       
       
       
       
       
```
This would result in the comment being interpreted as code.
## Challenge
Write a program or function that, given a width and height as input, outputs any valid Befunge-98 comment outline for that size. The width and height are guaranteed to be at least 1.
* You must output in spaces, semicolons and line breaks, unless your chosen programming language is unable to
* You may have trailing whitespace, however they can only be spaces and line breaks
* Each line may have trailing spaces
* You may alternatively take input as `w+2` and `h+2` instead of `w` and `h`
	+ You may also mix between the two e.g. you can input `w+2` and `h`
* As stated above, the width of the outline must be at most 1
* There must be a `w` by `h` area inside the outline made of only spaces
## More examples
`w = 2, h = 2`
```
;;;;
;  ;
;  ;
;;;;
```
`w = 3, h = 2`
```
 ;;;;
;   ;
;   ;
 ;;;;
```
`w = 2, h = 3`
```
 ;;
;  ;
;  ;
;  ;
;;;;
```
`w = 5, h = 1`
```
;;;;;;
;     ;
 ;;;;;;
```
  
[Answer]
# [Python](https://www.python.org), ~~93~~ ~~89~~ ~~85~~ ~~79~~ ~~74~~ 73 bytes
```
lambda w,h:';'*(w|1)+(';\n;'+' '*w)*h+';\n'+h%2*' '+';'*(w+~h%2+~(w^h)%2)
```
[Attempt This Online!](https://ato.pxeger.com/run?1=m72soLIkIz9vweI025ilpSVpuhY3PXMSc5NSEhXKdTKs1K3VtTTKaww1tTXUrWPyrNW11RXUtco1tTK0QXx17QxVIy2gkDZEoXYdkK9dp1Eel6GpaqQJMfAWo2RicXFqUYlCmoaRjpGmXnFJUWaBhqaCra1CDJeSkhKXNRBwWSsowAgQFygOU8jFhaTfmAj9IELB2loBhyHGeB2hACetcRthitMdUENgxiDTClB5JCMhIbRgAYQGAA)
-7 bytes thanks to [Arnauld](https://codegolf.stackexchange.com/users/58563/arnauld) and [bsoelch](https://codegolf.stackexchange.com/users/118682/bsoelch).
The last row is built from four parts:
1. a space if the height is odd
2. `w` semicolons
3. one additional semicolon if `h` is even
4. one additional semicolon if `w` and `h` have the same evenness.
[Answer]
# [Jelly](https://github.com/DennisMitchell/jelly), ~~23~~ 19 [bytes](https://github.com/DennisMitchell/jelly/wiki/Code-page)
```
aþ¬So1;Ʋ€ZṚƊ4¡ị⁾; Y
```
A dyadic Link that accepts \$w\$ on the left and \$h\$ on the right and yields a list of characters (or a full program that prints the result).
**[Try it online!](https://tio.run/##AS0A0v9qZWxsef//YcO@wqxTbzE7xrLigqxa4bmaxoo0wqHhu4vigb47IFn///81/zQ "Jelly – Try It Online")** Or see the [test-suite](https://tio.run/##y0rNyan8/z/x8L5Da4LzDa2PbXrUtCbq4c5Zx7pMDi18uLv7UeM@a4XI/2YPd043Ojrp4c4ZOoeX60eClWUB5Q5tO7TtPwA "Jelly – Try It Online").
### How?
```
aþ¬So1;Ʋ€ZṚƊ4¡ị⁾; Y - Link: integer, W; integer, H
 þ                  - [1..W] table [1..H] with:
a                   -   logical AND
  ¬                 - logical NOT
                       -> W×H zeros
             ¡      - repeat...
            4       - ...times: four
           Ɗ        - ...action: last three links as a monad:
        €           -              for each Row:
       Ʋ            -                last four links as a monad:
   S                -                sum {Row}
     1              -                one
    o               -                {sum} logical OR {one}
      ;             -                {that} concatenate {Row}
         Z          -              transpose }
          Ṛ         -              reverse   } - rotate a quarter
              ị⁾;   - index into "; " (1-based and modular)
                  Y - join with newline characters
```
[Answer]
# [Charcoal](https://github.com/somebody1234/Charcoal), ~~22~~ 21 bytes
```
Ｆ⁴«§; ⁺ι⁺ⅈⅉ×;Ｉ§⟦θη⟧ι↷
```
[Try it online!](https://tio.run/##S85ILErOT8z5/z8tv0hBw0RToZqLM6AoM69Ew7HEMy8ltUJDyVpBSUchIKe0WCMTSkdoaOooRGpoAoE1THlIZm5qMVAxUK1zYjFCe3ShjkJGrI5CJkx1Zll@SVBmekaJBpBb@/@/sYLxf92yHAA "Charcoal – Try It Online") Link is to verbose version of code. Explanation:
```
Ｆ⁴«
```
Loop over the four sides of the rectangle.
```
§; ⁺ι⁺ⅈⅉ
```
Output a space if the sum of the previous dimensions is odd but a semicolon if it is even.
```
×;Ｉ§⟦θη⟧ι
```
Output the appropriate number of semicolons.
```
↷
```
Pivot 90° so that the next iteration draws the next side of the rectangle.
(Would have saved 4 bytes to input the width and height as a tuple instead of separate values.)
[Answer]
# [Rust](https://www.rust-lang.org), ~~109~~ ~~100~~ ~~129~~ ~~120~~ ~~113~~ ~~112~~ 108 bytes
-4 bytes thanks to @corvus\_192
Is this what people mean when they say Rust's syntax is unreadable?
```
|w,h|{let r=str::repeat;r(";",w|1)+&r(&(r(";\n;",1)+&r(" ",w)),h)+";\n"+&r(" ",h%2)+&r(";",w+!h%2+!(w^h)%2)}
```
[Attempt This Online!](https://ato.pxeger.com/run?1=tZJRasMwDIbZq0-hGlqsxlupS2HE9BR7TD0Iw1kCXVYcZ4GlOcle8rAdajvNlLgj3QH6EkW_fumTwB-frq58_3PjshJe0qIUyFo4WA8Z7NhqyU6NzE9c8ztnjzb1ojmtMVoIrvflJA4Sh8mD-PebYzRY-b96PldDw0V_NM7FQGsHvNtV3sVxMGhHQC4D24mFcOcFZBBotiSonGhBC6DQnCRNpGRjJMW1VsYkzVyZhCwGu2uCGzpuQXa1FDM6M0dKiLhcfdU-u73_PlyVPaM0Iu5jjqR3Z2avGRuA3lb-Ka1sFUMi6qp4t3L8ot4a2JGmpEIJFDZD2IRsSxuMYYOGBmWvDgTdgFCU00RoGYwP6S091DaGB--K8pmGZqNXU_VIip8J3o6Wbl_SFVToGDvv2fch_gI)
At the end of the program, I have to calculate the number of semicolons to output for the last line. This forms a decision tree that can be visualized in the following table:
| w | h | result |
| --- | --- | --- |
| odd | odd | w + 1 |
| odd | even | w + 1 |
| even | odd | w |
| even | even | w + 2 |
First, I used an actual array and indexing with `n%2` to get the result, but this takes too many characters.
~~I have now converged to `w+(w&1)+2*(!(w|h)&1)` (first taking `w`, adding `1` if `w` is odd and then adding 2 if both `w` and `h` are even), but this can't be optimal.~~
~~I have now converged to `w+(!h&1)+(!(w^h)&1)` (first taking `w`, adding `1` if `h` is even and then again adding 1 the parity of `w` and `h` is equal, but that also can't be optimal. Just look at the amount of parens!~~
`w+!h%2+!(w^h)%2` seems to be the best option. Completely forgot about precedence whoops
[Answer]
# [J](https://www.jsoftware.com), 53 53 41 36 35 31 30 26 24 bytes
```
'; '{~1=3|+/&(3,$&5,2&|)
```
[Attempt This Online!](https://ato.pxeger.com/run?1=m70wa8FNVUtFK8NYM0UrS3V1LiU99TQFWysFdQUdBQMFKyDW1VNwDvJxW1pakqZrsUPdWkG9us7Q1rhGW19Nw1hHRc1Ux0itRhMifdNJkys1OSNfwUQhTcEYzASaCRYxBoqYYIiYooiAdJlATFqwAEIDAA)
Finally found a decent approach based on an addition table of the appropriate lists. Say our `m rows x n cols` input is `1 x 3`, which represents the dimensions of the inner box.
We construct lists for each dimension of an addition table as follows:
```
going down:
Initial number 
is always 3, followed
by m 5s, followed by....
v
3 
5 
1     <-- Final number is 1
          since m = 1 is odd.
          Otherwise would be 0.
              
going across:
3 followed by n=3 fives
v
3 5 5 5 1 <-- Final number is
              is 1 again, since n=3 
              is odd
```
Let's see what happens when we make a addition table:
```
  | 3  5  5  5  1
--+--------------
3 | 6  8  8  8  4
5 | 8 10 10 10  6
1 | 4  6  6  6  2
```
Next we mod by 3, and check if the result is 1, which it will be only for cells that should be a space:
```
0 0 0 0 1
0 1 1 1 0
1 0 0 0 0
```
And finally convert to spaces/semicolons:
```
;;;;
;   ;
 ;;;;
```
This procedure gives the correct result for all 4 possible even/odd combos.
[Answer]
# [05AB1E](https://github.com/Adriandmen/05AB1E/wiki/Commands), 29 [bytes](https://github.com/Adriandmen/05AB1E/wiki/Codepage)
```
«';Ž9¦S.ΛIÉ©нi¨}®θið®OÉǝ}®Oi¦
```
Can definitely be golfed by using a different approach..
Input as pair \$[w+2,h+2]\$.
[Try it online](https://tio.run/##ATwAw/9vc2FiaWX//8KrJzvFvTnCplMuzptJw4nCqdC9acKofcKuzrhpw7DCrk/DicedfcKuT2nCpv//WzcsNV0) or [verify all test cases](https://tio.run/##S0oszvifnFiiYKeQnJ@SqpdfnJiUmapgY6Pg6u/GpeSZV1BaYqWgZK/DpeRfWgLh6Pw/tFrd@uhey0PLgvXOzfY83Hlo5YW9mYdW1B5ad25H5uENh9b5H@48PhfI9c88tOx/rc6hbfZcIPO4yjMyc1IVilITUxQy87hS8rkUFPTzC0r0IdZCKTSX2CiogNXmpf6PNtExieWKNgWTJjqmYDaQBAA).
**Explanation:**
Step 1: Create a \$w+2\$ by \$h+2\$ box of `;`, filled with spaces:
```
«         # Merge the (implicit) input-pair to itself: [w+2,h+2,w+2,h+2]
 ';      '# Push character ";"
   Ž9¦    # Push compressed integer 2460
      S   # Convert it to a list of digits [2,4,6,0]
       .Λ # Use the (modifiable) Canvas builtin with these three arguments
```
[Try just step 1 online.](https://tio.run/##yy9OTMpM/f//0Gp166N7LQ8tC9Y7N/v//2hzHdNYAA)
Step 2: Do the following actions based on whether the \$w\$ and \$h\$ are odd:
| \$h\$=even,\$w\$=even | \$h\$=even,\$w\$=odd | \$h\$=odd,\$w\$=even | \$h\$=odd,\$w\$=odd |
| --- | --- | --- | --- |
| Do nothing | Insert a space at index 1;Remove the first character*†* | Remove the first character*†*Remove the last character | Insert a space at index 0;Remove the last character |
*†*: Removing the first character of the multiline string basically empties the top-right corner.
Combining those actions, we have the following three things to do:
| Remove the first character*†* | Remove the last character | Insert a space at index \$((w+h)=odd)\$ |
| --- | --- | --- |
| If \$w+h\$=odd | If \$w\$=odd | If \$h\$=odd |
Which translates to the following code:
```
I         # Push the input-pair again
 É        # Check for both whether they're odd (1 if odd; 0 if even)
  ©       # Store this pair in variable `®` (without popping)
   н      # Pop and push the first item
    i }   # If w is odd:
     ¨    #  Remove the last character of the box
®         # Push pair `®` again
 θ        # Pop and push its last item
  i     } # If h is odd:
   ð      #  Push a space character " "
    ®O    #  Push the sum of pair `®`
      É   #  Check if this sum is odd
       ǝ  #  Insert the space at that (0-based) index
®O        #  Push the sum of pair `®` yet again
  i       # If this sum is 1 (so either w or h is odd, and the other is even):
   ¦      #  Remove the first character of the box†
          # (after which the result is output implicitly)
```
[See this 05AB1E tip of mine to understand how the Canvas builtin `Λ` works.](https://codegolf.stackexchange.com/a/175520/52210)  
[See this 05AB1E tip of mine (section *How to compress large integers?*)](https://codegolf.stackexchange.com/a/166851/52210) to understand why `Ž9¦` is `2460`.
[Answer]
# [Ruby](https://www.ruby-lang.org/), 66 bytes
```
->w,h{(a="; "*w*h)[w+h]+?;*w+a[h]+"
;#{' '*w};"*h+"
"+a[w]+?;*-~w}
```
[Try it online!](https://tio.run/##KypNqvyfZvtf165cJ6NaI9FWyVpBSatcK0Mzulw7I1bb3lqrXDsxGshS4rJWrlZXUNcqr7VW0soA8pWAEuVgJbp15bX/uQqKMvNKFNL0khNzcjSMdIw0gWq4lNCFjbEJG@MSxm6IAU7lBppc/wE "Ruby – Try It Online")
We use "; " repeated (`w` \* `h`) times to get the character at the corners (by indexing) without using reminder operations.
The character at the top left corner is `;` if both or none of `w` and `h` are odd so we add them together, that's why we need a loooong "; ; ; ..." string
[Answer]
# [JavaScript (Node.js)](https://nodejs.org), 96 bytes
```
f=(x,y,h=y++,w=x++)=>~x?f(x-1,y,h,w)+' ;'[(Y=y>h|!y)^(x>w|!x)|Y&!x*h+!y*w+1]:y?f(w,y-1,h)+`
`:''
```
[Try it online!](https://tio.run/##fcvdCoIwFADg@55iu2mbZwbqnTF7DukHxbQV4iKjnQPSqy@7C6KuP75L/ajH5na@3uPBHdsQOiNRk7aGALQ3CKBM8cRNJzFO3qC9AsHWYitLQ4WdOKmDxMJPHNVULjlGFjhFHpJ9TnPzmuZoFVSLKhciNG4YXd@ueneSnUw1SxUDJnaDUIsvy35Z9udlny@8AA "JavaScript (Node.js) – Try It Online")
[Answer]
# [sed](https://www.gnu.org/software/sed/) `-E`, 158 bytes
Input is taken as `51` for w=5 and h=1. The first line adds a cheat sheet to teach `sed` counting down (of course you'd need some extra bytes for comments larger than 9) and produces the solution for w=1/h=1. Then the `w` loop adds two `;` and one  while counting down the first field. The `h` loop duplicates a line with a whitespace while counting down the second field. The next-to-last line adds a semicolon for a odd number of them. Not very slim, but probably the best to achieve with `sed`.
```
s/$/987654321\n;;\n; ;\n;;\n/
:w
s/^(.)(..*\1(\S).*;;)(.* )(.*;)/\3\2;\4 \5;/
tw
:h
s/^.(.)(.*\1(\S).*)(\n.* ;)/-\3\2\4\4/
th
s/(\n(;;)+)(;\n)/\1;\3/g
s/.*1//
```
[Try it online!](https://tio.run/##PY09DsIwDEZ3n6IDQxLUWE5SfuqZE7BaTKDCkiKlqLcnOCAx2LLl9z6X27Wf8qvWghs8Hva7IcVAkpm1Ov4NCOMKBS/GW@O9EzJytt4x6@q61tiiRAksqZOBEZYVxntT/Nf5K9ZIVkXxvvGSJCncSD0YDdxaow81jVgiTnrwjhBrJYIQIESIAQZ6z8/lMedS@9MH "sed – Try It Online")
]