# 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.)

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

## 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

# RETURN, 21 bytes

[$2÷%'/'\2øø4ø2␂{␋},] Try it here. Anonymous lambda. Usage: 5[$2÷%'/'\2øø4ø2␂{␋},]!

# Explanation

[                    ]  [lambda]%

# 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

## ><>, 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

# 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.

# 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:

• 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