Skip to main content
Changed to Peano curve because Hilbert was already done
Source Link

Draw a HilbertPeano Curve with Slashes

Given a positive integer N, draw the Nth iteration of the Hilbert CurvePeano Curve, using only slashes and backslashes (and spaces). The curve will be rotated at a 45 degree angle from its usual depiction. Here's an example for the first 43 iterations:

 /\
/ /
 / /
 \/
       /\
      / /
     / / /\
    /  \/ /
   / /\  / /\
   \/ /  \/ /
 /\  / /\  / /\
/ / / / / / / /
 / / / / / / / /
 \/ /  \/ /  \/
   / /\  / /\
   \/ /  \/ /
     / /\  /
     \/ / /
       / /
       \/
                         /\
                        /\ /
    /                   / / /\
    \                  /\ \ \/ /
  /\  /                 / /
 \  / /\
                     \/ /  \/\ /
 \ \                 /\  / /\  / /\
\                  / / / / / / /\ /
                 /\ / / / \/ / / / /\
  \   \           /\  \/
  /  \/\ /  \/ /
               / /\/
  / /\  / /\  / /\
      \/

N = 4

         \/ /  \/ /  \/ /  \/ /
             /\  / /\  / /\  / /\  / /\
            /\ / / / /  \/ / / / / / / /
           / / / / / /\  / / / / / / / /\
          /  \/ /  \/ /  \/ /  \/ /  \/ /
         / /\  / /\  / /\  / /\  / /\  / /\
         \/ /  \/ /  \/ /  \/ /  \/ /
   \/ /
       /\  / /\  / /\  / /\  / /\  / /\  / /\
      / /  \/ / / / / / / /  \/ / / / / / / / 
     / / /\  / / / / / / / /\  / / / / / / / /\
    /  \/ /  \/ /  \/ /  \/ /  \/ /  \/ /  \/ /
   / /\  / /\  / /\  / /\  / /\  / /\  / /\  / /\
   \/ /  \/ /  \/ /  \/ /  \/ /  \/ /  \/ /  \/ /
 /\  / /\  / /\  / /\
   / /\  / /\  / /\  / /\  / /\
/ / / / / / / / / / / / / / / / / / / / / / / / / /
 / / / / / / / / / / / / / / / / / / / / / / / / / /
 \/ /  \/ /  \/ /  \/ /  \/ /  \/ /  \/ /  \/ /  \/
   / /\  / /\ \ \/ \/\  / /\  / /\  / /\  / /\  / /\
   \/ /  \/ /  \/ /  \/ /  \/ /  \/ /  \/ /  \/ /
     / /\  / /\  / /\  / /\  / /\  / /\  / /\  /
     \/ / / / / / / /  \/ / / / / / / /  \/ / /
  \     / / / / / / / /\  / / / / / / / /\  / / 
       \/ /  \/ /  \/ /  \/ /  \/ /  \/ /  \/  
         / /\  / /\  / /\  / /\ \ / /\  / /\    
    \     \/ /  \/\ /  \/ /  \/ /  \/ /  \/ /    
           / /\  / /\  / /\  / /\  / /\  /     
           \/ / / / / / / /  \/ / / / / /      
             / / / / / / / /\  / / / / /       
             \/ /  \/ /  \/ /  \/ /  \/        
       \ \       / /\  / /\  / /\  / /\          
               \/ /  \/ /  \/ /  \/ /         
                 / /\  / /\  \/ /\  /
                 \/ / / / / / / / /
                   / / / / / / / /
                   \/ /  \/ /  \/
           \          / /\  / /\
                     \/ /  \/ /
                       / /\  /
                       \/ / /
                         / /
                         \/

Draw a Hilbert Curve with Slashes

Given a positive integer N, draw the Nth iteration of the Hilbert Curve, using only slashes and backslashes (and spaces). The curve will be rotated at a 45 degree angle from its usual depiction. Here's an example for the first 4 iterations:

 \
\/
  /
  \/\
/\   \
 / /\/
 \ \
  \/
       \
     /\/
    /   /\
    \/\ \ \
  /\  / / /
  / /  \/  \/\
 \ \/\  /\   \
\/   / / / /\/
  /\/ /  \ \
  \   \/\ \/
    \/\   \
     / /\/
     \ \
      \/

N = 4

              /
              \/\
            /\   \
           / / /\/
           \ \ \  /\
         /\/  \/  \ \
        /   /\  /\/ /
         \/\ \ \ \   \/\
      /\  / /  \ \/\   \
     / /  \/ /\/   / /\/
     \ \/\  /   /\/ /   /\
   /\/   /  \/\ \   \/\ \ \
   /   /\/ /\  / / /\  / / /
  \/\ \  / /  \/ / /  \/  \/\
/\   \ \ \ \/\   \ \/\  /\   \
 / /\/  \/   / /\/   / / / /\/
 \ \  /\  /\/  \  /\/ /  \ \
  \/  \ \ \  /\/  \   \/\ \/
    /\/ / / /   /\ \/\   \
    \   \/  \/\ \ \  / /\/
     \/\  /\  / / /  \ \
       / / /  \/  \/\ \/
       \ \ \/\  /\   \
        \/   / / / /\/
          /\/ /  \ \
          \   \/\ \/
           \/\   \
             / /\/
             \ \
              \/

Draw a Peano Curve with Slashes

Given a positive integer N, draw the Nth iteration of the Peano Curve, using only slashes and backslashes (and spaces). The curve will be rotated at a 45 degree angle from its usual depiction. Here's an example for the first 3 iterations:

 /\
/ /
 / /
 \/
       /\
      / /
     / / /\
    /  \/ /
   / /\  / /\
   \/ /  \/ /
 /\  / /\  / /\
/ / / / / / / /
 / / / / / / / /
 \/ /  \/ /  \/
   / /\  / /\
   \/ /  \/ /
     / /\  /
     \/ / /
       / /
       \/
                         /\
                        / /
                       / / /\
                      /  \/ /
                     / /\  / /\
                     \/ /  \/ /
                   /\  / /\  / /\
                  / / / / / / / /
                 / / / / / / / / /\
                /  \/ /  \/ /  \/ /
               / /\  / /\  / /\  / /\
               \/ /  \/ /  \/ /  \/ /
             /\  / /\  / /\  / /\  / /\
            / / / / /  \/ / / / / / / /
           / / / / / /\  / / / / / / / /\
          /  \/ /  \/ /  \/ /  \/ /  \/ /
         / /\  / /\  / /\  / /\  / /\  / /\
         \/ /  \/ /  \/ /  \/ /  \/ /  \/ /
       /\  / /\  / /\  / /\  / /\  / /\  / /\
      / /  \/ / / / / / / /  \/ / / / / / / / 
     / / /\  / / / / / / / /\  / / / / / / / /\
    /  \/ /  \/ /  \/ /  \/ /  \/ /  \/ /  \/ /
   / /\  / /\  / /\  / /\  / /\  / /\  / /\  / /\
   \/ /  \/ /  \/ /  \/ /  \/ /  \/ /  \/ /  \/ /
 /\  / /\  / /\  / /\  / /\  / /\  / /\  / /\  / /\
/ / / / / / / / / / / / / / / / / / / / / / / / / /
 / / / / / / / / / / / / / / / / / / / / / / / / / /
 \/ /  \/ /  \/ /  \/ /  \/ /  \/ /  \/ /  \/ /  \/
   / /\  / /\  / /\  / /\  / /\  / /\  / /\  / /\
   \/ /  \/ /  \/ /  \/ /  \/ /  \/ /  \/ /  \/ /
     / /\  / /\  / /\  / /\  / /\  / /\  / /\  /
     \/ / / / / / / /  \/ / / / / / / /  \/ / /
       / / / / / / / /\  / / / / / / / /\  / / 
       \/ /  \/ /  \/ /  \/ /  \/ /  \/ /  \/  
         / /\  / /\  / /\  / /\  / /\  / /\    
         \/ /  \/ /  \/ /  \/ /  \/ /  \/ /    
           / /\  / /\  / /\  / /\  / /\  /     
           \/ / / / / / / /  \/ / / / / /      
             / / / / / / / /\  / / / / /       
             \/ /  \/ /  \/ /  \/ /  \/        
               / /\  / /\  / /\  / /\          
               \/ /  \/ /  \/ /  \/ /         
                 / /\  / /\  / /\  /
                 \/ / / / / / / / /
                   / / / / / / / /
                   \/ /  \/ /  \/
                     / /\  / /\
                     \/ /  \/ /
                       / /\  /
                       \/ / /
                         / /
                         \/
Source Link

Draw a Hilbert Curve with Slashes

Given a positive integer N, draw the Nth iteration of the Hilbert Curve, using only slashes and backslashes (and spaces). The curve will be rotated at a 45 degree angle from its usual depiction. Here's an example for the first 4 iterations:

N = 1

 \
\/

N = 2

  /
  \/\
/\   \
 / /\/
 \ \
  \/

N = 3

       \
     /\/
    /   /\
    \/\ \ \
  /\  / / /
 / /  \/  \/\
 \ \/\  /\   \
\/   / / / /\/
  /\/ /  \ \
  \   \/\ \/
   \/\   \
     / /\/
     \ \
      \/

N = 4

              /
              \/\
            /\   \
           / / /\/
           \ \ \  /\
         /\/  \/  \ \
        /   /\  /\/ /
        \/\ \ \ \   \/\
      /\  / /  \ \/\   \
     / /  \/ /\/   / /\/
     \ \/\  /   /\/ /   /\
   /\/   /  \/\ \   \/\ \ \
  /   /\/ /\  / / /\  / / /
  \/\ \  / /  \/ / /  \/  \/\
/\   \ \ \ \/\   \ \/\  /\   \
 / /\/  \/   / /\/   / / / /\/
 \ \  /\  /\/  \  /\/ /  \ \
  \/  \ \ \  /\/  \   \/\ \/
    /\/ / / /   /\ \/\   \
    \   \/  \/\ \ \  / /\/
     \/\  /\  / / /  \ \
       / / /  \/  \/\ \/
       \ \ \/\  /\   \
        \/   / / / /\/
          /\/ /  \ \
          \   \/\ \/
           \/\   \
             / /\/
             \ \
              \/

You may optionally mirror this horizontally, vertically, or both if you choose. Leading spaces are clearly required for this. Trailing spaces are optional. This is code-golf, so the shortest code wins.