Cantor set: Difference between revisions

m
syntax highlighting fixup automation
(Added credits)
m (syntax highlighting fixup automation)
Line 10:
=={{header|11l}}==
{{trans|Python}}
<langsyntaxhighlight lang=11l>V WIDTH = 81
V HEIGHT = 5
 
Line 31:
L(i) 0 .< HEIGHT
V beg = WIDTH * i
print((lines[beg .< beg + WIDTH]).join(‘’))</langsyntaxhighlight>
{{out}}
<pre>
Line 42:
 
=={{header|Action!}}==
<langsyntaxhighlight lang=Action!>PROC FillRect(INT x,y,w,h)
INT i
 
Line 93:
DO UNTIL CH#$FF OD
CH=$FF
RETURN</langsyntaxhighlight>
{{out}}
[https://gitlab.com/amarok8bit/action-rosetta-code/-/raw/master/images/Cantor_set.png Screenshot from Atari 8-bit computer]
 
=={{header|Ada}}==
<langsyntaxhighlight lang=Ada>with Ada.Text_IO;
 
procedure Cantor_Set is
Line 121:
Ada.Text_IO.Put_Line (Image (L));
end loop;
end Cantor_Set;</langsyntaxhighlight>
{{out}}
<pre>*********************************************************************************
Line 130:
 
=={{header|ALGOL 68}}==
<langsyntaxhighlight lang=algol68>BEGIN
# draw a Cantor Set using ASCII #
INT lines = 5; # number of lines for the set #
Line 156:
segment width OVERAB 3
OD
END</langsyntaxhighlight>
{{out}}
<pre>
Line 168:
=={{header|ALGOL W}}==
Based on the Algol 68 sample.
<langsyntaxhighlight lang=algolw>begin
% draw a Cantor Set using ASCII %
integer LINES; % number of lines for the set %
Line 201:
end for_l
end
end.</langsyntaxhighlight>
{{out}}
<pre>
Line 214:
 
Using composable library functions whenever possible, for better productivity:
<langsyntaxhighlight lang=applescript>------------------------- CANTOR SET -----------------------
 
-- cantor :: [String] -> [String]
Line 376:
set my text item delimiters to dlm
str
end unlines</langsyntaxhighlight>
{{Out}}
<pre>█████████████████████████████████████████████████████████████████████████████████
Line 386:
=={{header|Arturo}}==
 
<langsyntaxhighlight lang=rebol>width: 81
height: 5
 
Line 406:
 
loop lines 'line
-> print join line</langsyntaxhighlight>
 
{{out}}
Line 417:
 
=={{header|AWK}}==
<langsyntaxhighlight lang=AWK>
# syntax: GAWK -f CANTOR_SET.AWK
# converted from C
Line 448:
cantor(start+seg*2,seg,indx+1)
}
</syntaxhighlight>
</lang>
{{out}}
<pre>
Line 459:
 
=={{header|BASIC}}==
<langsyntaxhighlight lang=gwbasic>10 DEFINT A-Z
20 N = 4
30 W = 3^(N-1)
Line 472:
120 MID$(L$,P,S) = SPACE$(S)
130 P = P+S
140 GOTO 100</langsyntaxhighlight>
{{out}}
<pre>###########################
Line 481:
=={{header|BASIC256}}==
{{trans|FreeBASIC}}
<langsyntaxhighlight lang=BASIC256>
global ancho, alto, intervalo
ancho = 81 : alto = 5
Line 515:
next i
End
</syntaxhighlight>
</lang>
{{out}}
<pre>
Line 522:
 
=={{header|BQN}}==
<langsyntaxhighlight lang=bqn>Cantor ← {" •" ⊏˜ >⥊¨(¯1⊸⊏⊢¨¨⊢)1‿0‿1∧⌜⍟(↕𝕩)1}</langsyntaxhighlight>
 
{{out}}
Line 539:
=={{header|C}}==
{{trans|Kotlin}}
<langsyntaxhighlight lang=c>#include <stdio.h>
 
#define WIDTH 81
Line 576:
print();
return 0;
}</langsyntaxhighlight>
 
{{output}}
Line 589:
=={{header|C sharp|C#}}==
{{trans|Java}}
<langsyntaxhighlight lang=csharp>using System;
 
namespace CantorSet {
Line 627:
}
}
}</langsyntaxhighlight>
{{out}}
<pre>*********************************************************************************
Line 637:
=={{header|C++}}==
{{trans|D}}
<langsyntaxhighlight lang=cpp>#include <iostream>
 
const int WIDTH = 81;
Line 672:
 
return 0;
}</langsyntaxhighlight>
{{out}}
<pre>*********************************************************************************
Line 681:
 
=={{header|CLU}}==
<langsyntaxhighlight lang=clu>cantor = cluster is make
rep = null
ac = array[char]
Line 713:
cs: string := cantor$make(81, 5, '*')
stream$puts(po, cs)
end start_up</langsyntaxhighlight>
{{out}}
<pre>*********************************************************************************
Line 722:
 
=={{header|COBOL}}==
<langsyntaxhighlight lang=cobol> IDENTIFICATION DIVISION.
PROGRAM-ID. CANTOR.
Line 769:
BLANK-CHAR.
MOVE SPACE TO CHAR(POS).
ADD 1 TO POS.</langsyntaxhighlight>
{{out}}
<pre>#################################################################################
Line 779:
=={{header|D}}==
{{trans|C}}
<langsyntaxhighlight lang=d>import std.stdio;
 
enum WIDTH = 81;
Line 811:
writeln(lines[beg..beg+WIDTH]);
}
}</langsyntaxhighlight>
{{out}}
<pre>*********************************************************************************
Line 821:
=={{header|Delphi}}==
{{Trans|Java}}
<langsyntaxhighlight lang=Delphi>
program Cantor_set;
 
Line 871:
Readln;
end.
</syntaxhighlight>
</lang>
 
{{out}}
Line 883:
 
{{Works with|Office 365 betas 2021}}
<langsyntaxhighlight lang=lisp>CANTOR
=LAMBDA(n,
APPLYN(n)(
Line 972:
)
)
)</langsyntaxhighlight>
 
and also assuming the following generic bindings in the Name Manager for the WorkBook:
 
<langsyntaxhighlight lang=lisp>APPENDCOLS
=LAMBDA(xs,
LAMBDA(ys,
Line 1,132:
)
)
)</langsyntaxhighlight>
 
{{Out}}
Line 1,147:
| style="text-align:center; font-family:Arial, Helvetica, sans-serif !important; background-color:#000000; color:#ffffff" | 1
| style="text-align:right; " | SHOWCANTOR(CANTOR(0))
| style="text-align:left; font-weight:bold" | <syntaxhighlight lang=text>█</langsyntaxhighlight>
 
|- style="text-align:right;"
| style="text-align:center; font-family:Arial, Helvetica, sans-serif !important; background-color:#000000; color:#ffffff" | 2
| style="text-align:right; " | SHOWCANTOR(CANTOR(1))
| style="text-align:left; background-color:#cbcefb;" | <syntaxhighlight lang=text>███
█ █</langsyntaxhighlight>
 
|- style="text-align:right;"
| style="text-align:center; font-family:Arial, Helvetica, sans-serif !important; background-color:#000000; color:#ffffff" | 3
| style="text-align:right; " | SHOWCANTOR(CANTOR(2))
| style="text-align:left; font-weight:bold" | <syntaxhighlight lang=text>█████████
███ ███
█ █ █ █</langsyntaxhighlight>
 
|- style="text-align:right;"
| style="text-align:center; font-family:Arial, Helvetica, sans-serif !important; background-color:#000000; color:#ffffff" | 4
| style="text-align:right; " | SHOWCANTOR(CANTOR(3))
| style="text-align:left; font-weight:bold" | <syntaxhighlight lang=text>███████████████████████████
█████████ █████████
███ ███ ███ ███
█ █ █ █ █ █ █ █</langsyntaxhighlight>
 
|}
Line 1,301:
 
=={{header|Factor}}==
<langsyntaxhighlight lang=factor>USING: grouping.extras io kernel math sequences
sequences.repeating ;
IN: rosetta-code.cantor-set
Line 1,323:
concat print ;
depth <iota> [ print-cantor ] each</langsyntaxhighlight>
{{out}}
<pre>
Line 1,335:
=={{header|Forth}}==
Where is says <code>[email protected]</code> it should say <code>c&#64;</code>, but I'm not keen on writing it as <code>c&amp;#64;</code> in the actual code.
<langsyntaxhighlight lang=Forth>warnings off
 
4 \ iterations
Line 1,360:
: go print BEGIN step done? UNTIL ;
 
go bye</langsyntaxhighlight>
Output:
<pre>#################################################################################
Line 1,369:
 
=={{header|FreeBASIC}}==
<langsyntaxhighlight lang=freebasic>
Const ancho = 81
Const alto = 5
Line 1,406:
Next i
End
</syntaxhighlight>
</lang>
{{out}}
<pre>
Line 1,418:
=={{header|Go}}==
{{trans|Kotlin}}
<langsyntaxhighlight lang=go>package main
 
import "fmt"
Line 1,456:
fmt.Println(string(line[:]))
}
}</langsyntaxhighlight>
 
{{out}}
Line 1,469:
=={{header|Groovy}}==
{{trans|Java}}
<langsyntaxhighlight lang=groovy>class App {
private static final int WIDTH = 81
private static final int HEIGHT = 5
Line 1,504:
}
}
}</langsyntaxhighlight>
{{out}}
<pre>*********************************************************************************
Line 1,515:
===Interval bars===
{{Trans|Python}} (Functional version)
<langsyntaxhighlight lang=haskell>-------------------------- CANTOR ------------------------
 
cantor :: [(Bool, Int)] -> [(Bool, Int)]
Line 1,541:
where
c True = '*'
c False = ' '</langsyntaxhighlight>
{{Out}}
<pre>*********************************************************************************
Line 1,551:
Or, using strings for the model as well as the display:
 
<langsyntaxhighlight lang=haskell>-------------------------- CANTOR ------------------------
 
cantor :: [String] -> [String]
Line 1,580:
. pred
)
)</langsyntaxhighlight>
{{Out}}
<pre>█████████████████████████████████████████████████████████████████████████████████
Line 1,590:
===Dual representation===
Intervals as fraction pairs, and intervals as graphic bars:
<langsyntaxhighlight lang=haskell>import Control.Monad (join)
import Data.Bifunctor (bimap)
import Data.List (intercalate, mapAccumL, maximumBy)
Line 1,648:
go x
| 1 /= x = '/' : show x
| otherwise = []</langsyntaxhighlight>
{{Out}}
<pre>(0, 1)
Line 1,661:
 
=={{header|IS-BASIC}}==
<langsyntaxhighlight lang=IS-BASIC>100 PROGRAM "Cantor.bas"
110 GRAPHICS HIRES 2
120 SET PALETTE BLACK,WHITE
Line 1,671:
180 CALL CANTOR(X+2*L/3,Y-HEIGHT,L/3,HEIGHT)
190 END IF
200 END DEF</langsyntaxhighlight>
 
=={{header|J}}==
The argument to the cantor_dust monad is an integer that describes the depth of the dust. Shown here are results for cantor_dust 2 and for cantor_dust 3 . It works by checking for 1 digits in the base 3 representation of the coordinates. These background coordinates are plotted with # character using ASCII art. 1j1 #"1 expands the lines to improve aspect ratio on character cell (console) display. }:"1 curtails the extra space character line by line. < draws a pretty box.
<syntaxhighlight lang=J>
<lang J>
odometer =: [: (4 $. $.) $&1
 
Line 1,684:
< (}:"1) 1j1 #"1 '#' (([: <"1 [: ;/"1 (#~ 1 e."1 [: (,/"2) 3 3&#:)) i)}a
)
</syntaxhighlight>
</lang>
 
<pre>
Line 1,733:
</pre>
With an `x' argument cantor_dust generalizes to higher dimensions. Try 3 cantor_dust 2
<syntaxhighlight lang=J>
<lang J>
cantor_dust =: 2&$: :(dyad define)
shape =. x # 3 ^ y
Line 1,740:
< (}:"1) 1j1 #"1 '#' (([: <"1 [: ;/"1 (#~ 1 e."1 [: (,/"2) 3 3&#:)) i)} a
)
</syntaxhighlight>
</lang>
 
=={{header|Java}}==
{{trans|Kotlin}}
<langsyntaxhighlight lang=java>public class App {
private static final int WIDTH = 81;
private static final int HEIGHT = 5;
Line 1,780:
}
}
</syntaxhighlight>
</lang>
{{out}}
<pre>*********************************************************************************
Line 1,792:
{{Trans|Python}} (Functional version)
{{Trans|Haskell}}
<langsyntaxhighlight lang=JavaScript>(() => {
"use strict";
 
Line 1,879:
// MAIN ---
return main();
})();</langsyntaxhighlight>
{{Out}}
<pre>*********************************************************************************
Line 1,890:
Using strings for the model as well as the display:
{{Trans|Haskell}}
<langsyntaxhighlight lang=javascript>(() => {
"use strict";
 
Line 1,961:
// MAIN ---
return main();
})();</langsyntaxhighlight>
{{Out}}
<pre>█████████████████████████████████████████████████████████████████████████████████
Line 1,977:
In the case of languages like Javascript which lack a built-in Ratio type, or standard Fraction/Ratio library, rendering stages of the set elaboration as lists of fraction pairs may take more work than rendering them as graphic lines.
 
<langsyntaxhighlight lang=javascript>(() => {
"use strict";
 
Line 2,363:
// MAIN ---
return main();
})();</langsyntaxhighlight>
{{Out}}
<pre>(0, 1)
Line 2,376:
 
=={{header|jq}}==
<langsyntaxhighlight lang=jq># cantor(width; height)
def cantor($w; $h):
def init: [range(0; $h) | [range(0; $w) | "*"]];
Line 2,393:
cantor($width; $height)
| pp</langsyntaxhighlight>
{{out}}
With the above in a file, cantor.jq, the following incantation
Line 2,402:
=={{header|Julia}}==
{{trans|AWK}}
<langsyntaxhighlight lang=julia>const width = 81
const height = 5
 
Line 2,422:
print(Char(lines[i, j]), j == width ? "\n" : "")
end
</langsyntaxhighlight>{{out}}
<pre>
#################################################################################
Line 2,433:
=={{header|Kotlin}}==
Simple terminal drawing.
<langsyntaxhighlight lang=scala>// Version 1.2.31
 
const val WIDTH = 81
Line 2,453:
cantor(0, WIDTH, 1)
lines.forEach { println(it) }
}</langsyntaxhighlight>
 
{{output}}
Line 2,466:
=={{header|Lua}}==
{{trans|python}}
<langsyntaxhighlight lang=lua>local WIDTH = 81
local HEIGHT = 5
local lines = {}
Line 2,511:
end
print()
end</langsyntaxhighlight>
{{out}}
<pre>*********************************************************************************
Line 2,519:
* * * * * * * * * * * * * * * *</pre>
=={{header|Mathematica}}/{{header|Wolfram Language}}==
<langsyntaxhighlight lang=Mathematica>Graphics[MeshPrimitives[CantorMesh[#],1]/.{x_}:>{x,-0.05#}&/@Range[5],ImageSize->600]</langsyntaxhighlight>
{{out}}
A graphic of a Cantor set is shown
Line 2,525:
=={{header|Modula-2}}==
{{trans|Kotlin}}
<langsyntaxhighlight lang=modula2>MODULE Cantor;
FROM Terminal IMPORT Write,WriteLn,ReadChar;
 
Line 2,576:
 
ReadChar;
END Cantor.</langsyntaxhighlight>
 
=={{header|Nim}}==
{{trans|Kotlin}}
 
<langsyntaxhighlight lang=Nim>import strutils
 
const
Line 2,601:
cantor(0, Width, 1)
for line in lines:
echo line</langsyntaxhighlight>
 
{{Out}}
Line 2,612:
=={{header|Objeck}}==
{{trans|Java}}
<langsyntaxhighlight lang=objeck>class CantorSet {
WIDTH : static : Int;
HEIGHT : static : Int;
Line 2,657:
};
}
}</langsyntaxhighlight>
 
{{Output}}
Line 2,670:
=={{header|Perl}}==
{{trans|Raku}}
<langsyntaxhighlight lang=Perl>use strict;
use feature 'say';
 
Line 2,697:
}
 
say for cantor(5);</langsyntaxhighlight>
 
{{Out}}
Line 2,707:
 
===regex version===
<langsyntaxhighlight lang=perl>#!/usr/bin/perl -l
 
use strict; # https://rosettacode.org/wiki/Cantor_set
Line 2,714:
$_ = '#' x 81;
 
1 while print, s/(#+)\1\1/ $1 . $1 =~ tr!#! !r . $1 /ge;</langsyntaxhighlight>
{{out}}
<pre>
Line 2,726:
=={{header|Phix}}==
Based on Algol 68, but even simpler, shorter, and sweeter!
<!--<langsyntaxhighlight lang=Phix>(phixonline)-->
<span style="color: #004080;">integer</span> <span style="color: #000000;">n</span> <span style="color: #0000FF;">=</span> <span style="color: #000000;">5</span><span style="color: #0000FF;">,</span>
<span style="color: #000000;">w</span> <span style="color: #0000FF;">=</span> <span style="color: #7060A8;">power</span><span style="color: #0000FF;">(</span><span style="color: #000000;">3</span><span style="color: #0000FF;">,</span><span style="color: #000000;">n</span><span style="color: #0000FF;">-</span><span style="color: #000000;">1</span><span style="color: #0000FF;">),</span>
Line 2,743:
<span style="color: #008080;">end</span> <span style="color: #008080;">while</span>
<span style="color: #008080;">end</span> <span style="color: #008080;">while</span>
<!--</langsyntaxhighlight>-->
{{out}}
<pre>
Line 2,754:
 
=={{header|Phixmonti}}==
<langsyntaxhighlight lang=Phixmonti>include ..\Utilitys.pmt
 
5 >ps
Line 2,774:
cps
line ?
endfor</langsyntaxhighlight>
Other solution
<langsyntaxhighlight lang=Phixmonti>include ..\Utilitys.pmt
 
5 >ps
Line 2,792:
endfor
endfor
line ?</langsyntaxhighlight>
{{out}}
<pre>#################################################################################
Line 2,803:
 
=={{header|Processing}}==
<langsyntaxhighlight lang=java>
//Aamrun, 1st July 2022
 
Line 2,819:
cantorSet(100,10,900,10,1,10,5);
}
</syntaxhighlight>
</lang>
 
=={{header|Python}}==
===Imperative===
<langsyntaxhighlight lang=python>WIDTH = 81
HEIGHT = 5
 
Line 2,846:
for i in xrange(HEIGHT):
beg = WIDTH * i
print ''.join(lines[beg : beg+WIDTH])</langsyntaxhighlight>
{{out}}
<pre>*********************************************************************************
Line 2,856:
Separating ''(Bool, Int)'' model from ''String'' display:
{{Works with|Python|3.7}}
<langsyntaxhighlight lang=python>'''Cantor set – separating model from display'''
 
from functools import (reduce)
Line 2,929:
# MAIN ---
if __name__ == '__main__':
main()</langsyntaxhighlight>
{{Out}}
<pre>
Line 2,942:
{{Trans|Haskell}}
{{Works with|Python|3.7}}
<langsyntaxhighlight lang=python>'''Cantor set – strings as both model and display.'''
 
from itertools import (chain, islice)
Line 3,012:
# MAIN ---
if __name__ == '__main__':
main()</langsyntaxhighlight>
{{Out}}
<pre>█████████████████████████████████████████████████████████████████████████████████
Line 3,022:
===Dual representations – fractional and graphic===
{{Works with|Python|3.7}}
<langsyntaxhighlight lang=python>'''A Cantor set generator, and two different
representations of its output.
'''
Line 3,147:
# MAIN ---
if __name__ == '__main__':
main()</langsyntaxhighlight>
{{Out}}
<pre>(0, 1)
Line 3,164:
Note: Other languages will need to zero out the a() array. In QB64 all arrays are initialized to zero at program start.
 
<langsyntaxhighlight lang=qb64>_Title "Cantor Set"
 
Dim Shared As Integer sw, sh, wide, high
Line 3,201:
Next
Next
End Sub</langsyntaxhighlight>
 
=={{header|Quackery}}==
Line 3,207:
===Using an L-System===
 
<langsyntaxhighlight lang=Quackery> [ $ "" swap witheach
[ nested quackery join ] ] is expand ( $ --> $ )
Line 3,227:
dip [ 3 / ] ] ]
2drop
</syntaxhighlight>
</lang>
 
{{out}}
Line 3,242:
[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
 
<syntaxhighlight lang=R>
<lang R>
cantorSet <- function() {
depth <- 6L
Line 3,294:
list(graph = g, data = df, set = cs)
}
</syntaxhighlight>
</lang>
{{out}}
 
Line 3,303:
{{trans|Kotlin}}
 
<langsyntaxhighlight lang=racket>#lang racket/base
;; {trans|Kotlin}}
 
Line 3,327:
(module+ main
(for-each displayln (Cantor_set)))
</syntaxhighlight>
</lang>
{{out}}
<pre>*********************************************************************************
Line 3,339:
(formerly Perl 6)
{{trans|Kotlin}}
<syntaxhighlight lang=raku perl6line>sub cantor ( Int $height ) {
my $width = 3 ** ($height - 1);
 
Line 3,359:
}
 
.say for cantor(5);</langsyntaxhighlight>
 
{{Out}}
Line 3,369:
 
=={{header|REXX}}==
<langsyntaxhighlight lang=rexx>/*REXX program displays an ASCII diagram of a Canter Set as a set of (character) lines. */
w= linesize() /*obtain the width of the display term.*/
if w==0 then w= 81 /*Can't obtain width? Use the default.*/
Line 3,384:
say $ /*display a line of the Cantor Set. */
#= # % 3 /*the part (thirds) to be blanked out. */
end /*j*/ /*stick a fork in it, we're all done. */</langsyntaxhighlight>
This REXX program makes use of &nbsp; '''linesize''' &nbsp; REXX program (or BIF) which is used to determine the screen width (or linesize) of the terminal (console).
 
Line 3,412:
 
=={{header|Ring}}==
<langsyntaxhighlight lang=ring>
# Project : Cantor set
 
Line 3,464:
cantor(x+floor(lens*2/3),y,floor(lens/3))
ok
</syntaxhighlight>
</lang>
Output image:
 
Line 3,471:
=={{header|Ruby}}==
This works by numbering the segments (starting with 0) in base 3. Print whitespace if this number contains the digit 1; a black square otherwise.
<langsyntaxhighlight lang=ruby>lines = 5
 
(0..lines).each do |exp|
Line 3,478:
puts chars.map{ |c| c * seg_size }.join
end
</syntaxhighlight>
</lang>
{{out}}
<pre>█████████████████████████████████████████████████████████████████████████████████
Line 3,489:
 
=={{header|Rust}}==
<langsyntaxhighlight lang=rust>
use convert_base::Convert;
use std::fmt;
Line 3,555:
}
 
</syntaxhighlight>
</lang>
{{out}}
<pre>
Line 3,569:
=={{header|Scala}}==
===Imperative Programming (Q&D)===
<langsyntaxhighlight lang=Scala>object CantorSetQD extends App {
val (width, height) = (81, 5)
 
Line 3,590:
cantor(0, width, 1)
lines.foreach(l => println(l.mkString))
}</langsyntaxhighlight>
{{Out}}See it in running in your browser by [https://scalafiddle.io/sf/QrqaHeu/0 (JavaScript)]
or by [https://scastie.scala-lang.org/4JTi1zXzRq6H4yUlAYNTSw Scastie (JVM)].
 
===Functional Programming (Recommended)===
<langsyntaxhighlight lang=Scala>object CantorSetFP extends App {
val (width, height) = (81, 5)
 
Line 3,626:
output.map(l => (0 to width).map(pos => if (l contains pos) '*' else ' ').mkString)
.mkString("\n"))
}</langsyntaxhighlight>
{{Out}}See it in running in your browser by [https://scalafiddle.io/sf/szUjPWO/7 (JavaScript)]
or by [https://scastie.scala-lang.org/ZaNUtEOcStuBfJImOnEz5Q Scastie (JVM)].
Line 3,632:
=={{header|Sidef}}==
{{trans|Raku}}
<langsyntaxhighlight lang=ruby>func cantor (height) {
var width = 3**(height - 1)
var lines = height.of { "\N{FULL BLOCK}" * width }
Line 3,652:
}
 
cantor(5).each { .say }</langsyntaxhighlight>
{{out}}
<pre>
Line 3,665:
{{works with|GNU Smalltalk}}
Smalltalk represents Intervals' start and stop values as Fraction, so precision is kept for quilte a while.
<langsyntaxhighlight lang=Smalltalk>Object subclass: CantorSet [
 
| intervals |
Line 3,732:
]
 
TestCantor iterations: 4.</langsyntaxhighlight>
Output:
<pre>#################################################################################
Line 3,742:
=={{header|Visual Basic .NET}}==
{{trans|C#}}
<langsyntaxhighlight lang=vbnet>Module Module1
 
Const WIDTH = 81
Line 3,781:
End Sub
 
End Module</langsyntaxhighlight>
{{out}}
<pre>*********************************************************************************
Line 3,791:
=={{header|Vlang}}==
{{trans|Go}}
<langsyntaxhighlight lang=vlang>const (
width = 81
height = 5
Line 3,816:
println(line.bytestr())
}
}</langsyntaxhighlight>
 
{{out}}
Line 3,830:
=={{header|Wren}}==
{{trans|Kotlin}}
<langsyntaxhighlight lang=ecmascript>var width = 81
var height = 5
 
Line 3,848:
 
cantor.call(0, width, 1)
for (i in 0...height) System.print(lines[i].join())</langsyntaxhighlight>
 
{{out}}
Line 3,860:
 
=={{header|XPL0}}==
<langsyntaxhighlight lang=XPL0>proc Cantor(N, LineSeg, Len); \Delete middle third of LineSeg
int N; char LineSeg; int Len, Third, I;
[if N>0 and Len>1 then
Line 3,878:
Text(0, LineSeg);
];
]</langsyntaxhighlight>
 
{{out}}
Line 3,890:
 
=={{header|zkl}}==
<langsyntaxhighlight lang=zkl>const WIDTH=81, HEIGHT=5;
var lines=HEIGHT.pump(List,List.createLong(WIDTH,"\U2588;").copy); // full block
Line 3,902:
}(0,WIDTH,1);
 
lines.pump(Console.println,"concat");</langsyntaxhighlight>
{{out}}
<pre>
10,333

edits