| Bytes | Lang | Time | Link |
|---|---|---|---|
| 051 | AWK | 250808T170503Z | xrs |
| 173 | Go | 231006T154032Z | bigyihsu |
| nan | Vyxal HS | 231006T151222Z | pacman25 |
| 061 | ink | 190329T181510Z | Sara J |
| 062 | PowerShell | 181111T165635Z | GMills |
| 066 | Ruby | 190223T221205Z | Will Cro |
| nan | Javascript | 190221T143244Z | Coert Gr |
| 056 | Attache | 190222T171232Z | Conor O& |
| 071 | C# Visual C# Interactive Compiler | 181124T191453Z | dana |
| 059 | PHP | 190201T211650Z | Oliver |
| 030 | Japt | 190201T150532Z | Oliver |
| 097 | Red | 181110T191741Z | Galen Iv |
| 070 | CJam | 181117T201906Z | Helen |
| 104 | Clojure | 181115T035218Z | TheGreat |
| 051 | Perl 5 | 181113T223517Z | Xcali |
| 029 | MathGolf | 181112T154644Z | Kevin Cr |
| 076 | C gcc | 181112T223046Z | gastropn |
| 017 | Stax | 181112T201251Z | recursiv |
| 068 | Python 2 | 181112T200810Z | Triggern |
| 092 | APLNARS | 181111T175802Z | user5898 |
| 123 | C# | 181110T212658Z | HatsuPoi |
| 060 | Powershell | 181112T161752Z | mazzy |
| 124 | C | 181110T164704Z | HatsuPoi |
| 062 | PowerShell | 181112T150736Z | AdmBorkB |
| 061 | R | 181112T073731Z | J.Doe |
| 095 | Python 3 | 181112T133853Z | glietz |
| 084 | C gcc | 181111T165333Z | Dennis |
| 084 | Python 2 | 181110T163120Z | ElPedro |
| 025 | Pyth | 181112T114438Z | Sok |
| 023 | 05AB1E | 181110T172148Z | Okx |
| 068 | Python 2 | 181112T060540Z | Vedant K |
| 091 | Java 8 | 181111T033201Z | NotBaal |
| 078 | Python 2 | 181111T172117Z | lynn |
| 065 | PHP | 181111T171457Z | Titus |
| 057 | JavaScript Node.js | 181110T150135Z | l4m2 |
| 061 | Bash | 181111T153535Z | Jonah |
| 053 | J | 181111T055513Z | FrownyFr |
| 225 | sfk | 181111T010802Z | Οurous |
| 100 | Clean | 181110T235534Z | Οurous |
| 103 | PHP | 181110T223403Z | th3pirat |
| 123 | Lua | 181110T214952Z | David Wh |
| 020 | Jelly | 181110T185232Z | Dennis |
| 030 | Charcoal | 181110T200924Z | Neil |
| 145 | Batch | 181110T193832Z | Neil |
| 110 | D | 181110T192652Z | Adalynn |
| 048 | Perl 6 | 181110T175238Z | nwellnho |
| 077 | Haskell | 181110T152342Z | Laikoni |
| 060 | Python 2 | 181110T163620Z | ovs |
| 060 | perl E | 181110T161711Z | user7392 |
Go, 173 bytes
import(."strings";."fmt")
func f(){S,F:=[]string{},Sprintf
for i:=1;i<100;i++{s:=F("%d",i)
if i%4<1{s=F("[%s]",s)}
if i%3<1{s=F("(%s)",s)}
S=append(S,s)}
Print(Join(S," "))}
Prints the output to STDOUT.
ink, 61 bytes
VAR j=0
-(i)~j="{i%4:{i}|[{i}]}"
{i%3:{j}|({j})} <>{i<99:->i}
Explanation
VAR j=0 // Declare a variable called j.
-(i)~j="{i%4:{i}|[{i}]}" // The i label keeps track of how many times it's been visited. Set j to that value, or that value surrounded by brackets, depending o nwhat it is.
{i%3:{j}|({j})} <>{i<99:->i} // Print j or (j), depending on i. Use glue (<>) to not print a newline. Go back to the i label if it's been visited fewer than 99 times.
PowerShell, 98 82 74 67 63 62 bytes
A whopping -31 bytes thanks to @Veskah -5 bytes thanks to @ASCII-only
(1..99|%{(($a=($_,"[$_]")[!($_%4)]),"($a)")[!($_%3)]})-join' '
I'm still not quite sure what I've done here.
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.
Javascript, 114 96 bytes
[...Array(99)].map(_=>['[4]','(3)'].reduce((a,r)=>n%r[1]<1?r.replace(r[1],a):a,++n),n=0).join` `
Thanks to Conor O'Brien for helping me improve it :-)
Attache, 56 bytes
Echo@@({~Join^^S@_'Mask[4'3|_,["["'"]","("'")"]]}=>1:99)
Explanation
Echo@@({~Join^^S@_'Mask[4'3|_,["["'"]","("'")"]]}=>1:99)
{ }=>1:99 over each number _, 1 to 99:
4'3|_ check if 4 or 3 divide _
Mask[ ,["["'"]","("'")"]] keep the respective brackets
^^S@_' fold over this list (seed = S[_]):
~Join joining elements by the iterator
Echo@@( ) print strings separated by spaces
Alternatives
58 bytes: Echo@@({~Join^^S@_'Mask[[4,3]|_,["["'"]","("'")"]]}=>1:99)
59 bytes: Print@@({~Join^^S@_'Mask[[4,3]|_,["["'"]","("'")"]]}=>1:99)
76 bytes: Print@@(&/S@{Mask[1'3'4'12|_,Split@$"${_} (${_}) [${_}] ([${_}])"] }=>1:99)
C# (Visual C# Interactive Compiler), 71 bytes
int i;for(;i<99;)Write("{0:;;(}{1:;;[}{2}{1:;;]}{0:;;)} ",++i%3,i%4,i);
-9 bytes thanks to @ASCIIOnly!
Leveraging the semicolon (The ";" section separator) to create a custom format string.
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" "]]
CJam, 70 bytes
99,:){X4%0={'[Xs']++}{X}?}fX]{Xs'[/_,(=']/0=i3%0={'(Xs')++}{X}?}fX]S*
Try it out online! (Permalink)
Explanation
99 Push 99 to stack
, Make a 0..98 array
:) Increment every value in array
{ }fX For X in array at top of stack
? If...
X4%0= Condition: X mod 4 = 0
{ } Is true, then:
'[ Push "["
Xs Push X as a string
'] Push "]"
++ Concatenate to "[X]"
{ } Is false, then:
X Push X
] Capture all in an array
{ }fX For X in array at top of stack
? If...
Xs X as a string
'[/ Split by "["
_,(= Take last element after split
']/ Split by "]"
0= Take first element after split
i Top element as an integer
Xs'[/_,(=']/0=i The number X minus any brackets
3%0= Condition: X mod 3 = 0
{ } Is true, then:
'( Push "("
Xs Push the original X as a string
') Push ")"
++ Concatenate to "(X)"
{ } If false, then:
X Push X
] Capture all in an array
S* Separate by a space
This does not output a trailing space.
Clojure, 104 bytes
(apply print(map #(do(def s(if(=(rem % 4)0)(str"["%"]")%))(if(=(rem % 3)0)(str"("s")")s))(range 1 100)))
MathGolf, 41 40 34 29 bytes
♀({îû)(î+╫îa_'(\')ßyΓî34α÷ä§
NOTE: It has a trailing space
Only my second MathGolf answer..
-5 bytes thanks to @JoKing.
Explanation:
♀( # Push 99 (100 decreased by 1)
{ # Start a loop, which implicitly loops down to (and excluding) 0
û)( # Push string ")("
î+ # Append the 1-indexed index
╫ # Rotate the string once towards the right
îa # Push the 1-indexed index of the loop, wrap in a list
_ # Duplicate it
'( '# Push string "("
\ # Swap the top two items of the stack
') '# Push string ")"
ßy # Wrap all three into a list, and join them
Γ # Wrap all four into a list
# (We now have a list [N, "(N)", "[N]", "([N])"], where N is the index)
î # Push the 1-indexed index of the loop
34 # Push 3 and 4 to the stack
α # Wrap all three into a list
÷ # Check for each if the index is divisible by it
# (resulting in either [0,0], [0,1], [1,0], or [1,1]
ä # Convert from binary to integer
# (resulting in either 0, 1, 2, or 3
§ # Push the string at that index from the array
# Push a space
# (After the loop, output the entire stack joined together implicitly)
C (gcc), 76 bytes
Surprisingly, this straight-forward solution was shorter than the "clever" ones I could come up with.
f(i){for(i=0;i++<99;)printf(i%3?i%4?"%d ":"[%d] ":i%4?"(%d) ":"([%d]) ",i);}
Python 2, 68 bytes
for i in range(1,100):print("(%s)","%s")[i%3>0]%("[%s]"%i,i)[i%4>0],
Ends with a trailing space.
APL(NARS), 46 chars, 92 bytes
{{0=3∣w:1⌽')(',⍵⋄⍵}{0=4∣w:1⌽'][',⍵⋄⍵}⍕w←⍵}¨⍳99
litte test:
{{0=3∣w:1⌽')(',⍵⋄⍵}{0=4∣w:1⌽'][',⍵⋄⍵}⍕w←⍵}¨⍳14
1 2 (3) [4] 5 (6) 7 [8] (9) 10 11 ([12]) 13 14
C#, 124 117 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);
Console.ReadKey();
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
$result
Output:
True
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)
C, C++, 136 133 131 129 128 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?" ":"");}
PowerShell, 67 62 bytes
"$(1..99|%{'('*!($x=$_%3)+'['*!($y=$_%4)+$_+']'*!$y+')'*!$x})"
Basically a FizzBuzz using string multiplication times Boolean variables (implicitly cast to 1 or 0). Those strings are left on the pipeline and gathered within a script block inside quotes. Since the default $OutputFieldSeparator for an array is spaces, this implicitly gives us space-delimited array elements.
Python 3, 95 bytes
print(*[(i if i%4else f"[{i}]")if i%3else(f"({i})"if i%4else f"([{i}])")for i in range(1,100)])
C (gcc), 84 bytes
main(i){while(99/i++)printf("%s%s%d%s%s ","("+i%3,"["+i%4,i-1,"]"+i%4,")"+i%3);}
There's a null byte at the beginning of each "bracket string".
Python 2, 105 97 88 86 85 84 bytes
x=1
while x<100:print((('%s','(%s)')[x%3<1],'[%s]')[x%4<1],'([%s])')[x%12<1]%x,;x+=1
Pyth, 25 bytes
jdmj]W!%d4dc2*"()"!%d3S99
Try it online here.
jdmj]W!%d4dc2*"()"!%d3S99
m S99 Map [1-99], as d, using:
%d3 d mod 3
! Logical not, effectively maps 0 to 1, all else to 0
*"()" Repeat "()" the above number of times
c2 Chop into two equal parts - maps "()" to ["(",")"] , and "" to ["",""]
The above is result {1}
%d4 d mod 4
! Logical not the above
]W d If the above is truthy, [d], else d
The above is result {2}
j Join {1} on string representation of {2}
jd Join the result of the map on spaces, implicit print
Python 2, 68 bytes
i=0
exec"i+=1;t,f=i%3<1,i%4<1;print'('*t+'['*f+`i`+']'*f+')'*t,;"*99
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);}
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.
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
I envisioned this cool approach slicing '([%0d])' but I can't get the expressions any shorter.
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.
JavaScript (Node.js), 57 bytes
f=(n=99)=>n&&f(n-1)+(s=n%4?n:`[${n}]`,n%3?s:`(${s})`)+' '
Changed to community cuz the optimize rely too much on it
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:
seqproduces 1..99- we pipe that into
awkwith 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.
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
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<+"]")]]
PHP 103
for(;$i<1e2;$i++)$a.=$i%12==0?"([$i]) ":($i%3==0?"($i) ":($i%4==0?"[$i] ":"$i "));echo substr($a,5,-1);
Lua, 161 123 bytes
b=""for i=1,99 do;c,d=i%3==0,i%4==0;b=b..(c and"("or"")..(d and"["or"")..i..(d and"]"or"")..(c and")"or"").." "end;print(b)
Ungolfed:
b = ""
for i = 1, 99 do
c = 1 % 3 == 0
d = 1 % 4 == 0
a = ""
if c then
a = a .. "("
end
if d then
a = a .. "["
end
a = a .. i
if d then
a = a .. "]"
end
if c then
a = a .. ")"
end
b = b .. a .. " "
end
print(b)
Jelly, 21 20 bytes
³Ṗµ3,4ṚƬḍד([“])”j)K
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.
Charcoal, 30 bytes
⪫EEE⁹⁹I⊕ι⎇﹪⊕κ⁴ι⪫[]ι⎇﹪⊕κ³ι⪫()ι
Try it online! Link is to verbose version of code. Explanation:
⁹⁹ Literal 99
E Map over implicit range
ι Current value
⊕ Incrementd
I Cast to string
E Map over list of strings
κ Current index
⊕ Incremented
⁴ Literal 4
﹪ Modulo
ι Current value
[] Literal string `[]`
ι Current value
⪫ Join i.e wrap value in `[]`
⎇ Ternary
E 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
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.
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?" ":"");}
Ported from @HatsuPointerKun's C++ answer.
Haskell, 77 bytes
unwords[f"()"3$f"[]"4$show n|n<-[1..99],let f(x:r)m s|mod n m<1=x:s++r|1<3=s]
I wonder if show[n] can be used to shorten things up, so far to no avail.
Python 2, 68 65 60 bytes
i=0
exec"i+=1;print'('[i%3:]+`[i][i%4:]or i`+')'[i%3:],;"*99
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.