g | x | w | all
Bytes Lang Time Link
035AWK241106T150315Zxrs
006K ngn/k240315T144745Zcoltim
007Perl 5 + p240315T131019ZDom Hast
038Swift 5.9240315T121711ZmacOSist
009Juby240315T005428ZJordan
006Uiua SBCS240315T001402Zchunes
011J230429T015624Zsouth
063Scala230429T011656Z138 Aspe
003Japt m230403T161214ZShaggy
nan230401T094715ZThe Thon
019Regex PCRE2220814T220536ZDeadcode
004MATL220814T174504ZLuis Men
070Rust220322T200858ZSylveste
001Vyxal220322T154140ZSeggan
003Vim220318T221336ZPablocha
007Gema220318T170350Zmanatwor
021Python 3220318T162927ZEphraimR
055///220318T161112ZSpitemas
019Charcoal220315T233856Zjixperso
014R220318T123639ZMerijn v
022brainfuck220318T092902Zl4m2
030R220316T165020ZDominic
013Octave220317T154032ZTom Carp
006Husk220316T155314ZDominic
00105AB1E220316T082821ZKevin Cr
018Ruby220316T193652ZAZTECCO
028Haskell220316T153142Zlynn
032Haskell220316T120027ZAZTECCO
001Vyxal220315T225403Zlyxal
057Elisp + s.el220316T010641Zjixperso
031Python 3220315T220016Zloopy wa
025JavaScript V8220315T230755ZMatthew
004Jelly220315T221804ZJonathan
060Batch220315T224722ZNeil
008Charcoal220315T224226ZNeil
003Pip220315T224035ZDLosc
006Retina 0.8.2220315T223744ZNeil
033C tcc220315T222836Zovs
025Factor + pairrocket220315T223504Zchunes
032APL+WIN220315T222312ZGraham
013Pyth220315T221219Zsinvec
068Lua220315T214932Ztwentysi
008sed220315T210625Zuser3604
012Bash + coreutils220315T212855ZDigital

AWK, 35 bytes

gsub(/ /,1)gsub(/#/," ")gsub(1,"#")

Try it online!

There has to be a way to regex this better.

K (ngn/k), 7 6 bytes

-1 byte from @algorithmshark

"# "2!

Try it online!

Perl 5 + -p, 7 bytes

y; #;# 

Try it online!

Explanation

Uses the transliteration syntax (y///) but using the implicit ; from -p (-n: while (<STDIN>) {...;}).

Swift 5.9, 38 bytes

let f={($0+[]).map{($0+[]).map{1-$0}}}

f(_:)'s type is ([[Int]]) -> [[Int]]. The two "characters" are 1 and 0.

J-uby, 9 bytes

Uses A and a (or any letter and its swapped-case counterpart) as the “pixels.”

:swapcase

Attempt This Online!

Uiua SBCS, 6 bytes

⍜(⊛♭)¬

Try it!

What it does is flatten the input, convert it to binary , logical not ¬ it, unbinary it back to characters, then assume the original shape. Under is the modifier that handles all the function inverses.

Or, using Jordan's method,

Uiua SBCS, 1 byte

¯

Just swapcase, but unlike the first answer the letters used must be lower/upper case of the same letter.

Try it!

J, 11 bytes

'# '{~'#'&=

Attempt This Online!

'# '{~'#'&=
      '#'&=  NB. vectorized equality check, returns boolean matrix
    {~       NB. index into
'# '         NB. inverted char list

Scala, 63 bytes

Golfed version. Try it online!

def f(s:String)=s.map(c=>if(c=='#')' 'else if(c==' ')'#'else c)

Ungolfed version. Try it online!

def f(s: String): String = s.map {
  case '#' => ' '
  case ' ' => '#'
  case c   => c
}

Japt -m, 3 bytes

I/O as an array of binary strings.

mèT

Try it

Thunno, \$ 2 \log_{256}(96) \approx \$ 1.65 bytes

ZX

Attempt This Online! or see it with # and

Port of Seggan's Vyxal answer. Uses a and A as the two characters.

Thunno N, \$ 10 \log_{256}(96) \approx \$ 8.23 bytes

A\Ziedi1_J

Attempt This Online! or see it with # and

Uses 0 and 1 as the two characters.

Explanation

ZX  # Implicit input
ZX  # Swap case of input
    # Implicit output
A\Ziedi1_J  # Implicit input
A\          # Push a newline
  Zi        # Split the input on newlines
    e       # Map over this list:
     di     #  Convert each character to an integer
       1_   #  Subtract each from one
         J  #  Join the resulting list
            # N flag joins on newlines
            # Implicit output

Regex (PCRE2), 19 bytes

s/(#)| /${1:+ :#}/g

Try it online!
Try it on regex101!

This is a single regex substitution, to be applied once.

In this explanation, indicates a space:

s/         # Match the following:
    (#)    # \1 = match one "#"
|          # or
    ␣      # match one space
/          # Replace with the following:
${1:+␣:#}  # If \1 is set, replace with a space, else replace with "#"
/g         # Enable Global replacement flag

Regex (Boost), 15 bytes

s/(#)| /?1 :#/g

Try it online!

MATL, 4 bytes

5\Zc

Input is a char matrix containing and #.

Try it online!

How it works

     % Implicit input
5\   % Modulo 5 of (codepoints) of the input chars. This gives 2 for space, 0 for '#'
Zc   % Convert nonzeros to '#' and zeros to char(0)
     % Implicit display. char(0) is displayed as a space

Rust, 70 bytes

|s:&str|->String{s.replace("#","?").replace(" ","#").replace("?"," ")}

This replaces all occurrences of # with ?, replaces all with #, and then all ? with . It's quite an effective algorithm.

Try it online!

Vyxal, 1 byte

N

Try it Online!

A different Vyxal solution. Expects uppercase letters for # and lowercase letters for or vice versa. N is the swap case element. The header and footer converts the test case format into the format that the program expects and vice versa.

Vim, 3 bytes

VG~

Your output characters must be the same as your input characters (e.g. ["#"," "] -> [" ","#"]), which you are free to choose (but must be printable characters)

We will use the upper case and lower case version of any alphabetic character.

Explanation

  1. V: Select the whole line
  2. G: Go to the end of the document
  3. ~: Swap case of the characters

Try it online! (Using: ["q","Q"] -> ["Q","q"])
Try it online! (Adding some replaces to fit the caracters in the examples)

Gema, 7 characters

%=.;.=%

For this version choose the % and . characters.

Try it online!

Gema, 10 characters

\#=\ ;\ =#

This uses the original # and characters. Unfortunately this needs escaping because

Try it online!

Python 3, 21 bytes

lambda s:s.swapcase()

Takes a multiline string consisting of a for spaces and A for #'s and outputs the string after swapping the case of each letter. Not quite as nice-looking (or interesting) as loopy walt's wonderful answer, but I'm happy to finally write an answer to one of these :)

Try it online!

///, 55 bytes

/
 /
> //
#/
>#// #/ >#//# /#> //>#/->//> /#>//-/ //>//

Man, the underscore on the /// link looks bad. Ah, well.

Basically, we first put a cursor (>) before every run of hashes or spaces, then flip each character after a >. We need to use an intermediate character (-) to avoid flipping things twice.

Try it online!

Charcoal, 19 bytes

WS«Fι«≡κ ¦#¦ »M±Lι¹

Try it online!

R, 14 bytes

-5 bytes by l4m2, using 1-m instead of abs(m-1) and +11 for providing the required function call.

function(m)1-m

Try it online!

I do personally dislike the freedom of I/O in this challenge and allowing any other input characters than " " and "#". I learned something new from Dominic van Essen's answer actually as I was never aware of that function. But bending the rules to make life easier, nevertheless my answer. Input a 0-1 matrix and just reverse the values.

brainfuck, 28 22 bytes

,[-------[->+++<]>+.,]

Try it online!

Switch *(42) and j(106). Long to make \n(10) same

R, 38 30 bytes

Or 23 bytes by exchanging function for \ using R≥4.1: Attempt This Online!

function(x)chartr("# "," #",x)

Try it online!

Octave, 13 bytes

@(x)['' 67-x]

Try it online!

Takes the input as an array of '# ' characters.

The sum of '#' and ' ' is 67, so all we need to do is subtract the input string from 67 and it will "negate" the characters.

Unfortunately we then have to spend a few bytes forcing the output back to being a character array rather than an integer, but ho hum.

Husk, 6 bytes

†?_aD¶

Try it online!

Input & output as single multiline string; 'pixels' are 'A' and 'a' (or any other pair of uppercase & lowercase letters).

Split on newlines (), then, for each () character, if (?) it's uppercase (D) convert to lowercase (_), otherwise convert to uppercase (a).

If input is already list of strings, we can drop the for 5 bytes. If input is a list of integers (1 and zero) we can have 2 bytes.

05AB1E, 1 byte

Each line is a separated potential program:

_
≠
È

I/O as a matrix of 1s and 0s.

Try it online or verify all test cases.

Using the actual # and spaces as I/O, it would be 5 bytes instead:

„# ‡

I/O as multiline strings with #s/spaces and potential newlines.

Try it online or verify all test cases.

Explanation:

      # Transform each 1 to 0 and each 0 to 1 in the (implicit) input-matrix,
_     #  using an ==0 check
≠     #  or !=1 check
È     #  or %2==0 (is_even) check
      # (after which the modified matrix is output implicitly)

„#    # Push string "# "
   Â  # Bifurcate it, short for Duplicate & Reverse copy
    ‡ # Transliterate all "#" to " " and vice-versa in the (implicit) input
      # (after which the modified string is output implicitly)

Ruby, 18 bytes

->s{s.tr"# "," #"}

Try it online!

I suggested this to fix a Ruby answer but disappeared..

Haskell, 28 bytes

map g
g ' '='#'
g c=min ' 'c

Try it online!

Acts on a string with newlines in it.

By the same rules-lawyering as this Pip answer I guess map$map(1-) is a valid answer, but I don't really like it.

Haskell, 32 bytes

f l=[[x|c<-s,x<-"# ",x/=c]|s<-l]

Try it online!

Takes and returns a list of String

Vyxal, 1 byte

Try it Online!

Same method as DLosc's 3 byte Pip answer. Takes a list of lists of either 0 or 1.

Simply computes 1 - n for each digit. Alternatively,

Vyxal, 3 bytes

₀S*

Try it Online!

Takes a multiline string of 0s and 1s. The flag, header and footer are for allowing the test cases to be directly pasted in without having to change them.

Explained

₀S*
₀S  # The string "10"
  * # Ring translate the input according to that - change 0 to 1, 1 to 0 and leave newlines as they are. 

Elisp + s.el, 57 bytes

(s-replace"-""#"(s-replace"#"" "(s-replace" ""-"(read))))

enter image description here

Python 3, 31 bytes

lambda s:s.translate(9*"# \n ")

Try it online!

How

The 9*"# \n " is a string that has a "\n" at position 10 which matches its own code point, and at positions 32 and 35 it has copies of "#" and " " so these two are at each other's code point. str.translate uses this string as a lookup table replacing each character of s by the value associated with its code point. It will leave newlines in place and swap hashes and spaces.

JavaScript (V8), 25 bytes

s=>s.replace(/./g,i=>i^1)

Try it online!

Takes input as string of 0's, 1's, and newlines.

Explanation:

s => s.replace(
  /./g,       // '.' matches anything but newline, ie. 0 or 1 only.
              // 'g' marks regex as global, to replace everything
  i => i ^ 1  // JavaScript's aggressive type casting forces '0' or '1' string into a number
              // boolean XOR (^) with 1 transforms 0 -> 1 and 1 -> 0
)

Jelly, 4 bytes

O^1Ọ

A monadic Link that accepts a list of lists of characters (from and !) and yields a list of lists of characters with these characters swapped.

Try it online!

How?

O^1Ọ - Link: list of lists of characters
O    - ordinal (vectorises)   : ' ' -> 32  and '!' -> 33
  1  - one                    : 1
 ^   - XOR (vectorises)       : 32  -> 33  and 33  -> 32
   Ọ - character (vectorises) : 33  -> '!' and 32  -> ' '

If integers are allowed in place of characters as I/O then the one byte Link ¬ would suffice (vectorising loginal NOT).

Batch, 60 bytes

@set/ps=
@set s=%s: =$%
@set s=%s:#= %
@echo(%s:$=#%
@%0

Swaps spaces with #s. Doesn't work well with file input as it needs to be interrupted with Ctrl+C to exit. Explanation:

@set/ps=

Read in the next line.

@set s=%s: =$%

Replace the spaces with $s.

@set s=%s:#= %

Replace the #s with spaces.

@echo(%s:$=#%

Replace the $s with #s and output the result.

@%0

Rinse and repeat.

Charcoal, 8 bytes

WS⟦⭆ι¬Σκ

Try it online! Link is to verbose version of code. Takes input as a list of newline-terminated strings of 0s and 1s. Explanation:

WS

While there are more strings in the input...

⟦⭆ι¬Σκ

... logically invert each character's decimal value and output the result on its own line.

Pip, 3 bytes

1-_

Maybe this is too cheaty?

The solution is a function that takes and returns a list of lists of 0s and 1s. Attempt This Online!

Explanation: subtract each number from 1.


Here's a 6-byte version that's on much safer ground rules-wise. It's also a function, and it also uses 0 and 1, but it takes and returns a multiline string:

_TRt01

Attempt This Online!

Explanation: Transliterate the characters in 10 (the t builtin) to the characters in 01.

Retina 0.8.2, 6 bytes

T`10`d

Try it online! Swaps 0 with 1 but link is to test suite that converts from # to 01 and back. Explanation: d is shorthand for 0-9 or 0123456789 so this translates 1 to 0 and 0 to 1 (the extra target characters are ignored).

C (tcc), 33 bytes

Function that modifies its input.

f(char*s){*s^=1^*s%3;*++s&&f(s);}

Try it online!

Factor + pair-rocket, 25 bytes

[ "# "=> " #"substitute ]

Try it online!

APL+WIN, 32 bytes

Prompts for m x n matrix

n←(⍴m←⎕)⍴' '⋄((,m=' ')/,n)←'#'⋄n

Try it online! Thanks to Dyalog APL Classic

Pyth, 13 bytes

L:::bdN\#dN\#

Try it online!

Lua, 68 bytes

a=io.read('*a')b,d=a.gsub,' 'print((b(b(b(a,'#','!'),d,'#'),'!',d)))

Attempt This Online!

lol

sed, 23 8 bytes

-15 bytes thanks to Digital Trauma

y/# / #/

Try it online!

Bash + coreutils, 12

tr '# ' ' #'

Try it online!