18
\$\begingroup\$

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

Please put your answers in Language, X bytes format, as it's easy to read. The least amount of bytes wins!

\$\endgroup\$
12
  • 6
    \$\begingroup\$ "Any arrows" sounds pretty ambiguous to me - what about ^v? \$\endgroup\$
    – Sp3000
    Jul 10, 2015 at 7:27
  • 1
    \$\begingroup\$ @Sp3000 No, cause they don't have the little tails. \$\endgroup\$
    – jado
    Jul 10, 2015 at 7:30
  • 3
    \$\begingroup\$ Are these arrows allowed: and ? (unicode code points U+21C5 and U+21F5) \$\endgroup\$ Jul 10, 2015 at 16:28
  • 1
    \$\begingroup\$ @DigitalTrauma They are perfect! \$\endgroup\$
    – jado
    Jul 10, 2015 at 16:29
  • 13
    \$\begingroup\$ @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. \$\endgroup\$ Jul 10, 2015 at 16:40

33 Answers 33

1
2
0
\$\begingroup\$

R, 60 62 bytes

Takes input from STDIN and outputs to STDOUT. Creates a 3 x (2 * input) array, adds a column of carriage returns and then outputs the transposed array.

cat(t(cbind(array(c('↑','↓'),c(3,2*scan())),'\n')),sep='')

Test run

cat(t(cbind(array(c('↑','↓'),c(3,2*scan())),'\n')),sep='')
1: 25
2: 
Read 1 item
↑↓↑↓↑↓↑↓↑↓↑↓↑↓↑↓↑↓↑↓↑↓↑↓↑↓↑↓↑↓↑↓↑↓↑↓↑↓↑↓↑↓↑↓↑↓↑↓↑↓
↓↑↓↑↓↑↓↑↓↑↓↑↓↑↓↑↓↑↓↑↓↑↓↑↓↑↓↑↓↑↓↑↓↑↓↑↓↑↓↑↓↑↓↑↓↑↓↑↓↑
↑↓↑↓↑↓↑↓↑↓↑↓↑↓↑↓↑↓↑↓↑↓↑↓↑↓↑↓↑↓↑↓↑↓↑↓↑↓↑↓↑↓↑↓↑↓↑↓↑↓
\$\endgroup\$
0
\$\begingroup\$

Tcl 49 bytes

No winner but at least it's competitive:

foreach x {⇅ ⇵ ⇅} {puts [string repeat $x $argv]}
\$\endgroup\$
3
  • \$\begingroup\$ You can save bytes using lmap instead of foreach \$\endgroup\$
    – sergiol
    Nov 20, 2017 at 0:19
  • \$\begingroup\$ And string repeatcan be abbreviated to string re \$\endgroup\$
    – sergiol
    Nov 20, 2017 at 0:21
  • \$\begingroup\$ And I am not sure, but implementing it as a proc retrieving a side effect of lmap returning values and replacing $argv by someone one-letter variable may save bytes. \$\endgroup\$
    – sergiol
    Nov 20, 2017 at 0:24
-1
\$\begingroup\$

Swift 2.0, 79 bytes

Nothing clever...

let p=3;for x in 0...2{print((0..<p*2).reduce(""){$0+["↑","↓"][($1+x)%2]})}
\$\endgroup\$
1
  • 3
    \$\begingroup\$ This would need to be put in a function, having to change the code for input isn't allowed \$\endgroup\$
    – Downgoat
    Jul 11, 2015 at 5:29
1
2

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.