# All credits to Adnan for coming up with this challenge.

My last challenge, before I go on break.

Given positive integer n, if n is odd, repeat / that many times; if n is even, repeat \ that many times.

(Seriously, the testcases would be much clearer than this description, so just look at the testcases.)

# Testcases

n output
1 /
2 \\
3 ///
4 \\\\
5 /////
6 \\\\\\


# Python 3, 43 Bytes

n=int(input())
a='\\'*n
if n%2:a='/'*n
print(a)


In python the \ symbol is also used as an operator when inside a string (e.g: \n means newline) so \\ has to be used to get the backslash symbol.

This code works by assuming the input (n) is odd, and then checks if it is even. If so, then it redefines the variable a (the output) before displaying it.

This is shorter than using an if-else statement by 5 bytes as it does the checking after defining the variable, meaning that the else command is not needed.

• You could save bytes by changing to Python2, since int(input()) could be changed to input() and print wouldn't need parentheses. Also, there's an unnecessary whitespace in n%2: . – Yytsi Aug 31 '16 at 12:12
• Also, you may hook the character from a string (selecting n%2-th) character, but that would end up being the same answer as @xnor has. It's a nice trick for the future! – Yytsi Aug 31 '16 at 12:16
• Indeed, '\/'[n%2]*n is pretty much as short as it can be. – SylvainD Sep 1 '16 at 9:58
• Thanks for the tips, I'll bear them in mind for next time – sonrad10 Sep 1 '16 at 11:25

## ><>, 15 + 3 = 18 bytes

\/:l2-),:2%0go:


+3 bytes for the -v flag to initialise the stack with the input. Try it online!

><> is a toroidal 2D language, so the following runs in a loop:

\/          Mirrors that reflect the instruction pointer. Since the code is
one row high, the reflection wraps and the IP ends up moving in the
same direction anyway, so these are no-ops.

:l2-)       Push (input > length of stack - 1) - note that the actual subtraction
is by 2 to account for the fact that we duplicated an element with :

,           Divide the input by the above. If (input == length of stack - 1),
then the program errors out due to division by 0. Otherwise, the
input is unchanged.

:2%0g       Push the char at (input % 2, 0), which will be one of the two slashes
at the beginning of the code

o           Output this char

:           Duplicate the input, increasing the length of the stack by 1


## PHP, 63 52 bytes

Version 1 - 63 bytes

$i=$argv[1];$x=($i%2?"/":"\\");echo sprintf("%'".$x.$i."s",$x);  Version 2 - 52 bytes Thanks to manatwork for saving 11 bytes $i=$argv[1];$x=$i%2?"/":"\\";printf("%'$x{$i}s",$x);


Run with php -f squiggle.php <number>

https://repl.it/DFdi/2 (remember to change the input on repl)

• No need for parenthesis around the ternary expression. Why using sprintf() to return a value just to echo it and not directly printf() it? And is shorter to use variable expansion than concatenating the format string: "%'$x{$i}s". – manatwork Sep 2 '16 at 13:28
• @manatwork thanks for the great tips! I've modified my answer. – ʰᵈˑ Sep 2 '16 at 13:38

## Bash + coreutils, 29 28 bytes

yes $1_45r2%*92+P|sed$1q|dc


yes $[92-$1%2*45]P|sed $1q|dc  In the new script I just transferred the calculation of the ASCII code from bash to dc entirely. • @LeakyNun I was used with the Bash and pure Bash terms until I started here. I updated my answer. – seshoumara Aug 31 '16 at 14:39 # Husk, 6 bytes R¹!"/¦  Try it online! -4 bytes from Zgarb. ¦ is an alias for \ in a string. # Husk, 10 bytes *⁰;!⁰"/\\"  Try it online! ## Explanation *⁰;!⁰"/\\" !⁰"/\\" get element at index n in string "/\" (wraps around) ; create singleton list from it *⁰ repeat list n times  # Forth (gforth), 55 bytes : b 1- dup for dup 2 mod if 92 else 47 then emit next ;  Try it online! called as <number> b. # S.I.L.O.S, 55 bytes readIO c=i c%2 c*45 c-92 c| lbla printChar c i-1 if i a  Try it online! Port of this answer in C. ## Haskell, 32 bytes f n=replicate n$"\\/"!!(mod n 2)

• replicate n x can be replaced by [1..n]>>[x] or x<$[1..n] (with GHC 7.10). You can find other haskell tricks here: codegolf.stackexchange.com/questions/19255/… – Damien Aug 31 '16 at 6:14 # RETURN, 21 bytes [$2÷%'/'\2øø4ø2␂{␋},]


Try it here.

Anonymous lambda. Usage:

5[$2÷%'/'\2øø4ø2␂{␋},]!  # Explanation [ ] [lambda]%$2÷%                   [copy input and mod 2]%
'/'\2øø            [choose either / or \ depending on input mod 2]%
4ø          [get input again]%
2␂{      [copy the /\ char and the input into a new stack]%
␋},   [repeat the stack by the input and output the stack]%


# Bash, 63 bytes

q(){ seq -s0 0 $1|cut -c-$1|tr 0-9 $(($1%2))|sed 'y/10/\/\\/';}

• Weird. If you know the tr command, then why used sed for the 2nd transliteration? – manatwork Aug 31 '16 at 7:05
• Move your code outside of the function and drop the q(){} part. Also, you can drop both tr and sed conversions by doing something like this: c=(\\ /);seq -s${c[$1%2]} 0 $1|tr -d [0-9]. For an even shorter way see my answer – seshoumara Aug 31 '16 at 14:29 # Rust, 210 190 Bytes fn main(){let x:usize=std::env::args().nth(1).unwrap().parse::<usize>().unwrap();let l:&str=match x%2{0=>"\\",1=>"/",_=>"",};println!("{}",std::iter::repeat(l).take(x).collect::<String>());}  Ungolfed: fn main() { let x : usize = std::env::args().nth(1) .unwrap() .parse::<usize>() .unwrap(); let l : &str = match x % 2 { 0 => "\\", 1 => "/", _ => "", }; println!("{}", std::iter::repeat(l).take(x) .collect::<String>()); }  I don't usually golf (so I bet this isn't a great score, at least for Rust), but I figured this would be good Rust practice. This compiles into an executable run as squiggly.exe x where x is the number of times to repeat the character. • Cut off 20 bytes by realizing that direct referencing (std::env::args(), std::iter::repeat(l)) is more effective than use clauses – MutantOctopus Sep 1 '16 at 15:36 # awk, 26 bytes NF=$1,$1=OFS=$1%2?"/":"\\"


\$1 is the input and then part of the output

NF is the number of fields

OFS is the output field separator

It prints if the expression before the comma is truthy.

# Acc!!, 90 bytes

N
Count i while _%60-10 {
_*10+_%60*50-2880+N
}
_/60
Count j while _-j {
Write 92-_%2*45
}


Try it online!

# Read a line of stdin, convert it to a decimal number, and store it in the accumulator
N
Count i while _%60-10 {
_*10+_%60*50-2880+N
}
_/60
# Loop that many times
Count j while _-j {
# Output \ if accumulator mod 2 is 0, or / if it is 1
Write 92-_%2*45
}

• Acc!! is a really fun language! – null Aug 13 '20 at 3:39

# x86-16 machine code, PC DOS, 18 bytes

Binary:

00000000: a082 002c 30a8 0191 b85c 0a74 02b0 2fcd  ...,0....\.t../.
00000010: 10c3                                     ..


Listing:

A0 0082     MOV  AL, BYTE PTR[82H]  ; first char of command line into AL
2C 30       SUB  AL, '0'            ; ASCII convert input char
A8 01       TEST AL, 1              ; set ZF if even
91          XCHG AX, CX             ; CL = number of times to repeat
B8 0A5C     MOV  AX, 0A5CH          ; AL = '\', AH = 0AH (BIOS write char)
74 02       JZ   WRITE              ; if even, write with a '\'
B0 2F       MOV  AL, '/'            ; otherwise change to a '/'
WRITE:
CD 10       INT  10H                ; write AL to console CX number of times


Standalone PC DOS executable (COM) program. Input n on command line (note: this is limited to single digit values).

# Forth, 58 54 bytes

Leaves n%2 as junk on the stack. Output is sent to stdout. 47 is /, and 92 is \. Computes y=92-45*x, where x is n%2 and emits (outputs) the character with that codepoint.

: f dup 2 mod swap 0 DO dup 92 swap 45 * - emit LOOP ;


Try it online

# Lua (33 44 Bytes)

Never tried golfing with Lua before.

Shortest program I could come up with:

n=io.read()print(({'\\','/'})[n%2+1]:rep(n))

• Your code should handle either input or parameter. – manatwork Sep 2 '16 at 13:31

# PL-SQL (Oracle), 530 characters

DECLARE
-- Enter your input here, here example is taken as 3 ---
n number := 3 ;
k varchar2(20);
BEGIN
-- Checking the input number for odd --
if mod(n,2)=1 then
for j in 1..n loop
k := k||'/';
end loop;
DBMS_OUTPUT.PUT_line (n||' '||k);
end if;

-- Checking the input number for even --
if mod(n,2)=0 then
for j in 1..n loop
k := k||'\';
end loop;
DBMS_OUTPUT.PUT_line (n||' '||k);
end if;
END;

• Language name?. – acrolith Sep 2 '16 at 21:43
• Welcome to PPCG! Please put what language this is and the length in bytes at the top of your post. Also, remove as many extraneous characters as possible, including whitespace. Posters must make a serious effort to golf (shorten) their code for [code-golf] questions. – mbomb007 Sep 2 '16 at 21:43

# MAWP, 38 bytes

%@!!2P2WA{~[67W5M;1A].}~[99W25W1MM;1A]


Made using Dion's modulus function from here.

Try it!

# Japt, 7 bytes

çUg"\\/


Try it

# Pyth, 5 bytes

*@"\/


Try it online!

*@"\/
@("\/", Q) * Q  // After implicit input is read and re-structured to appear more readable.
@("\/", Q)      // Get element at index Q(input)
@("\/", Q) * Q  // Repeat Q times.


# 05AB1E, 7 5 bytes

-2 bytes thanks to @Neil.

„\/è×


Try it online!

     è   # 0-based index...
# implicit input...
è   # implicit mod 2 in...
„\/     # "\/"
×  # repeat implicit input times
# implicit output

• è is a) modular, so you don't need É, and b) commutative, so you don't need s. – Neil Nov 22 '20 at 16:44