• I removed the www from the URL, please update your bookmarks and pay attention to the bottom of the screen if using Google Chrome to allow push notifications again.

Russian Sorting Halves Danilin

DANILIN

Member
Joined
Oct 19, 2018
Messages
14
Programming Experience
10+
Russian Sorting Halves and fast and human
sorts 1'000'000 in 2.2 seconds on QB64
sorts 1'000'000 in 0.3 seconds on PureBasic

me interested implementation of algorithm in language C#

number of elements is written to file with c:/N.txt or use variable n
array d(n) can be read from a file or synthesized in a program

Code:
' Russian Sorting Halves Danilin
 
DECLARE SUB RussianSortingHalvesDAV (ab!, yz!, part!, age!)
CLOSE
OPEN "c:/N.txt" FOR INPUT AS #1
INPUT #1, n
'n=1234567
age = 1 + LOG(n) / LOG(2)
PRINT n
 
DIM SHARED d(n) 'AS LONG
DIM SHARED a(n) 'AS LONG
 
'OPEN "c:/ISX.txt" FOR INPUT AS #2
'FOR i=1 TO n: INPUT #2, d(i): NEXT
 
'FOR i = 1 TO n: d(i) = n - i + 1: NEXT ' INT(RND*n)
FOR i = 1 TO n: d(i) = INT(RND * n): NEXT '
 
FOR k = 1 TO 20: PRINT d(k);: NEXT: PRINT: PRINT
FOR k = n - 19 TO n: PRINT d(k);: NEXT: PRINT: PRINT
 
start = TIMER
 
IF age > 0 THEN
    CALL RussianSortingHalvesDAV(1, n, 1, age)
END IF
 
finish = TIMER
 
PRINT finish - start; "second ": PRINT
 
OPEN "c:/=RuSortHalves_dav.txt" FOR OUTPUT AS #3
PRINT #3, finish - start; "second "
PRINT #3, n; "elements", "RECURSION"
FOR i = 1 TO 22: PRINT #3, d(i): NEXT
FOR i = n - 22 TO n: PRINT #3, d(i): NEXT
 
FOR k = 1 TO 20: PRINT d(k);: NEXT: PRINT: PRINT
FOR k = n - 19 TO n: PRINT d(k);: NEXT: PRINT: PRINT
 
END
 
SUB RussianSortingHalvesDAV (ab, yz, part, age)
 
IF yz - ab < 1 THEN EXIT SUB
 
FOR i = ab TO yz
    summa = summa + d(i)
NEXT
middle = summa / (yz - ab + 1)
 
abc = ab - 1
xyz = yz + 1
 
FOR i = ab TO yz
    IF d(i) < middle THEN abc = abc + 1: a(abc) = d(i): ELSE xyz = xyz - 1: a(xyz) = d(i)
NEXT
 
FOR i = ab TO yz: d(i) = a(i): NEXT
 
IF part < age THEN
    IF abc >= ab THEN CALL RussianSortingHalvesDAV(ab, abc, part + 1, age)
    IF xyz <= yz THEN CALL RussianSortingHalvesDAV(xyz, yz, part + 1, age)
END IF
 
END SUB
Russian Sorting Halves Danilin visualisation
https://www.youtube.com/watch?v=UxvSwOtpiuc
https://www.youtube.com/watch?v=9poxfAcbxFQ



me interested implementation of algorithm in language C#
 

jmcilhinney

C# Forum Moderator
Staff member
Joined
Apr 23, 2011
Messages
2,230
Location
Sydney, Australia
Programming Experience
10+
If you know how to write C# code, attempt to implement the algorithm yourself and then post here if and when you encounter a specific issue. If you don't know how to write C# code, you need to learn that first. There's a tutorial link in my signature below. You can then attempt to implement the algorithm and post back here if and when you encounter an actual issue.
 

DANILIN

Member
Joined
Oct 19, 2018
Messages
14
Programming Experience
10+
There is a super sorting visualization
comparing 2 sortings simultaneously.

This program is written in an unknown language.
And I guess the source code is: CSharp

? given code Csharp ?

Code:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Windows.Forms;

namespace SortComparison
{
    static class Program
    {
        /// <summary>
        /// The main entry point for the application.
        /// </summary>
        [STAThread]
        static void Main()
        {
            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);
            Application.Run(new frmMain());
        }
    }
}
? given code Csharp ?

 

DANILIN

Member
Joined
Oct 19, 2018
Messages
14
Programming Experience
10+
Russian Sorting Halves and fast and human
sorts 1'000'000 in 0.2 seconds on C# Csharp

Code:
// RUSSIAN SORTING HALVES DANILIN
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;
namespace davApp
{
    class Program
    {
        private long age;
        static long[] a;
        static long[] d;

        static void Main(string[] args)
        {
            int n = 0;
            // READ NUMBERS
            var inpFile = new StreamReader("N.txt");
            n = Convert.ToInt32(inpFile.ReadLine());
            inpFile.Close();

            var age = 1 + Math.Log(n) / Math.Log(2);

            Console.WriteLine(n);

            a = new long[n + 1];
            d = new long[n + 1];

            for (int i = 1; i <= n; i++)
                d[i] = n - i + 1;

            //var rand = new Random();
            //// RANDOM [1;n]
            //for (int i = 1; i <= n; i++)
            //    d[i] = rand.Next(1, n);

            // REAN N LINE FROM FILE
            //inpFile = new StreamReader("ISX.txt");
            //for (int i = 1; i <= n; i++)
            //    d[i] = Convert.ToInt64(inpFile.ReadLine());
            //inpFile.Close();

            // WRITE ON SCREEN
            int m = Math.Min(n, 20);
            for (int i = 1; i <= m; i++)
                Console.Write("{0} ", d[i]);
            Console.WriteLine();

            // RUSSIAN SORTING HALVES DANILIN
            var start = DateTime.Now;
            if (age > 0)
                dav(1, n, 1, age);
            var finish = DateTime.Now;

            Console.WriteLine("{0} second", (finish - start).TotalSeconds);

            // WRITE ON SCREEN
            Console.WriteLine("[1..{0}]", m);
            for (int i = 1; i <= m; i++)
                Console.Write("{0} ", d[i]);
            Console.WriteLine();

            // WRITE ON SCREEN
            Console.WriteLine("[{0}..{1}]", n - m + 1, n);
            for (int i = n - m + 1; i <= n; i++)
                Console.Write("{0} ", d[i]);
            Console.WriteLine();

            // WRITE IN FILE
            var outFile = new StreamWriter("dav.txt");
            for (int i = 1; i <= m; i++)
                outFile.WriteLine(d[i]);
            outFile.WriteLine();

            for (int i = n - m + 1; i <= n; i++)
                outFile.WriteLine(d[i]);
            outFile.WriteLine();
            outFile.Close();

            Console.WriteLine("Press any key");
            Console.ReadKey();
        }

        static void dav(int ab, int yz, int part, double age)
        {
            if (yz - ab < 1)
                return;

            long summa = 0;
            for (int i = ab; i <= yz; i++)
                summa = summa + d[i];

            double middle = summa / (yz - ab + 1.0);

            var abc = ab - 1;
            var xyz = yz + 1;

            for (int i = ab; i <= yz; i++)
                if (d[i] < middle)
                {
                    abc = abc + 1;
                    a[abc] = d[i];
                }
                else
                {
                    xyz = xyz - 1;
                    a[xyz] = d[i];
                }

            for (int i = ab; i <= yz; i++)
                d[i] = a[i];

            if (part < age)
            {
                if (abc >= ab) dav(ab, abc, part + 1, age);
                if (xyz <= yz) dav(xyz, yz, part + 1, age);
            }
            return;
        }
   }
}
Russian Sorting Halves and fast and human
sorts 1'000'000 in 2.2 seconds on QB64
sorts 1'000'000 in 0.3 seconds on PureBasic
sorts 1'000'000 in 0.2 seconds on C# Csharp
sorts 1'000'000 in 0.15 seconds on Freebasic
 
Last edited:

DANILIN

Member
Joined
Oct 19, 2018
Messages
14
Programming Experience
10+
applying inside my above C# program
bubble sort inside time control
with removing recursion

results: 100'000 sorted 60 seconds bubble

at same time it proves how easy it is to adapt my development
to test any sorting algorithms using 3 methods

however 100,000 items
Russian sorting halves sorts in 0.015 seconds

rshemblems.png
 

DANILIN

Member
Joined
Oct 19, 2018
Messages
14
Programming Experience
10+
a 4 times acceleration proof

Code:
// Russian Sorting Halves 4 part accelerate bubble sorting 
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace octoberApp
{
    class Program
    {
        static int n;
        static double[] d;
        static double[] a;
        static double[] v;
        static int[] q;

        static void Main(string[] args)
        {
            n = 57539; 

            d = new double[n+1];
            a = new double[n+1];
            v = new double[n+1];
            q = new int[5+1];
            var rand = new Random();
            for (int i = 1; i <= n; i++)
                d[i] = Math.Truncate(rand.NextDouble() * n);

            for (int i = 1; i <= 10; i++)
                Console.Write("{0} ", d[i]);
            Console.WriteLine();

            for (int i = n - 9; i <= n; i++)
                Console.Write("{0} ", d[i]);
            Console.WriteLine();
            Console.WriteLine();

            var start = DateTime.Now;
            var s = 0;
            //ALL
            double summa = 0;
            for (int i = 1; i <= n; i++)
                summa += d[i];
            double middle = summa / n;
            var y = 1;
            var z = 0;

            for (int i = 1; i <= n; i++)
                if (d[i] < middle)
                {
                    a[y] = d[i]; y++;
                }
                else
                {
                    a[n - z] = d[i];
                    z++;
                }

            q[3] = y - 1;
            Console.WriteLine("ALL middle = {0}", middle);

            for (int i = 1; i <= 10; i++)
                Console.Write("{0} ", a[i]);
            Console.WriteLine();
            Console.WriteLine();
            for (int i = n - 9; i <= n; i++)
                Console.Write("{0} ", a[i]);
            Console.WriteLine();
            Console.WriteLine();

            // 1 FROM 2
            summa = 0;
            for (int i = 1; i <= q[3]; i++)
                summa += a[i];

            middle = summa / q[3];
            y = 1;
            z = 0;
            Console.WriteLine("1 FROM 2 = {0} 1 ...{1}", middle, q[3]);

            for (int i = 1; i <= q[3]; i++)
                if (a[i] < middle)
                {
                    v[y] = a[i]; y++;
                }
                else
                {
                    v[q[3] - z] = a[i];
                    z++;
                }

            for (int i = 1; i <= 10; i++)
                Console.Write("{0} ", v[i]);
            Console.WriteLine();
            for (int i = q[3] - 9; i <= q[3]; i++)
                Console.Write("{0} ", v[i]);
            Console.WriteLine();
            Console.WriteLine();

            q[2] = y - 1;

            // 2 FROM 2
            summa = 0;
            for (int i = q[3] + 1; i <= n; i++)
                summa += a[i];
            middle = summa / (1 + n - q[3]);
            y = q[3];
            z = 0;
            Console.WriteLine("2 FROM 2 = {0} {1}...{2}", middle, q[3] + 1, n);
            for (int i = q[3]; i <= n; i++)
                if (a[i] < middle)
                {
                    v[y] = a[i]; y++;
                }
                else
                {
                    v[n - z] = a[i];
                    z++;
                }
            for (int i = q[3]; i <= q[3] + 10; i++)
                Console.Write("{0} ", v[i]);
            Console.WriteLine();
            for (int i = n - 9; i <= n; i++)
                Console.Write("{0} ", v[i]);
            Console.WriteLine();
            Console.WriteLine();

            q[4] = y - 1;
            q[1] = 2;
            q[5] = n;

            //BUBBLE
            Console.WriteLine("1= {0} 2= {1} 3= {2} 4= {3} 5= {4}", 1, q[2], q[3], q[4], n);
            Console.WriteLine();

            for (int t = 1; t <= 4; t++)
                for (int i = q[t] - 1; i <= q[t + 1]; i++)
                    for (int j = i + 1; j <= q[t + 1]; j++)
                        if (v[i] > v[j])
                        {
                            var x = v[i];
                            v[i] = v[j];
                            v[j] = x;
                            s++;
                        }

            var finish = DateTime.Now;

            for (int i = 1; i <= 10; i++)
                Console.Write("{0} ", v[i]);
            Console.WriteLine();

            for (int i = n - 9; i <= n; i++)
                Console.Write("{0} ", v[i]);
            Console.WriteLine();
            Console.WriteLine();
            Console.WriteLine("DArus4 {0} second swap {1}", (finish - start).TotalSeconds, s);

            var outFile = new System.IO.StreamWriter("RUoct.txt");
            outFile.WriteLine("DArus4 {0} second swap {1}", (finish - start).TotalSeconds, s);
            outFile.WriteLine("{0} 4 parts bubble ", n);

            for (int i = 1; i <= n / 2; i++)
                outFile.WriteLine(v[i]);
            for (int i = n / 2; i <= n; i++)
                outFile.WriteLine(v[i]);

            outFile.Close();

            start = DateTime.Now;
            s = 0;

            for (int i = 1; i <= n; i++)
                for (int j = i + 1; j <= n; j++)
                    if (d[i] > d[j])
                    {
                        var x = d[i];
                        d[i] = d[j];
                        d[j] = x;
                        s++;
                    }
            finish = DateTime.Now;

            Console.WriteLine("BUBBLE {0} second swap {1}", (finish - start).TotalSeconds, s);

            Console.WriteLine("Press any key");
            Console.ReadKey();
        }
    }
}
a 4 times acceleration proof

da44bubble.pngdivision of array into 4 parts occurs instantly
name q(3) will be replaced by a simpler name

but separation attempts for 2 nested loops
broken about order of midpoints 3 2 4

which leads to arrays with 2nd brackets
which complicates understanding and better apply

speaking variables of type middle3
leaving 3 cycles separate
 
Last edited:

DANILIN

Member
Joined
Oct 19, 2018
Messages
14
Programming Experience
10+
We learn C# knowing Basic & Excel & qb64

? Why C# & Basic & Excel & qb64?
because C# & qb64 are compiled

I have a C# csc.exe compiler in Win7
and compile through an individual bat

Excel: even micro-sized environments
Basic: qb64 compatible with Win7

qb64 quadratic equation:

C#:
' quadratic equation QB64 DAV
INPUT "INPUT A"; A
INPUT "INPUT B"; B
INPUT "INPUT C"; C

D = B ^ 2 - 4 * A * C
IF D < 0 THEN PRINT "D<0 ": END

PRINT "ANSWER: "
PRINT "D ="; D

X1 = (-B + SQR(D)) / (2 * A)
X2 = (-B - SQR(D)) / (2 * A)
PRINT "X1 ="; X1
PRINT "X2 ="; X2
END
C# quadratic equation without checking d<0:

C#:
// quadratic equation C# DAV
using System;
using System.Text;
using System.IO;
namespace DAV
{
    class Program
        {
    static void Main(string[] args)
    {
Console.Write("INPUT A: ");
long a = Convert.ToInt32(Console.ReadLine());
Console.Write("INPUT B: ");
long b = Convert.ToInt32(Console.ReadLine());
Console.Write("INPUT C: ");
long c = Convert.ToInt32(Console.ReadLine());

long d = (b * b - 4 * a * c);
Console.WriteLine("ANSWER: ");
Console.Write("D = ");
Console.WriteLine(d);

var x1 = (-b + Math.Sqrt(d)) / (2 * a);
var x2 = (-b - Math.Sqrt(d)) / (2 * a);

Console.Write("X1 = ");
Console.WriteLine(x1);
Console.Write("X2 = ");
Console.WriteLine(x2);

        Console.ReadKey();
        }
    }
}
excel quadratic equation without checking d<0:
excel: copy and paste in A1

C#:
6
7
2
=A2^2-4*A1*A3
=(-A2+(A4^(1/2)))/(2*A1)
=(-A2-(A4^(1/2)))/(2*A1)
further need to examine conditions
creating a toy "guess number"
 
Last edited by a moderator:

DANILIN

Member
Joined
Oct 19, 2018
Messages
14
Programming Experience
10+
qb64 for 1 minute created main lines and for minutes issued
C# in 3 hours created by internet tips with new ideas

Code:
'qb64 dav guess number from 0 to 100 with counting of steps 
RANDOMIZE TIMER
s = INT(RND * 100)
t = 0

10 PRINT: t = t + 1:
INPUT "your variant"; a

IF a < s THEN PRINT "need MORE": GOTO 10
IF a > s THEN PRINT "need less": GOTO 10
PRINT "win by"; t; "steps"
END
Code:
'//C# dav guess number from 0 to 100 with counting of steps 
using System;
using System.Text;
namespace DAV 
{
    class Program
        {
    static void Main(string[] args) 
    {
Random rand = new Random();
int s = rand.Next(100);
int t = 0;

dav:
Console.WriteLine();
t++;

Console.Write("your variant ");
string d = Console.ReadLine();
int a = Convert.ToInt32(d);

if(a > s)
    {
    Console.WriteLine("need less");
    goto dav;
    }
else if(a < s)
    {
    Console.WriteLine("need MORE");
    goto dav;
    }
Console.Write("win by ");
Console.Write(t);
Console.Write(" steps"); 
        Console.ReadKey();
        }
    }
}
 

DANILIN

Member
Joined
Oct 19, 2018
Messages
14
Programming Experience
10+
Code:
'milliard & billion qb64 DAV guess 1 number of 1'OOO'000'ooo by 30 steps

RANDOMIZE TIMER
h2 = INT(RND * 10 ^ 9)
h1 = 0
c = INT(RND * h2) 'comp
h = INT(RND * h2) 'human
t = 0

10 t = t + 1
PRINT t, c, h,

IF h < c THEN PRINT "MORE": a = h: h = INT((h + h2) / 2): h1 = a: GOTO 10
IF h > c THEN PRINT "less": a = h: h = INT((h1 + h) / 2): h2 = a: GOTO 10
PRINT "win by "; t; " steps"
END
C# compiler feature noticed
remark that there is a mistake at beginning of program
may mean a lack of characters } at end

example for a range from 0 to 100
Code:
1    40    11    MORE
2    40    55    less
3    40    33    MORE
4    40    44    less
5    40    38    MORE
6    40    41    less
7    40    39    MORE
8    40    40    win by 8 steps
BasiC# qbc# C##

Online C# compiler detected
and dozens more languages without qbasic
working without registration

and there typing program is possible
save state with program

for example program C # Billion
guessing 1 of 1'000'OOO'ooo
=log(10^9;2) in 30 moves

rextester.com/JRGX29275

Code:
//milliard & billion C# DAV guess 1 number of 1000000000 by 30 steps 
using System;
using System.Text;
namespace DAV
{
    class Program
    {
    static void Main(string[] args)
    {
int h2 = 1000000000;//or 500
int h1 = 0;
Random rand = new Random();
int c = rand.Next(h2); //computer
int h = rand.Next(h2); //human or h2/2;
int t = 0;

dav:
t++;
Console.WriteLine();
Console.Write(t);
Console.Write("  ");
Console.Write(c);
Console.Write("  ");
Console.Write(h);
Console.Write("  ");

if(h < c)
    {
    Console.Write("MORE");
    int a = h;
    h = (h + h2) / 2;
    h1 = a;
    goto dav;
    }
else if(h > c)
    {
    Console.Write("less");
    int a = h;
    h = (h1 + h) / 2;
    h2 = a;
    goto dav;
    }
Console.Write("win by ");
Console.Write(t);
Console.Write(" steps");
        Console.ReadKey();
        }
    }
}
Searching see programs stored ... 5 years
and for certain still there is an online compiler C#
and really are through Yandex search

but since interested in graphics
while I use cs & bat
 

DANILIN

Member
Joined
Oct 19, 2018
Messages
14
Programming Experience
10+
we draw 5D relief creating a random array of heights

on QB64 in 5 minutes and plus in an hour
beauty and versatility



Code:
' 5d relief and array
SCREEN 12: RANDOMIZE TIMER: DIM a(12,12)
FOR t=1 TO 12 ' quantity
    FOR x=1 TO 12: FOR y=1 TO 12
a(x,y)=INT(RND*20)'heights
    NEXT: NEXT: CLS
    FOR y=1 TO 12: FOR x=1 TO 11
LINE (50+20*x+20*y, 400-20*y-a(x,y))-(50+20*(x+1)+20*y, 400-20*y-a(x+1,y)), y
    NEXT: NEXT
    FOR x=1 TO 12: FOR y=1 TO 11
LINE (50+20*x+20*y, 400-20*y-a(x,y))-(50+20*(x+1)+20*y, 400-20*(y+1)-a(x,y+1)), x
    NEXT: NEXT:SLEEP 1
NEXT
END
on C# pendulum program is used
because of what remained incomprehensible lines about timer
and random function depends on outside / inside cycles
and to understand another program created random

how to clear screen is still unclear and builds slowly
and it is unclear how to set color of lines by variables



still as task manager shows
simple C# program or array fills memory
and only at end does memory clear line save

Code:
//RELIEF
using System;
using System.Drawing;
using System.Windows.Forms;
class RELIEF
{
Timer timer; // it is not clear
Form form;
    
int[,] a = new int[22, 22];
static void Main(string[] args) 
{
var p = new RELIEF();
}
public RELIEF()
{
    form = new Form() { Text = "RELIEF", Width = 600, Height = 360 };
    timer = new Timer() { Interval = 200 }; // it is not clear
    timer.Tick += delegate(object sender, EventArgs e) // it is not clear
    {
    Random rand = new Random();
// heights
    for (int x = 1; x <=12; x++)
    {
    for (int y = 1; y <=12; y++)
    a[x,y]=rand.Next(20);
    }
// parallels X
    for (int y = 1; y <=12; y++)
    {
    for (int x = 1; x <=11; x++)
        {
    var x1 = 50 + 20*x + 20*y; 
    var y1 = 300 - 20*y - a[x,y];
    var x2 = 50 + 20*(x+1) + 20*y;
    var y2 = 300 - 20*y - a[x+1,y];

    Bitmap dblBuffer = new Bitmap(form.Width, form.Height);
    Graphics g = Graphics.FromImage(dblBuffer);
    Graphics f = Graphics.FromHwnd(form.Handle);

    g.DrawLine(Pens.Red, new Point(x1, y1), new Point(x2, y2));
//    f.Clear(Color.Green); // clear screen
    f.DrawImage(dblBuffer, new Point(0, 0));
     }
    }
// parallels Y
    for (int x = 1; x <=12; x++)
    {
    for (int y = 1; y <=11; y++)
    {
    var x1 = 50 + 20*x + 20*y; 
    var y1 = 300 - 20*y - a[x, y];
    var x2 = 50 + 20*(x+1) + 20*y;
    var y2 = 300 - 20*(y+1) - a[x, y+1];

    Bitmap dblBuffer = new Bitmap(form.Width, form.Height);
    Graphics g = Graphics.FromImage(dblBuffer);
    Graphics f = Graphics.FromHwnd(form.Handle);

    g.DrawLine(Pens.Red, new Point(x1, y1), new Point(x2, y2));
//    f.Clear(Color.Green); // clear screen
    f.DrawImage(dblBuffer, new Point(0, 0));
    }
    }
Array.Clear(a, 0, 22); // clears memory
    };
    timer.Start(); // it is not clear
    Application.Run(form);
    }     
}
besides C# pendulum is C # diagonal simpler
and no other C# program is included
so as in basic: 1 file = 1 program

that's why my given 5D relief program is important.
drawing at least something predictable
and at same time we study nested loops

and I'm still looking for compilable graphics programs:

1 file = 1 program
1bas=1exe & 1cs=1exe

and already created studies about strings
 

DANILIN

Member
Joined
Oct 19, 2018
Messages
14
Programming Experience
10+
it is question of drawing characters
is directly related to this topic

because the following is an animation
on example of movement of characters



animation "Cat Basic" and further parameterization is possible

Code:
//cat.cs
using System; 
using System.Drawing;
using System.Windows.Forms;

class cat: Form
    {
    public static void Main()
    {
    Application.Run(new cat());
    }
    public cat()
        {
        Text = "cat";
    BackColor = System.Drawing.Color.Blue;
    ForeColor = System.Drawing.Color.Red;
        ResizeRedraw = true;
        Width = 600;
        Height = 360;
        }
    protected override void OnPaint(PaintEventArgs dan)
        {
Pen pen = new Pen(ForeColor);
SolidBrush redBrush = new SolidBrush(Color.Blue);
Graphics dav = dan.Graphics;

    for (int k = 1; k <=5; k++)
    for (int x = -50; x <=50; x++)
    {
int y=0;
if (x< 50) y=-x/5;
if (x< 25) y= x/5;
if (x<-25) y=-x/5;
if (x<-50) y= x/5;

dav.FillRectangle(redBrush, 0, 120, 600, 200);

dav.DrawEllipse(new Pen(Color.Magenta, 3), x*k+195, 225, 10, -80);
dav.DrawEllipse(new Pen(Color.Magenta, 3), x*k+200, 200, 100, 50);
dav.DrawEllipse(new Pen(Color.Magenta, 3), x*k+280, y+170, 50, 50);

dav.DrawEllipse(new Pen(Color.Magenta, 3), x*k+290, y+190, 10, 10);//x/5, x/5
dav.DrawEllipse(new Pen(Color.Magenta, 3), x*k+294, y+194, 2, 2);
dav.DrawEllipse(new Pen(Color.Magenta, 3), x*k+310, y+190, 10, 10);//x/5, x/5
dav.DrawEllipse(new Pen(Color.Magenta, 3), x*k+314, y+194, 2, 2);

dav.DrawEllipse(new Pen(Color.Magenta, 3), x*k+280, y+205, 25, 10);
dav.DrawEllipse(new Pen(Color.Magenta, 3), x*k+310, y+205, 25, 10);

dav.DrawLine(new Pen(Color.Magenta, 3), new Point(x*k+280, y+190), new Point(x*k+280, y+160));
dav.DrawLine(new Pen(Color.Magenta, 3), new Point(x*k+290, y+175), new Point(x*k+280, y+160));
dav.DrawLine(new Pen(Color.Magenta, 3), new Point(x*k+330, y+190), new Point(x*k+330, y+160));
dav.DrawLine(new Pen(Color.Magenta, 3), new Point(x*k+320, y+175), new Point(x*k+330, y+160));

dav.DrawLine(new Pen(Color.Magenta, 3), new Point(x*k+210, 240), new Point(x*k+210, 280));
dav.DrawLine(new Pen(Color.Magenta, 3), new Point(x*k+220, 230), new Point(x*k+220, 290));
dav.DrawLine(new Pen(Color.Magenta, 3), new Point(x*k+280, 230), new Point(x*k+280, 290));
dav.DrawLine(new Pen(Color.Magenta, 3), new Point(x*k+290, 240), new Point(x*k+290, 280));

dav.DrawEllipse(new Pen(Color.Magenta, 3), x*k+205, 275, 10, 10);
dav.DrawEllipse(new Pen(Color.Magenta, 3), x*k+215, 285, 10, 10);
dav.DrawEllipse(new Pen(Color.Magenta, 3), x*k+275, 285, 10, 10);
dav.DrawEllipse(new Pen(Color.Magenta, 3), x*k+285, 275, 10, 10);

System.Threading.Thread.Sleep(10);
}
}
}
 
Last edited:

DANILIN

Member
Joined
Oct 19, 2018
Messages
14
Programming Experience
10+
using example of collection of programs
and compile hint get program

quadratic equation



Code:
//winquall.cs
using System;
using System.Windows.Forms;
using System.IO;

class winQUAll : Form
{
winQUAll()
{
Text= "winQUAll A=6 B=7 C=2";
BackColor = System.Drawing.Color.Green;
ForeColor = System.Drawing.Color.White;
ResizeRedraw = true;
Width = 400;
Height = 250;
{
var buttons = new Button();
buttons.Text= "SAVE";
buttons.Dock = DockStyle.Top;
    var zc = -7;
    var labelc = new Label();
    var buttonc = new Button();
    buttonc.Text= "C+3";
    buttonc.Dock = DockStyle.Bottom;
var zb = 12;
var labelb = new Label();
var buttonb = new Button();
buttonb.Text= "B-1";
buttonb.Dock = DockStyle.Bottom;
    var za = 2;
    var labela = new Label();
    var buttona = new Button();
    buttona.Text= "A+1";
    buttona.Dock = DockStyle.Bottom;
var labelx = new Label();
    var d = (zb * zb - 4 * za * zc);
    double x1 = (-zb + Math.Sqrt(d)) / (2 * za);
    double x2 = (-zb - Math.Sqrt(d)) / (2 * za);
    var labeld = new Label();
labeld.Text= "d= " + d +"   X1= " + x1 + "   X2= " + x2 + "  ";
labeld.Dock = DockStyle.Top;
x1 = (Math.Truncate(x1 * 100))/100;
x2 = (Math.Truncate(x2 * 100))/100;
    //labeld.Location = new System.Drawing.Point(80, 15);
labelx.Text= "X1=" + x1 + " X2=" + x2 + "  ";
labelx.Location = new System.Drawing.Point(125, 125);
Controls.Add(labeld);
Controls.Add(labelx);
    labelc.Text= "C=" + zc + ".....";
    labelc.Location = new System.Drawing.Point(20, 100);
Controls.Add(labelc);
buttonc.Click += delegate
    {
    zc = zc+3;
    d = (zb * zb - 4 * za * zc);
    x1 = (-zb + Math.Sqrt(d)) / (2 * za);
    x2 = (-zb - Math.Sqrt(d)) / (2 * za);
labeld.Text= "d= " + d +"   X1= " + x1 + "   X2= " + x2 + "  ";
labeld.Dock = DockStyle.Top;
x1 = (Math.Truncate(x1 * 100))/100;
x2 = (Math.Truncate(x2 * 100))/100;
    //labeld.Location = new System.Drawing.Point(80, 15);
labelx.Text= "X1=" + x1 + " X2=" + x2 + "  ";
labelx.Location = new System.Drawing.Point(125, 125);
labelc.Text= "C=" + zc + "  ...";
labelc.Location = new System.Drawing.Point(20, 100);
    };
Controls.Add(buttonc);
Controls.Add(labeld);
Controls.Add(labelx);
    labelb.Text= "B=" + zb + ".....";
    labelb.Location = new System.Drawing.Point(50, 80);
Controls.Add(labelb);
buttonb.Click += delegate
    {
    zb--;
    d = (zb * zb - 4 * za * zc);
    x1 = (-zb + Math.Sqrt(d)) / (2 * za);
    x2 = (-zb - Math.Sqrt(d)) / (2 * za);
labeld.Text= "d= " + d +"   X1= " + x1 + "   X2= " + x2 + "  ";
labeld.Dock = DockStyle.Top;
x1 = (Math.Truncate(x1 * 100))/100;
x2 = (Math.Truncate(x2 * 100))/100;
    //labeld.Location = new System.Drawing.Point(80, 15);
labelx.Text= "X1=" + x1 + " X2=" + x2 + "  ";
labelx.Location = new System.Drawing.Point(125, 125);
labelb.Text= "B=" + zb + "  ...";
labelb.Location = new System.Drawing.Point(50, 80);
    };
Controls.Add(buttonb);
Controls.Add(labeld);
Controls.Add(labelx);
    labela.Text= "A=" + za + ".....";
    labela.Location = new System.Drawing.Point(80, 60);
Controls.Add(labela);
buttona.Click += delegate
    {
    za++;
    d = (zb * zb - 4 * za * zc);
    x1 = (-zb + Math.Sqrt(d)) / (2 * za);
    x2 = (-zb - Math.Sqrt(d)) / (2 * za);
labeld.Text= "d= " + d +"   X1= " + x1 + "   X2= " + x2 + "  ";
labeld.Dock = DockStyle.Top;
x1 = (Math.Truncate(x1 * 100))/100;
x2 = (Math.Truncate(x2 * 100))/100;
    //labeld.Location = new System.Drawing.Point(80, 15);
labelx.Text= "X1=" + x1 + " X2=" + x2 + "  ";
labelx.Location = new System.Drawing.Point(125, 125);
labela.Text= "A=" + za + "  ...";
labela.Location = new System.Drawing.Point(80, 60);
    };
Controls.Add(buttons);
buttons.Click += delegate
    {
var outFile = new StreamWriter("dan.txt");
outFile.WriteLine(za);
outFile.WriteLine(zb);
outFile.WriteLine(zc);
outFile.WriteLine(d);
outFile.WriteLine(x1);
outFile.WriteLine(x2);
outFile.Close();
    };
Controls.Add(buttona);
Controls.Add(labeld);
Controls.Add(labelx);
    };
}
    static void Main()
    {
Application.Run(new winQUAll());
    }
}
1cs=1exe

and then I test engines and windows inside of window
 
Last edited:

DANILIN

Member
Joined
Oct 19, 2018
Messages
14
Programming Experience
10+


Application reads from windows
set or assigned values
and creates calculations and design
using data given
further planned graphics in form

Code:
//SUMCOMB.cs
using System; 
using System.Drawing;
using System.Windows.Forms;
namespace SUMCOMB
{
    public class Program
    {
    static void Main()
    {
Application.Run(new SUMCOMB());
    }
    }
    class SUMCOMB : Form
    {
    ComboBox comboBoxD;
    TextBox textBoxA; 
    Button buttonV;

public SUMCOMB()
    {
var labelD = new Label();
    labelD.Text = "D СТРОК";
    labelD.Location = new System.Drawing.Point(45, 28);
    Controls.Add(labelD);

comboBoxD = new ComboBox();
    comboBoxD.Location = new Point(45, 50);
    comboBoxD.Width = 50;
    comboBoxD.Items.Add("7");
    comboBoxD.Items.Add("5");
    comboBoxD.Items.Add("3");
    comboBoxD.SelectedIndex = 1;
    this.Controls.Add(comboBoxD);

var labelA = new Label();
    labelA.Text = "A СТОЛБЦОВ";
    labelA.Location = new System.Drawing.Point(45, 78);
    Controls.Add(labelA);

textBoxA=new TextBox();
    textBoxA.Text = "4"; 
    textBoxA.Location = new System.Drawing.Point(45, 100);
    this.Controls.Add(textBoxA); 

buttonV = new Button();    
    buttonV.Location = new System.Drawing.Point(45, 200);
    buttonV.Text = "SUMCOMB";
    buttonV.Click+=buttonV_Click;
    Controls.Add(buttonV);
}

private void buttonV_Click(object sender, EventArgs e)
    {
    int dd = int.Parse(comboBoxD.Text);
    int aa = int.Parse(textBoxA.Text);
for (int i = 1; i <= dd; i++)
{
string s= "";
for (int j = 1; j <= aa; j++)
s = s+"  "+(i+j).ToString();
var labelI = new Label();
labelI.Text = s;
labelI.Location = new System.Drawing.Point(145, 25+25*i);
Controls.Add(labelI);
}
        }
    }
}
 
Last edited:

DANILIN

Member
Joined
Oct 19, 2018
Messages
14
Programming Experience
10+
Data transfer between programs
specifically 1 sign: number of nodes



Code:
//GRAF11.cs
using System; 
using System.IO;
using System.Drawing;
using System.Diagnostics;
using System.Windows.Forms;
namespace GRAF11
{
    public class Program
{
static void Main()
    {
Application.Run(new GRAF11());
    }
    }
    class GRAF11 : Form 
    {
int[] x = new int[10];
int[] y = new int[10];
Random rand = new Random();
ComboBox comboBoxD;
Button buttonA;

    public GRAF11()
    {
comboBoxD = new ComboBox();
    comboBoxD.Location = new Point(45, 50);
    comboBoxD.Width = 50;
    comboBoxD.Items.Add("7");
    comboBoxD.Items.Add("5");
    comboBoxD.Items.Add("3");
    comboBoxD.SelectedIndex = 1;
buttonA = new Button();    
    buttonA.Location = new System.Drawing.Point(30, 80);
    buttonA.Text = "START";
    buttonA.Click+=buttonA_Click;
var labelV = new Label();
    labelV.Text = "CIRCLES";
    labelV.Location = new System.Drawing.Point(45, 28);
Controls.Add(comboBoxD);
Controls.Add(buttonA);
Controls.Add(labelV);
    }
private void buttonA_Click(object sender, EventArgs e)
    {
for (int i = 1; i <10; i++)
        {
x[i]=150+rand.Next(100);
y[i]=20+rand.Next(100);
        }
var outFile = new StreamWriter("dan.txt");
outFile.WriteLine(comboBoxD.Text);
for (int i = 1; i <10; i++)
        {
outFile.WriteLine(x[i]);
outFile.WriteLine(y[i]);
        }
outFile.Close();

    Process.Start("GRAF22.exe");
        }
    }
}
Code:
//GRAF22.cs
using System;
using System.IO;
using System.Drawing;
using System.Windows.Forms;
namespace GRAF22
{
    public class Program
{
static void Main()
    {
Application.Run(new GRAF22());
    }
}
    class GRAF22 : Form
    {
int[] x = new int[10];
int[] y = new int[10];
int[] z = new int[2];

    public GRAF22()
    {
var inpFile = new StreamReader("dan.txt");

z[1] = Convert.ToInt32(inpFile.ReadLine());

for (int i = 1; i <10; i++)
        {
x[i] = Convert.ToInt32(inpFile.ReadLine());
y[i] = Convert.ToInt32(inpFile.ReadLine());
        }
inpFile.Close();
}

protected override void OnPaint(PaintEventArgs dav)
    {
Graphics da = dav.Graphics;
Pen pen = new Pen(ForeColor);
for (int i = 1; i <= z[1]; i++)
da.DrawEllipse(new Pen(Color.Magenta, i), x[i]-5, y[i]-5, 10, 10);

for (int i = 1; i <= z[1]-1; i++)
for (int j = i+1; j <= z[1]; j++)
    {
da.DrawLine(new Pen(Color.Red, i), new Point(x[i], y[i]), new Point(x[j], y[j]));
System.Threading.Thread.Sleep(150);
    }
        }
    }
}
 
Last edited:
Top Bottom