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


Javascript, 22 bytes

n=>"\\/"[n%2].repeat(n)


Defines an anonymous function.

If only * repeated strings in Javascript. sighs

• Finally you have found the right operator Aug 30, 2016 at 23:21
• @LeakyNun What are you talking about? Aug 30, 2016 at 23:22
• You were using the ternary operator to choose the character, no? Aug 30, 2016 at 23:22
• @LeakyNun Initially, yes, but if you look at chat, I also posted this about a minute later. Aug 30, 2016 at 23:23
• @Jordumus You could either assign the function to a variable: f=n=>..., you could directly call it: (n=>...)(5). (Or if you are using the Node.js REPL, then you could use this._, which stands for the last thing entered) Sep 1, 2016 at 14:22

Python, 20 bytes

lambda n:'\/'[n%2]*n

• Great, simple and elegant ^_^ Sep 2, 2016 at 13:19

05AB1E/2sable, 15119 8 bytes

DÈ„/\sè×


-2 bytes thanks to Leaky Nun

-1 byte thanks to Emigna

• ftfy Aug 31, 2016 at 0:21
• It says sè× 😮 Aug 31, 2016 at 4:56
• "/\" can be „/\ Aug 31, 2016 at 7:06
• You can remove the leading D for -1 byte in both languages, since input is implicit. You can also save an additional byte in 05AB1E (legacy) by changing È„/\ to „\/, since indexing is modular. (PS: in the new version of 05AB1E it's even 1 byte less by removing the s, but there is already an answer for that.) Apr 26, 2023 at 9:36

Perl, 20 bytes

Includes +1 for -p

Run with input on STDIN:

squigly.pl <<< 6


squigly.pl

#!/usr/bin/perl -p
T/\\^(..)+$ Try it online (First line added to allow multiple testcases to be run). C#, 42 bytes string f(int n)=>new string("\\/"[n%2],n);  Selects the correct character, then creates a new string consisting of that character repeated n times. PHP, 38 bytes for(;$i++<$a=$argv[1];)echo'\/'[$a%2];  (variant 38 bytes) while($i++<$a=$argv[1])echo'\/'[$a%2];  (variant 38 bytes) <?=str_pad('',$a=$argv[1],'\/'[$a%2]);


(variant 40 bytes)

<?=str_repeat('\/'[($a=$argv[1])%2],$a);  C, 40 bytes i;f(n){for(i=n;i--;)putchar(n%2?47:92);}  Try it on Ideone • putchar(92-n%2*45) is the same length. Sep 2, 2016 at 13:46 Jelly, 5 bytes ị⁾/\x  ị⁾/\x ị⁾/\ modular-indexing into the string "/\" x repeat  • Although I suspect this challenge may have something to do with it existing, it's worth noting that Ø^ is a byte shorter than ⁾/\ . Oct 15, 2019 at 3:16 Haskell, 25 bytes f n=cycle"\\/"!!n<$[1..n]


-1 byte thanks to Damien with cycle.

• f n=cycle"\\/"!!n<$[1..n] Aug 31, 2016 at 6:20 • @Damien Wow, how did I forget cycle. – xnor Aug 31, 2016 at 6:22 • I don't know. But I'm glad to have had the opportunity to "beat" you once :) Aug 31, 2016 at 6:31 Mathematica, 3432 28 bytes If[OddQ@#,"/","\\"]~Table~#&  Anonymous function. Takes an integer as input and returns a list of characters as output. • You can use ~Table~#. Aug 31, 2016 at 6:37 • I think it was added in 10.2. Aug 31, 2016 at 10:09 • Also, I think you can ditch the <>"" and return a list of characters. Aug 31, 2016 at 10:11 • @MartinEnder They must have also added ~Do~Infinity and such in 10.2+ as well... Aug 31, 2016 at 11:35 Mathematica, 29 bytes "\\"["/"][[#~Mod~2]]~Table~#&  Cruelly exploits the fact that [[1]] returns the first argument of a function while [[0]] returns the function (head) itself, applied to the strangely valid function named "\\" which is being "evaluated" at "/". • It's slightly less weird when you consider that something of the form a[b] is just a generic expression with head a (index 0) and element b (index 1), and functions are just special kinds of expression (actually, it would be more correct to say that functions aren't expressions at all, but are simply rules for transforming expressions which usually have form f[x...]). :) Aug 31, 2016 at 10:16 • I've seen many languages abused on this site, but I think this is the first abuse of Mathematica that I've seen. Good job! Aug 31, 2016 at 13:43 Powershell, 30 27 bytes Update: param($n)('\','/')[$n%2]*$n


Switching to param, thanks to timmyd.

"$("\/"[$args[0]%2])"*$args[0]  or slightly more readable ("\","/")[$args[0]%2]*$args[0]  Test: > 1..10 | % { ./run.ps1$_ }
/
\\
///
\\\\
/////
\\\\\\
///////
\\\\\\\\
/////////
\\\\\\\\\\

• Welcome to PPCG! Nice to see another PowerShell user around here. You can shave a few bytes by taking input as param($n) instead of $args, like follows for 27 bytes -- param($n)('\','/')[$n%2]*$n Aug 31, 2016 at 12:29 Ruby, 15 bytes ->n{'\/'[n%2]*n}  See it on eval.in: https://eval.in/632030 Fourier, 27 bytes 92~SI~N%2{1}{47~S}N(Sai^~i)  Try it online! Brachylog, 15 bytes :2%:"\/"rm:?jbw  Try it online! Explanation :2% Input mod 2… :"\/"rm …is the index of the element in string "\/",… :?j …element that we juxtapose Input times to itself… bw …and print to STDOUT after removing one slash/backslash  CJam, 9 bytes ri_"\/"=*  Try it online! Explanation ri e# Read input and convert to integer N. _ e# Duplicate N. "\/"= e# Use N as cyclic index into "\/", giving '\ for even and '/ for odd inputs. * e# Repeat N times.  ><> (Fish), 30 Bytes :2%?'/'o1-:?!;30. 30. >'\'50p  First time using this language, but I think I at least saved a little room by conditionally using the / as either part of the output or a mirror to redirect flow. Probably still horribly inefficient though, I feel like it could probably be cut down a little more at the very least. Input is the initial stack, output is stdout Try it online! • Welcome to Programming Puzzles & Code Golf! Sep 1, 2016 at 3:22 • @Dennis Thanks! I appreciate the welcome. Sep 1, 2016 at 4:28 Dyalog APL, 11 bytes Requires ⎕IO←0 which is default on many systems. ⊢⍴'\/'⊃⍨2|⊢  ⊢ the argument ⍴ reshapes (repeats) '\/'⊃⍨ the string "/" selected by 2|⊢ the division remainder when the argument is divided by two TryAPL online! • Cool! Very similar to J. Aug 31, 2016 at 0:04 • @ConorO'Brien Yes, the only difference is that 2-trains in J are hooks, while they are atops in Dyalog, so an explicit left tine is needed. – Adám Aug 31, 2016 at 0:13 • Ah, I was wondering why the argument was there. Aug 31, 2016 at 0:31 • Finally an APL answer with all characters rendered correctly for me! Aug 31, 2016 at 15:21 • @Cyoce Yeah, I wish we could specify (and embed) fonts on SE. – Adám Aug 31, 2016 at 15:44 Java 11, 6865 29 bytes n->(n%2<1?"\\":"/").repeat(n)  -3 bytes saved thanks to @user902383 and @SeanBean -36 bytes switching from Java 7 to Java 11+ Try it online. Explanation: n-> // Method with integer parameter and String return-type (n%2<1? // If n is even: "\\" // Use String "\" : // Else (n is odd): "/") // Use String "/" instead .repeat(n) // Repeat it n amount of times  • Hi Kevin. Why not a Lambda Expression? – Vale Aug 31, 2016 at 8:45 • @Vale Hi Vale. Because I'm an old-fashion Java 7 programmer. :) If you have a Java 8 or 9 answer that is slightly different than my answer, feel free to post it. Aug 31, 2016 at 8:58 • @Vale (he's odd like that :P) Aug 31, 2016 at 9:24 • i think if you change x=-1;++x<i to x=0;x++<i you can reduce by one byte Aug 31, 2016 at 10:00 • Also you can replace "\\" : "/" with 92:'/' ;) Aug 31, 2016 at 10:24 Julia, 20 bytes !x="$("/\\"[x%2])"^x


R, 47 46 bytes

n=scan();cat(rep(c("\\","/")[n%%2+1],n),sep="")


In R, you have to escape backslashes. the argument sep also has to be fully specified since it comes after .... Thus annoyingly few opportunities to save chars :(

Thanks to bouncyball for golfing away a byte.

• Save one byte by using indexing: n=scan();cat(rep(c('\\','/')[n%%2+1],n),sep='') Aug 31, 2016 at 20:54

T-SQL 50 bytes

Of course no STDIN here, so let's assume a hardcoded INT variable like this: DECLARE @ INT then the solution is:

PRINT IIF(@%2=0,REPLICATE('\',@),REPLICATE('/',@))


Pip, 8 bytes

"\/"@aXa


Straightforward. Uses modular indexing to select the character and string repetition to multiply it. Try it online!

This question presents an interesting comparison between Pip, Pyth, and Jelly, the latter two each having scored 5 bytes. All three languages have implicit output, with single-char operators for modular indexing and string repetition, and no requirement to escape backslashes in strings. There are two key differences, though:

1. Under certain circumstances, Pyth and Jelly need only one delimiter to define a string;
2. Pyth and Jelly have syntax such that the input doesn't need to be explicitly represented in the code (though for very different reasons, as Maltysen explained to me).

Neither one of these features is likely to show up in Pip1 (I don't like the aesthetics of unbalanced delimiters, and point-free syntax or implicit operands seem like they would be too alien to my infix expression parser), but I'm okay with playing third fiddle. Even though "readability" is extremely relative when golfing, I'd argue that those three extra bytes make the Pip program a lot easier to understand at a glance--and in my book, that's a worthwhile tradeoff.

1 Although, single-character strings in Pip use a single ' delimiter, inspired by CJam and by quoting in Lisp.

• I'm not sure that readability is a plus, in code golf? Not at the cost of bytes ! Aug 31, 2016 at 11:02
• @GreenAsJade I expect a lot of people feel the same. I would just make one distinction: code golf != golflang design. Now you may well argue that the same principle (shorter is always better) applies to language design too. I'm just saying that for me, usability and even aesthetics are considerations. Aug 31, 2016 at 15:59
• Pro tip for making a golfing language: don't use infix Aug 31, 2016 at 22:50
• Sep 1, 2016 at 0:52
• pyth doesn't have implicit point free syntax. it works pretty much the same way it does in python, making it readable yet short. your comment about the unbalanced delimiters on the other hand is pretty true Sep 2, 2016 at 4:26

Psithurism, 11 bytes

*(%2?"/:"\)


This is a language I'm still developing, but I'm going to start posting answers here to get a feeling of what kind of built-in functions might be useful to have. (This one has taught me I really need some way to index into arrays/strings lol.)

explained:

*(        # implicitly multiply the input by
%2      # implicitly take input mod 2
? "/  # / if truthy (1)
: "\  # \ if falsy (0)
)


Github: https://github.com/AroLeaf/psithurism/
Docs (soon™): https://psithurism.leaf.moe/

• I don't think it's non-competing since we dropped the rule that languages have to be older than the challenge. May 2, 2023 at 15:59
• @TheThonnu oh that's nice, thanks! I do assume that implementing a feature to improve your score is still non-competing?
– Leaf
May 2, 2023 at 16:03
• If you make the feature just for that challenge, yeah it's non-competing, but if you make a feature which generally improves the language, and improves your score as a side effect, then that's fine. May 2, 2023 at 16:09
• @TheThonnu alright, thanks for clarifying
– Leaf
May 2, 2023 at 16:09
• So for your example adding indexing would be fine in my opinion, because it's a useful feature for many challenges. Related loophole on Meta if you want more info. May 2, 2023 at 16:12

Pyth, 5 bytes

*@"\/


Test suite.

Modular-indexing into the string \/ and then repeat.

• You're FGITW'ing your own challenge?
– xnor
Aug 30, 2016 at 23:44
• @xnor it isn't exactly my challenge. Aug 30, 2016 at 23:49

Perl 6, 16 bytes

{<\ />[$_%2]x$_}


Usage:

for 1..6 {
say $_, {<\ />[$_%2]x$_}($_ )
}

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


SpecBAS - 28 bytes

1 INPUT n: ?"\/"(ODD(n)+1)*n


ODD returns 1 if number is odd, then uses that as an index to print the correct character n number of times. Have to add 1 as SpecBAS strings start at character 1.

Java 8, 56 bytes

(i,j)->{for(j=i;j-->0;)System.out.print(i%2<1?92:'/');};


I'd like to thank @Kevin Cruijssen in advanced for golfing my answer further.

Ungolfed Test Program

public static void main(String[] args) {
BiConsumer<Integer, Integer> consumer = (i, j) -> {
for (j = i; j-- > 0;) {
System.out.print(i % 2 < 1 ? 92 : '/');
}
};

consumer.accept(5, 0);
consumer.accept(1, 0);
consumer.accept(8, 0);
}
`