# Multiplicity Test

Use any programming language to display numbers between 1 and 99 (including both) in such a way, so that:

• the numbers are separated by single space,
• if a number is divisible by 3, it should be in parentheses,
• if a number is divisible by 4, it should be in square brackets,
• if a number is divisible by both 3 and 4, it should be in both parentheses and square brackets (with square brackets closer to the number).

1 2 (3) [4] 5 (6) 7 [8] (9) 10 11 ([12]) 13 14 (15) [16] 17 (18) 19 [20] (21) 22 23 ([24]) 25 26 (27) [28] 29 (30) 31 [32] (33) 34 35 ([36]) 37 38 (39) [40] 41 (42) 43 [44] (45) 46 47 ([48]) 49 50 (51) [52] 53 (54) 55 [56] (57) 58 59 ([60]) 61 62 (63) [64] 65 (66) 67 [68] (69) 70 71 ([72]) 73 74 (75) [76] 77 (78) 79 [80] (81) 82 83 ([84]) 85 86 (87) [88] 89 (90) 91 [92] (93) 94 95 ([96]) 97 98 (99)

• Related – ETHproductions Nov 10 '18 at 14:48
• Can we output each entry on a new line, or must the output be all on one line? – ETHproductions Nov 10 '18 at 14:56
• Can the output end with a space. A few answers seem to assume so. – Dennis Nov 11 '18 at 16:14

# 05AB1E, 23 bytes

-1 byte thanks to Kevin Cruijssen

тGND4Öi…[ÿ]}N3Öi…(ÿ)]ðý


Try it online!

• -1 byte by changing }?ð? to ]ðý (close both the if and loop, and join the entire stack by spaces) – Kevin Cruijssen Nov 11 '18 at 21:56
• @KevinCruijssen Thanks, that was exactly what I was looking for! – Okx Nov 12 '18 at 8:36
• -1 by using Å€ – Grimmy Nov 20 '19 at 14:03

# Python 2, 6865 60 bytes

i=0
exec"i+=1;print'('[i%3:]+[i][i%4:]or i+')'[i%3:],;"*99


Try it online!

• I was right :) +1 – ElPedro Nov 10 '18 at 16:42

# R, 61 bytes

"+"=c
r=""+""
cat(paste0(r+"(",r+""+"[",1:99,r+""+"]",r+")"))


Try it online!

• brilliant aliasing! – Giuseppe Nov 12 '18 at 20:08
• How does this even work? That's amazing! +1 to you my friend – Sumner18 Dec 20 '18 at 20:29

# Jelly, 21 20 bytes

³Ṗµ3,4ṚƬḍ×“([“])”j)K


Try it online!

### How it works

³Ṗµ3,4ṚƬḍ×“([“])”j)K  Main link. No arguments.

³                     Set the return value to 100.
Ṗ                    Pop; yield [1, ..., 99].
µ               )   Map the chain in between over [1, ..., 9]; for each integer k:
3,4                    Set the return value to [3, 4].
ṚƬ                  Reverse until a loop is reached. Yields [[3, 4], [4, 3]].
ḍ                 Test k for divisibility by [[3, 4], [4, 3]], yielding a
matrix of Booleans.
×“([“])”         Repeat the characters of [['(', '['], [']', ')']] as many
times as the Booleans indicate.
j        Join the resulting pair of strings, separated by k.
K  Join the resulting array of strings, separated by spaces.


# D, 110 bytes

import std.stdio;void f(){for(int i;i<99;)write(++i%3?"":"(",i%4?"":"[",i,i%4?"":"]",i%3?"":")",i%99?" ":"");}


Try it online!

# Charcoal, 30 bytes

⪫ＥＥＥ⁹⁹Ｉ⊕ι⎇﹪⊕κ⁴ι⪫[]ι⎇﹪⊕κ³ι⪫()ι


Try it online! Link is to verbose version of code. Explanation:

    ⁹⁹                          Literal 99
Ｅ                            Map over implicit range
ι                       Current value
⊕                        Incrementd
Ｉ                         Cast to string
Ｅ                             Map over list of strings
κ                   Current index
⊕                    Incremented
⁴                  Literal 4
﹪                     Modulo
ι                 Current value
[]              Literal string []
ι             Current value
⪫                Join i.e wrap value in []
⎇                      Ternary
Ｅ                              Map over list of strings
κ         Current index
⊕          Incremented
³        Literal 3
﹪           Modulo
ι       Current value
()    Literal string ()
ι   Current value
⪫      Join i.e wrap value in ()
⎇            Ternary
Literal space
⪫                               Join list
Implicitly print


# J, 54 53 bytes

1 byte less thanks to @Jonah

(*stdout(3|.0=4 3 1 3 4&|,1=":)#3|.']) ([',":)@>i.100


Try it online!

• Thanks for doing this one. Also, why do you have to do stdout here... I've never seen that before. @FrownyFrog – Jonah Nov 11 '18 at 5:58
• @Jonah I can’t output it as a complete string, it gets cut off (. . .) stdout doesn’t do that, and it doesn’t print a newline either, so I can also print each number separately. For some reason though it makes trailing spaces appear (there are 4, and only 1 is intentionally there) – FrownyFrog Nov 11 '18 at 6:09
• This approach is really clever, both the rotation and the choice to use #. I had introduced an auxiliary verb to surround with () and []: g=. {.@[ , ":@] , {:@[. ugh the verboseness! – Jonah Nov 11 '18 at 6:10
• one more question: any reason you used LF instead of _. the latter seems to work too. – Jonah Nov 11 '18 at 6:34

## C, C++, 136133131129128 124 bytes

-5 bytes thanks to Zacharý and inspired by write() function in D language ( see Zacharý answer )

-2 bytes thanks to mriklojn

-12 bytes for the C version thanks to mriklojn

-4 bytes thanks to ceilingcat

#include<cstdio>
void f(){for(int i=0;i++<99;)printf("(%s%d%s%s%s"+!!(i%3),i%4?"":"[",i,i%4?"":"]",i%3?"":")",i%99?" ":"");}


### C Specific Optimization : 115 bytes

#include<stdio.h>
i;f(){for(;i++<99;)printf("(%s%d%s%s%s"+!!(i%3),i%4?"":"[",i,i%4?"":"]",i%3?"":")",i%99?" ":"");}

• Does MSVC let you do the inf f() thing? Sorry 'bout deleting my comments, thought I had something shorter (I didn't) – Zacharý Nov 10 '18 at 19:18
• @Zacharý No, i think the function is too simple and it generates a "f must return an int". BTW, your solution was 3 bytes shorter ( include compression paired with moving the incrementation of i ) – HatsuPointerKun Nov 10 '18 at 19:22
• Dang, dotally forgot printf wasa thing. Couldn't you use the C stdio then? – Zacharý Nov 10 '18 at 19:50
• Another thing you could use/exploit is the fact that, at least with gcc 5.3.1, you don't need the #include, and you can also remove the function return type. Additionally, if you declare the int i outside the function (in global scope) then its value defaults to 0 and data type defaults to int. This would result in your loop starting at 0, and to fix this you could move the increment into the condition expression in your for loop, making it look like i;f(){for(;++i<=99;) – mriklojn Nov 10 '18 at 20:22
• Suggest ")\0"+i%3 instead of i%3?"":")". Also, I think you need to add i=0 at the beginning of the loop. – ceilingcat Dec 31 '18 at 6:19

# Powershell, 60 bytes

"$(1..99|%{($_,"($_)","[$_]","([$_])")[!($_%3)+2*!($_%4)]})"  Explanation: • the array with 4 elements: $_, "($_)", "[$_]", "([$_])" • and the index: [!($_%3)+2*!($_%4)] • repeat for each number • convert the result to a string Less golfed Test script: $f = {

$r = 1..99|%{ ($_, "($_)", "[$_]", "([$_])") [!($_%3)+2*!($_%4)] } "$($r)" }$expected = '1 2 (3) [4] 5 (6) 7 [8] (9) 10 11 ([12]) 13 14 (15) [16] 17 (18) 19 [20] (21) 22 23 ([24]) 25 26 (27) [28] 29 (30) 31 [32] (33) 34 35 ([36]) 37 38 (39) [40] 41 (42) 43 [44] (45) 46 47 ([48]) 49 50 (51) [52] 53 (54) 55 [56] (57) 58 59 ([60]) 61 62 (63) [64] 65 (66) 67 [68] (69) 70 71 ([72]) 73 74 (75) [76] 77 (78) 79 [80] (81) 82 83 ([84]) 85 86 (87) [88] 89 (90) 91 [92] (93) 94 95 ([96]) 97 98 (99)'
$result = &$f
$result-eq$expected

## C#, 124117 123 bytes

-5 bytes thanks to Kevin Cruijssen

x=>{for(int i=0;i++<99;)System.Console.Write((i%3<1?"(":"")+(i%4<1?"[":"")+i+(i%4<1?"]":"")+(i%3<1?")":"")+(i>98?"":" "));}


Test with :

Action<int> t = x=>{for(int i=0;i++<99;)System.Console.Write((i%3<1?"(":"")+(i%4<1?"[":"")+i+(i%4<1?"]":"")+(i%3<1?")":"")+(i>98?"":" "));}
t.Invoke(0);

• Into the foray of C#, I see. Does C# allow integers as the left argument to a ternary operator, or does it have to be a boolean? – Zacharý Nov 10 '18 at 22:39
• I don't know much about C#, but could you use x instead of i,thus not having to worry about the int ? (You'd still have to set it, of course). – Zacharý Nov 10 '18 at 22:41
• @Zacharý No, it generates a CS0029 error "Can't convert implicitly int to boolean". And yes, i could use i and the fact that i can initialize it at 0 when i Invoke. But wouldn't that mean that i would have to include the declaration of t ( Action<int> ) and the call ( t.Invoke(0) ) in the bytecount ? – HatsuPointerKun Nov 10 '18 at 22:49
• I'm asking if something like x=>{for(x=0;x++<99;)Console.Write((x%3==0?"(":"")+(x%4==0?"[":"")+x+(x%4==0?"]":"")+(x%3==0?")":"")+(x%99==0?"":" "));}; would work. – Zacharý Nov 10 '18 at 23:22
• All five ==0 can be <1. – Kevin Cruijssen Nov 11 '18 at 22:00

# Red, 99 97 bytes

repeat n 99[a: b: c: d:""if n% 3 = 0[a:"("c:")"]if n% 4 = 0[b:"["d:"]"]prin rejoin[a b n d c" "]]


Try it online!

# Ruby, 72 66 bytes

p [*1..99].map{|x|a=x
a="[#{x}]"if x%4<1
a="(#{a})"if x%3<1
a}*' '


Thanks to @jonathan-frech and @conor-obrien for additional trimming.

• Hello and welcome to PPCG! 70 bytes. – Jonathan Frech Feb 23 '19 at 22:21
• Welcome to PPCG! Here's another 4 bytes off of @JonathanFrench 's suggestion, for 66 bytes, since a.join b for an array a and string b is equivalent to a*b – Conor O'Brien Feb 24 '19 at 4:41

# PowerShell, 9882746763 62 bytes

A whopping -31 bytes thanks to @Veskah -5 bytes thanks to @ASCII-only

(1..99|%{(($a=($_,"[$_]")[!($_%4)]),"($a)")[!($_%3)]})-join' '


Try it online!

I'm still not quite sure what I've done here.

• Just some quick golfing for 70 bytes. You don't have to cast $a as a string and "$a" will still substitute in the value. (Note: Single-quotes do not replace $foo, only double-quotes). Another trick is ifs only care about 0 or 1 so you can use boolean logic to save a byte – Veskah Nov 12 '18 at 21:43 • 67 bytes if you use list indexing as well. – Veskah Nov 12 '18 at 21:53 • also 67 – ASCII-only Feb 22 '19 at 13:30 • 63? – ASCII-only Feb 22 '19 at 13:34 • 62? – ASCII-only Feb 22 '19 at 13:43 # perl -E, 60 bytes $,=$";say map$_%12?$_%3?$_%4?$_:"[$_]":"($_)":"([$_])",1..99


Some bytes can be saved if we can use newlines between the numbers: in that case, we can remove the $,=$";, change the map into a for loop, while moving the say into the loop.

• Are you the Abigail? Inventor of /^1$|^(11+?)\1+$/? – msh210 Nov 11 '18 at 22:54
• Wow. What an honor to have you here! – msh210 Nov 12 '18 at 12:56

# Perl 6, 51 48 bytes

put {$_%3??$^a!!"($a)"}(++$_%4??$_!!"[$_]")xx 99


Try it online!

• I was going to abuse the difference between lists and array representations, like this, but I'm not sure how to get rid of the enclosing brackets around the whole list... – Jo King Nov 11 '18 at 1:27
• @JoKing I thought about that, too, but I only came up with this 51-byter. – nwellnhof Nov 11 '18 at 9:10

## Batch, 145 bytes

@set s=
@for /l %%i in (1,1,99)do @set/an=%%i,b=n%%4,p=n%%3&call:c
@echo%s%
:c
@if %b%==0 set n=[%n%]
@if %p%==0 set n=(%n%)
@set s=%s% %n%


The code falls through into the subroutine but the string has already been printed by this point so the code executes harmlessly.

for(;$i<1e2;$i++)$a.=$i%12==0?"([$i]) ":($i%3==0?"($i) ":($i%4==0?"[$i] ":"$i "));echo substr($a,5,-1); https://www.ideone.com/SBAuWp # Clean, 100 bytes import StdEnv,Text  join" "[if(n/3*3<n)m("("+m+")")\\n<-[1..99],m<-[if(n/4*4<n)(""<+n)("["<+n<+"]")]]  Try it online! # sfk, 225 bytes for n from 1 to 99 +calc -var #(n)/3+1/3 -dig=0 +calc -var #text*3-#(n) +setvar t +calc -var #(n)/4 -dig=0 +calc -var #text*4-#(n) +xed -var _0_#(t)$#(n)$_ _*_#(t)#(n)_ +xed _0*_([part2])_ _?*_[part2]_ +xed "_\n_ _" +endfor  Try it online! # Bash, 61 bytes -14 bytes, thanks to Dennis seq 99|awk '{ORS=" ";x=$1%4?$1:"["$1"]";print$1%3?x:"("x")"}'  # explanation Pretty straightforward: • seq produces 1..99 • we pipe that into awk with the output record separator (ORS) set to space so the output is a single line. • the main awk body just adds "[]" when the number is divisible by 4, and then adds, on top of that, "()" when divisible by 3. Try it online! # JavaScript (Node.js), 57 bytes f=(n=99)=>n&&f(n-1)+(s=n%4?n:[${n}],n%3?s:(${s}))+' '  Try it online! Changed to community cuz the optimize rely too much on it • You could shorten significantly by doing ${n%4?n:[${n}]} – ETHproductions Nov 10 '18 at 15:12 • 66 bytes (with ETH's suggestion) – Alion Nov 10 '18 at 15:15 • 59 bytes – Arnauld Nov 10 '18 at 18:15 • 57 bytes – Neil Nov 10 '18 at 19:47 # PHP, 65 bytes while($i++<99)echo$i%4?$i%3?$i:"($i)":($i%3?"[$i]":"([$i])")," ";  or while($i++<99)echo"("[$i%3],"["[$i%4],$i,"]"[$i%4],")"[\$i%3]," ";


(requires PHP 5.5 or later)

Run with -nr or try them online.

# Python 2, 78 bytes

i=0
exec"i+=1;u=i%3/-2*(i%4/-3-1);print'([%0d])'[u:7-u:1+(i%3<1<=i%4)]%i,;"*99


Try it online!

I envisioned this cool approach slicing '([%0d])' but I can't get the expressions any shorter.

# Java 8, 92 91 bytes

-1 byte thanks to @Dana

i->{for(;i++<99;)out.printf((i>1?" ":"")+(i%12<1?"([%d])":i%3<1?"(%d)":i%4<1?"[%d]":i),i);}

Try it online!

Alternative solution, 82 bytes (with trailing space in the output - not sure if that's allowed):

i->{for(;i++<99;)out.printf((i%12<1?"([%d])":i%3<1?"(%d)":i%4<1?"[%d]":i)+" ",i);}

Explanation:

for(;i++<99;) - a for loop that goes from the value of i (reused as input, taken to be 0 in this case) to 99

out.printf(<part1>+<part2>,i); - formats the string before immediately printing it to stdout with the value of i

where <part1> is (i>1?" ":"") - prints the space before printing the number unless that number is 1, in which case it omits the space

and <part2> is (i%12<1?"([%d])":i%3<1?"(%d)":i%4<1?"[%d]":i) - if i is divisible by both 3 and 4, i has both square and round brackets around it; else if i is divisible by 3, i has round brackets; else if i is divisible by 4, i has square brackets; else, i has no brackets.

• Save a byte by moving the space to the beginning of each loop iteration (i>1:" ":"") – dana Nov 11 '18 at 6:35
• That would only work if I printed the result in reverse (see this) but would actually save 2 bytes instead of 1. – NotBaal Nov 11 '18 at 16:23
• Unfortunately that's not the same as the expected output as per the question, but thank you for the suggestion nevertheless! – NotBaal Nov 11 '18 at 16:24
• The "try it online" links seem to be broken. I was thinking i->{for(;i++<99;)out.printf((i>1?" ":"")+(i%12<1?"([%d])":i%3<1?"(%d)":i%4<1?"[%d]":i),i);} ? – dana Nov 11 '18 at 16:37
• Ohhhh you're right that does work! Thanks for that! – NotBaal Nov 11 '18 at 16:55