Cantor set: Difference between revisions
Content deleted Content added
(12 intermediate revisions by 7 users not shown) | |||
Line 205:
# # # # # # # # # # # # # # # #
</pre>
=={{header|Amazing Hopper}}==
{{Trans|C}}
VERSION 1:
<syntaxhighlight lang="c">
#include <basico.h>
#define WIDTH 81
#define HEIGHT 5
#proto cantor(_X_,_Y_,_Z_)
algoritmo
decimales '0'
dimensionar(HEIGHT,WIDTH) matriz rellena("#",líneas)
_cantor(1, WIDTH, 2)
fijar separador 'NULO', imprimir( líneas, NL)
terminar
subrutinas
cantor(inicio, largo, índice)
seg=0
#( seg:=(int(largo/3))), no es cero?, entonces{
#basic{
líneas[índice:HEIGHT, (inicio+seg):((inicio+seg*2)-1)] = " ")
cantor( inicio, seg, índice+1 ) )
cantor( (inicio+(seg*2)), seg, índice+1 ) )
}
}
retornar
</syntaxhighlight>
{{out}}
<pre>
#################################################################################
########################### ###########################
######### ######### ######### #########
### ### ### ### ### ### ### ###
# # # # # # # # # # # # # # # #
</pre>
{{Trans|Ruby}}
VERSION 2:
<syntaxhighlight lang="c">
#include <basico.h>
#define HEIGHT 5
algoritmo
decimales '0'
cantor="", j=0
iterar
i=0
cadenas 's,v'
iterar grupo ( ++i, #(i< (3^j)),\
#( v = occurs("1", dectobase(i,3)) ? " " : "#"; )\
#( s = s $ replicate(v, 3^(HEIGHT-j-1) )) )
#(cantor = cantor $ s $ NL)
mientras ' #(j<=HEIGHT); ++j '
imprimir(cantor)
terminar
</syntaxhighlight>
{{out}}
<pre>
#################################################################################
########################### ###########################
######### ######### ######### #########
### ### ### ### ### ### ### ###
# # # # # # # # # # # # # # # #
</pre>
=={{header|AppleScript}}==
Line 449 ⟶ 525:
* * * * * * * * * * * * * * * *
</pre>
=={{header|BASIC}}==
{{works with|QBasic}}
{{works with|GW-BASIC}}
{{works with|MSX BASIC}}
<syntaxhighlight lang="gwbasic">10 DEFINT A-Z
20 N = 4
Line 469 ⟶ 549:
### ### ### ###
# # # # # # # #</pre>
==={{header|BASIC256}}===
{{trans|FreeBASIC}}
<syntaxhighlight lang="
ancho = 81 : alto = 5
dim intervalo(alto, ancho)
Line 504 ⟶ 584:
print
next i
end</syntaxhighlight>
==={{header|Chipmunk Basic}}===
{{trans|FreeBASIC}}
{{works with|Chipmunk Basic|3.6.4}}
<syntaxhighlight lang="qbasic">100 cls
110 ancho = 81
120 alto = 5
130 dim intervalo$(alto,ancho)
140 '
150 sub cantor()
160 for i = 0 to alto-1
170 for j = 0 to ancho-1
180 intervalo$(i,j) = chr$(254)
190 next j
200 next i
210 end sub
220 '
230 sub conjcantor(inicio,longitud,indice)
240 segmento = longitud/3
250 if segmento = 0 then exit sub
260 for i = indice to alto-1
270 for j = inicio+segmento to inicio+segmento*2-1
280 intervalo$(i,j) = chr$(32)
290 next j
300 next i
310 conjcantor(inicio,segmento,indice+1)
320 conjcantor(inicio+segmento*2,segmento,indice+1)
330 end sub
340 '
350 cantor()
360 conjcantor(0,ancho,1)
370 for i = 0 to alto-1
380 for j = 0 to ancho-1
390 print intervalo$(i,j);
400 next j
410 print
420 next i
430 end</syntaxhighlight>
==={{header|GW-BASIC}}===
{{works with|PC-BASIC|any}}
{{works with|BASICA}}
The [[#BASIC|BASIC]] solution works without any changes.
==={{header|MSX Basic}}===
{{works with|MSX BASIC|any}}
The [[#BASIC|BASIC]] solution works without any changes.
==={{header|QBasic}}===
{{trans|FreeBASIC}}
{{works with|QBasic|1.1}}
{{works with|QuickBasic|4.5}}
<syntaxhighlight lang="qbasic">SUB Cantor
FOR i = 0 TO alto - 1
FOR j = 0 TO ancho - 1
intervalo$(i, j) = CHR$(254) '"#"
NEXT j
NEXT i
END SUB
SUB ConjCantor (inicio, longitud, indice)
segmento = INT(longitud / 3)
IF segmento = 0 THEN EXIT SUB
FOR i = indice TO alto - 1
FOR j = inicio + segmento TO inicio + segmento * 2 - 1
intervalo$(i, j) = CHR$(32) '" "
NEXT j
NEXT i
CALL ConjCantor(inicio, segmento, indice + 1)
CALL ConjCantor(inicio + segmento * 2, segmento, indice + 1)
END SUB
CONST ancho = 81
CONST alto = 5
DIM SHARED intervalo$(alto, ancho)
CLS
CALL Cantor
CALL ConjCantor(0, ancho, 1)
FOR i = 0 TO alto - 1
FOR j = 0 TO ancho - 1
PRINT intervalo$(i, j);
NEXT j
PRINT
NEXT i
END</syntaxhighlight>
==={{header|True BASIC}}===
{{trans|QBasic}}
<syntaxhighlight lang="qbasic">LET ancho = 81
LET alto = 5
DIM intervalo$(0,0)
MAT REDIM intervalo$(0 TO alto, 0 TO ancho)
SUB cantor
FOR i = 0 TO alto-1
FOR j = 0 TO ancho-1
LET intervalo$(i, j) = "#" !CHR$(254)
NEXT j
NEXT i
END SUB
SUB conjcantor (inicio,longitud,indice)
LET segmento = INT(longitud/3)
IF segmento = 0 THEN EXIT SUB
FOR i = indice TO alto-1
FOR j = inicio+segmento TO inicio+segmento*2-1
LET intervalo$(i, j) = CHR$(32) !" "
NEXT j
NEXT i
CALL conjcantor (inicio, segmento, indice+1)
CALL conjcantor (inicio+segmento*2, segmento, indice+1)
END SUB
CALL cantor
CALL conjcantor (0, ancho, 1)
FOR i = 0 TO alto-1
FOR j = 0 TO ancho-1
PRINT intervalo$(i, j);
NEXT j
PRINT
NEXT i
END</syntaxhighlight>
==={{header|Yabasic}}===
{{trans|FreeBASIC}}
<syntaxhighlight lang="vb">ancho = 81
alto = 5
dim intervalo$(alto, ancho)
Cantor()
ConjCantor(0, ancho, 1)
for i = 0 to alto - 1
for j = 0 to ancho - 1
print intervalo$(i, j);
next j
print
next i
end
sub Cantor()
for i = 0 to alto - 1
for j = 0 to ancho - 1
intervalo$(i, j) = chr$(254) //"#"
next j
next i
end sub
sub ConjCantor(inicio, longitud, indice)
segmento = longitud / 3
if segmento = 0 return
for i = indice to alto - 1
for j = inicio + segmento to inicio + segmento * 2 - 1
intervalo$(i, j) = " "
next j
next i
ConjCantor(inicio, segmento, indice + 1)
ConjCantor(inicio + segmento * 2, segmento, indice + 1)
end sub</syntaxhighlight>
=={{header|BQN}}==
<syntaxhighlight lang="bqn">Cantor ← {" •" ⊏˜ >⥊¨(¯1⊸⊏⊢¨¨⊢)1‿0‿1∧⌜⍟(↕𝕩)1}</syntaxhighlight>
Line 857 ⟶ 1,092:
{{out}}
Same result of Java
=={{header|EasyLang}}==
[https://easylang.online/show/#cod=S87PyS9SMDU15Sooyk9WSE7MKwHyKxQqFYqrFPQU9LgUFBQy00AcOwUDPUMQFwiKq4wVbEGC+grGUKHc/LJUsD5dkCxUsCg1uQSkDCGCZAFYITYpbQUjBS2wJJoiPS49LqgqAwULAwVDAwMuAA== Run it]
<syntaxhighlight lang=text>
color 555
proc cantor x y sz . .
if sz > 0.1
sz3 = sz / 3
move x y - sz3
rect sz sz3
cantor x y - sz3 sz3
cantor x + 2 * sz3 y - sz3 sz3
.
.
cantor 0 80 100
</syntaxhighlight>
=={{header|Elixir}}==
Line 1,521 ⟶ 1,774:
[[File:FutureBasic Cantor Set.png]]
=={{header|Fōrmulæ}}==
{{FormulaeEntry|page=https://formulae.org/?script=examples/The_Cantor_set}}
'''Solution'''
Strictly speaking, a visualization of the perfect Cantor set is impossible, it consists of a infinite set of isolated points in the interval [0, 1]. The most we can do is drawing the early steps of its construction.
Several ways of visualization of the Cantor set are shown.
'''Preliminaries'''
Let us start with a definition of the points that define the central points of the intervals of the Cantos set on any step:
[[File:Fōrmulæ - Cantor set 01.png]]
[[File:Fōrmulæ - Cantor set 02.png]]
[[File:Fōrmulæ - Cantor set 03.png]]
The followign function defines the segments on each step:
[[File:Fōrmulæ - Cantor set 04.png]]
[[File:Fōrmulæ - Cantor set 05.png]]
[[File:Fōrmulæ - Cantor set 06.png]]
=== Plotting the central points ===
[[File:Fōrmulæ - Cantor set 07.png]]
[[File:Fōrmulæ - Cantor set 08.png]]
=== Common method ===
[[File:Fōrmulæ - Cantor set 09.png]]
[[File:Fōrmulæ - Cantor set 10.png]]
[[File:Fōrmulæ - Cantor set 11.png]]
=== Cantor dust ===
[[File:Fōrmulæ - Cantor set 12.png]]
[[File:Fōrmulæ - Cantor set 13.png]]
[[File:Fōrmulæ - Cantor set 14.png]]
=== [https://en.wikipedia.org/wiki/Knaster%E2%80%93Kuratowski_fan Knaster–Kuratowski fan or "Cantor teepee"] ===
[[File:Fōrmulæ - Cantor set 15.png]]
[[File:Fōrmulæ - Cantor set 16.png]]
[[File:Fōrmulæ - Cantor set 17.png]]
The following forms of visualization are taken from [https://en.wikipedia.org/wiki/Point-set_topology point-set topology]. They are not intended as forms of visualization of the Cantor set, instead, these structures make use of the Cantor set.
=== [https://en.wikipedia.org/wiki/Indecomposable_continuum Brouwer–Janiszewski–Knaster continuum, or "the bucket handle"] ===
[[File:Fōrmulæ - Cantor set 18.png]]
[[File:Fōrmulæ - Cantor set 19.png]]
[[File:Fōrmulæ - Cantor set 20.png]]
=== "Double Knaster" ===
[[File:Fōrmulæ - Cantor set 21.png]]
[[File:Fōrmulæ - Cantor set 22.png]]
[[File:Fōrmulæ - Cantor set 23.png]]
=={{header|Go}}==
Line 2,618 ⟶ 2,946:
{{out}}
A graphic of a Cantor set is shown
=={{header|MiniScript}}==
<syntaxhighlight lang="miniscript">
cantorSet = function(start, length, depth)
if depth == 0 then return [[start, start+length - 1]]
newLen = length / 3
leftInterval = cantorSet(start, newLen, depth - 1)
rightInterval = cantorSet(start + 2 * newLen, newLen, depth - 1)
return leftInterval + rightInterval
end function
for depth in range(0, 4)
output =[" "] * 81
segments = cantorSet(1, 81,depth)
for segment in segments
for x in range(segment[0] - 1, segment[1]-1)
output[x] = "#"
end for
end for
print output.join("")
end for
</syntaxhighlight>
{{out}}
<pre>
#################################################################################
########################### ###########################
######### ######### ######### #########
### ### ### ### ### ### ### ###
# # # # # # # # # # # # # # # #
</pre>
=={{header|Modula-2}}==
{{trans|Kotlin}}
Line 3,342 ⟶ 3,704:
===Using an L-System===
(Described at [[L-system#Quackery]].)
<syntaxhighlight lang="quackery"> [ $ "" swap witheach
Line 3,373 ⟶ 3,737:
q q q q q q q q q q q q q q q q
</pre>
=={{header|R}}==
[https://creativecommons.org/licenses/by-nc-sa/4.0 Attribution-NonCommercial-ShareAlike 4.0 International, CC BY-NC-SA 4.0] to neonira@gmail.com
Line 3,994 ⟶ 4,359:
=={{header|Wren}}==
{{trans|Kotlin}}
<syntaxhighlight lang="
var height = 5
|