How to resolve the algorithm Cantor set step by step in the V (Vlang) programming language

Published on 12 May 2024 09:40 PM

How to resolve the algorithm Cantor set step by step in the V (Vlang) programming language

Table of Contents

Problem Statement

Draw a Cantor set.

See details at this Wikipedia webpage:   Cantor set

Let's start with the solution:

Step by Step solution about How to resolve the algorithm Cantor set step by step in the V (Vlang) programming language

Source code in the v programming language

const (
    width = 81
    height = 5
)
 
fn cantor(mut lines [][]u8, start int, len int, index int) {
    seg := len / 3
    if seg == 0 {
        return
    }
    for i in index.. height {
        for j in start + seg..start + 2 * seg {
            lines[i][j] = ' '[0]
        }
    }
    cantor(mut lines, start, seg, index + 1)
    cantor(mut lines, start + seg * 2, seg, index + 1)
}
 
fn main() {
	mut lines := [][]u8{len:height, init: []u8{len:width, init:'*'[0]}}
    cantor(mut lines, 0, width, 1)
    for line in lines {
        println(line.bytestr())
    }
}

  

You may also check:How to resolve the algorithm Abbreviations, automatic step by step in the Kotlin programming language
You may also check:How to resolve the algorithm Simple windowed application step by step in the Standard ML programming language
You may also check:How to resolve the algorithm Sierpinski pentagon step by step in the Prolog programming language
You may also check:How to resolve the algorithm Hello world/Text step by step in the MANOOL programming language
You may also check:How to resolve the algorithm Penney's game step by step in the Prolog programming language