# Antiferromagnetic ordering

Antiferromagnetism is what IBM researchers used to jump from a 1 terabyte disk to a 100 terabyte disk in the same amount of atoms.

In materials that exhibit antiferromagnetism, the magnetic moments of atoms or molecules, usually related to the spins of electrons, align in a regular pattern with neighboring spins (on different sublattices) pointing in opposite directions.

Your job is to write a program that draws the ordering of antiferromagnetic atoms like the picture shown above. You must be able to have at least four sets of pairs, though you may have more.

Each pair must be shown as follows, though they must be actual arrows:

 up  down
down  up
up  down


Your output can be in ascii art or graphical output.

You can make only a function or a whole program, but it must take an input and draw that many pairs. Examples with only words:

Input: 1

 up  down
down  up
up  down


Input: 2

 up  down  up  down
down  up  down  up
up  down  up  down


Acceptable arrows:

• ↑ and ↓
• ⇅ and ⇵
• /|\ and \|/

• "Any arrows" sounds pretty ambiguous to me - what about ^v? – Sp3000 Jul 10 '15 at 7:27
• @Sp3000 No, cause they don't have the little tails. – phase Jul 10 '15 at 7:30
• Are these arrows allowed: ⇅ and ⇵? (unicode code points U+21C5 and U+21F5) – Digital Trauma Jul 10 '15 at 16:28
• @DigitalTrauma They are perfect! – phase Jul 10 '15 at 16:29
• @Phase I rolled back your edit. Changing the scoring from bytes to chars will significantly change scores for a lot of these answers. Changing the rules after getting 15 answers is generally frowned upon. – Digital Trauma Jul 10 '15 at 16:40

# APL, 18 12 bytes

⍉(2×⎕)3⍴'↑↓'


This constructs a 2n x 3 matrix, where n is the input (⎕), filled with the characters ↑ and ↓. The transpose (⍉) of this matrix is then printed.

You can try it online.

• Nice abuse of the APL character set. I guess other answers can also use this character set, though. – jimmy23013 Jul 10 '15 at 15:26
• @jimmy23013: The APL code page is EBCDIC-based. Not sure how many languages can handle that. – Dennis Jul 10 '15 at 15:38
• @Dennis Can't the program itself be in ASCII (or some gibberish in EBCDIC) while it prints EBCDIC strings? The shortcut for newlines would be gone, though. Alternatively, the Windows console seemed to print \x18\x19 as ↑↓. – jimmy23013 Jul 10 '15 at 16:07
• – jimmy23013 Jul 10 '15 at 16:17
• @jimmy23013: Yes, I just talked about old consoles in chat. The gibberish might work, but it's probably worth a meta discussion. – Dennis Jul 10 '15 at 16:31

# Pyth, 15 bytes (11 chars)

V3.>*Q"↑↓"N


Try it online: Demonstration

### Explanation:

              implicit: Q = input number
V3            for N in [0, 1, 2]:
"↑↓"       string "↑↓"
*Q           repeat Q times
.>      N      rotate the string by N


# Java, 313 296 bytes

Here's an example that displays arrows graphically:

import java.awt.*;void f(int n){new Frame(){public void paint(Graphics g){for(int k=0,l,m,o;k<n*6;o=k%6,l=o/2*10+32,m=k/6*20+(k++%2==0?19:29),g.fillPolygon(new int[]{m+4,m,m+4,m+4,m+6,m+6,m+10},o==1|o==2|o==5?new int[]{l+9,l+5,l+5,l,l,l+5,l+5}:new int[]{l,l+5,l+5,l+9,l+9,l+5,l+5},7));}}.show();}


import java.awt.*;
void f(int n) {
new Frame() {
public void paint(Graphics g) {
for (int k = 0, l, m, o; k < n*6;){
o = k % 6;
l = o / 2 * 10 + 32;
m = k / 6 * 20 + (k++ % 2 == 0 ? 19 : 29);
g.fillPolygon(new int[] {m+4,m,m+4,m+4,m+6,m+6,m+10},
o == 1 || o == 2 || o == 5 ?
new int[] {l+9,l+5,l+5,l,l,l+5,l+5} :
new int[] {l,l+5,l+5,l+9,l+9,l+5,l+5},
7);
}
}
}.show();
}


The display for 5 as input:

You'll have to resize the window that appears to see the arrows. I tried to make it so that none of them would appear "chopped off" by the window's inside border, but it may appear that way on certain platforms.

# CJam, 18 bytes (14 chars)

ri3*"↑↓"*3/zN*


Generate the columns (which form a repeating pattern) then transpose.

Alternative 18 bytes:

3,ri"↑↓"*fm>N*


Rotate the string "↑↓"*n by 0, 1 or 2 times.

ri"↑↓"*_(+1]N*  Online demo • Win condition is bytes, not chars. – isaacg Jul 10 '15 at 6:29 • @PeterTaylor: The challenge specified Language, X bytes format. You have it in char format, but unicode characters are worth 2 bytes so your actual score is 17 bytes – Levi Jul 10 '15 at 6:40 • @Levi According to this they're 3 bytes each. – isaacg Jul 10 '15 at 7:10 • @isaacg ah my bad – Levi Jul 10 '15 at 7:18 ## Befunge, 71 bytes My first answer, so please be gentle with me :o) Annoying alignment issues resulted in a few wasted bytes, if you have any improvements for me I'd love to hear them! &::3>:2% #v_0#v" \|/ "< >\^,*52<> 0#v" /|\ "< :#^_1-:#^_@  >:#,_$\1-  Input: 4  /|\ \|/ /|\ \|/ /|\ \|/ /|\ \|/ \|/ /|\ \|/ /|\ \|/ /|\ \|/ /|\ /|\ \|/ /|\ \|/ /|\ \|/ /|\ \|/  # CJam, 14 bytes 0000000: 332c 7269 2218 1922 2a66 6d3e 4e2a 3,ri".."*fm>N*  This requires a supporting terminal that renders code page 850 like this: The non-pointy part of the code turned out to be identical to @Sp3000's alternative version. # CJam, 17 bytes ri"⇅⇵⇅"f*N*  Cheaty double arrow version, with credits to @DigitalTrauma. Try it online. # Pyth, 16 bytes (12 chars) J"↑↓"V3*~_JQ  Example: Input: 4 Output: ↑↓↑↓↑↓↑↓ ↓↑↓↑↓↑↓↑ ↑↓↑↓↑↓↑↓  # Python 2, 131 122 bytes from turtle import* for k in range(input()*6):z=k/3+k%3&1;pu();goto(k/3*32,z*32^k%3*64);pd();seth(z*180+90);fd(32);stamp()  Well... I beat C Java I guess? I've chosen height 32 for the arrows, which is pretty large, so after a while the turtle starts drawing offscreen. If you want everything to fit for large inputs, you can either make the arrows smaller by replacing the 32s, or use screensize() (I'm not sure if there's a meta post on offscreen output...) • So... when are going to add turtle graphics to Pyth? – Digital Trauma Jul 11 '15 at 4:37 • Surely for golfing purposes you should choose a single digit number for the sizing... – Beta Decay Jul 13 '15 at 12:35 • @BetaDecay For single digit sizing the tail is barely visible, since it's obscured by the turtle – Sp3000 Jul 13 '15 at 12:37 # GNU sed, 25 bytes I found the ⇅ and ⇵ unicode arrow symbols, which allow more shortening and they have been allowed by this comment: h s/1/⇅/g H G s/1/⇵/g  Input is in unary, so e.g. 4 is 1111: $ echo 1 | sed -f antiferro.sed
⇅
⇵
⇅
$echo 1111 | sed -f antiferro.sed ⇅⇅⇅⇅ ⇵⇵⇵⇵ ⇅⇅⇅⇅$


Previous answer in case ⇅ and ⇵ are disallowed:

# GNU sed, 39 bytes

s/1/↑↓/g
s/.*/&a&↑\n&/
s/a↑/\n/

• Whenever I see "GNU sed" at the top of a post, I don't even need to scroll down to know who posted it. – Alex A. Jul 10 '15 at 17:22
• @AlexA. This guy? ;-) – Digital Trauma Jul 10 '15 at 17:30
• Input is in unary?! Is that a general for the language or something you programmed in? – Beta Decay Jul 12 '15 at 7:46
• What a nefarious answer :-) – xebtl Jul 13 '15 at 8:16
• @BetaDecay thats the unique property of unary strings - their numeric value is equal to their length. The meta question/answer allows for this strictly for languages that don't have native arithmetic (e.g. sed). This is particularly handy for this question, because the output of the required length can easily be generated from the unary input. Cheaty? perhaps - but the meta answer consensus seems to be OK with it. – Digital Trauma Jul 13 '15 at 15:46

let f={n in(0..<n*3).map{print("↑↓",appendNewline:$0%n==n-1)}}  If Swift would be just a liiiitle bit less verbose, it wouldn't even be that bad for golfing (I'm looking at you, named parameter appendNewline) # Ruby 39 (or 44) characters, 43 (or 48) bytes According to https://mothereff.in/byte-counter the arrow characters are 3 bytes each! ->(n){a=['↑↓'*n]*3;a[1]=a[1].reverse;a}  An anonymous function which returns an array. If the function has to print the array, it should end with puts a for 5 more bytes. Example use f=->(n){a=['↑↓'*n]*3;a[1]=a[1].reverse;a} puts f.call(6)  Gives ↑↓↑↓↑↓↑↓ ↓↑↓↑↓↑↓↑ ↑↓↑↓↑↓↑↓  # J, 4135 32 bytes (28 characters) 3$(,:|.)(2*".1!:1[1)$ucp'↑↓'  I have never programmed anything in J so this took me a while, and it's most definitely not the best way to do it. This waits for you to input a number when run before outputing the arrows. • What do you mean you haven't programmed anything in J? I seem to recall a certain J answer which got you over 1k rep. ;) – Alex A. Jul 10 '15 at 14:19 • @AlexA. Doing simple arithmetics is not really what I would call programming. When I posted that answer I really didn't know anything about J besides the right to left priority – Fatalize Jul 10 '15 at 14:21 # Javascript (ES6), 666353 47 bytes (625549 41 characters) f=n=>⇅ ⇵ ⇅.replace(/./g,'$&'.repeat(n))


Props to Digital Trauma for finding the ⇅ and ⇵ characters and allowing me to shave off more bytes.

## J, 30 bytes

|:((2*".1!:1<1),3)$ucp'↑↓'  # C, 169170162125123105119 107 bytes So, I though I might as well give this a go, even though this is obviously not the winner :) Golfed: n,i,j;main(){n=getchar();n=atoi(&n);for(;j++<3;){for(i=0;i++<n;)printf("%.3s ","⇅⇵"+(j%2)*3);puts("");}}  Ungolfed: #include <stdio.h> #include <stdlib.h> /* n -> Number of columns, i & j -> Loop counters */ n,i,j; main() { /* Get the number of iterations from stdin */ n = getchar(); n = atoi(&n); /* Thanks @AndreaBiondo */ for (; j++ < 3;) { /* Print rows of arrows */ for (i = 0; i++ < n;) printf("%.3s ","⇅⇵" + (j % 2) * 3); /* Print a newline */ puts(""); } }  Example: Input: 4 ⇵ ⇵ ⇵ ⇵ ⇅ ⇅ ⇅ ⇅ ⇵ ⇵ ⇵ ⇵  ### Update: See it run here • You can do for(j=0;j++<3;) and the same with i – lirtosiast Jul 11 '15 at 1:26 • @ThomasKwa aha... well spotted. thanks – Levi Jul 11 '15 at 1:30 • i and j are globals, so they're initialized to zero. You can drop i=0 and j=0. – Andrea Biondo Jul 12 '15 at 12:36 • Also, you can exploit little-endianess and zero initialization to use n as a buffer: n=getchar();n=atoi(&n); – Andrea Biondo Jul 12 '15 at 12:46 • @AndreaBiondo when i remove i=0 and j=0, all the output is on one line. can you reproduce this? i'm using gcc 4.9.2 – Levi Jul 12 '15 at 12:52 # Octave, 37 bytes EDIT: corrected from the earlier stripe-antiferromagnetic version. Thanks @beta-decay for catching my mistake. f=@(n)repmat(["⇅";"⇵";"⇅"],1,n)  Defines a function f(n). Sample output: octave:4> f(1) ans = ⇅ ⇵ ⇅ octave:5> f(5) ans = ⇅⇅⇅⇅⇅ ⇵⇵⇵⇵⇵ ⇅⇅⇅⇅⇅  ## CoffeeScript, 60 bytes (58 chars) Comprehensions make it easy without recursion: f=(n,x='')->x+='\n⇵⇅'[i%(n+1)&&1+i%2]for i in[1..n*3+2];x  # Ruby, 33 bytes As a function: f=->n{[s="↑↓"*n,s.reverse,s]}  Example: > puts f[3] ↑↓↑↓↑↓ ↓↑↓↑↓↑ ↑↓↑↓↑↓  # Ruby, 37 bytes Full program which takes input from stdin: puts s="↑↓"*gets.to_i,s.reverse,s  • You can make only a function or a whole program, but it must take an input and draw that many pairs. – Dennis Jul 10 '15 at 17:27 • @Dennis ok, I'm on it – daniero Jul 10 '15 at 17:37 • We seem to have a misunderstanding. I posted the quote to show that a function is in fact valid, since you implied in your original revision that a full program was required by the question. – Dennis Jul 10 '15 at 17:49 • @Dennis No problem. I was just thinking that returning 3 strings wasn't really "drawing", but I guess it doesn't matter. Anyways, got both versions golfed down a bit :) – daniero Jul 10 '15 at 18:22 ## ><>, 55 Bytes "⇅⇵⇅"{:&3*1-:0(?;\ |.!09v!?%&:&:{o:}/ oa{~}/|.!09  Try it online here, inputting the desired length as initial stack value. Non ⇅⇵ solution, 59 Bytes: "↓↑"{:&3*>1-:0(?;{:{\ |.!09v!?%&:&:oo}}@:/ 9oa{$}/|.!0


# BBC BASIC, 70 bytes

## Swift 2.0, 79 bytes

Nothing clever...

let p=3;for x in 0...2{print((0..<p*2).reduce(""){$0+["↑","↓"][($1+x)%2]})}

• This would need to be put in a function, having to change the code for input isn't allowed – Downgoat Jul 11 '15 at 5:29