Multi-Platform Open-Source sm_calculator (SM Calculator) tool 0.0.1.1

Multi-Platform Open-Source sm_calculator (SM Calculator) tool 0.0.1.1 has been released.

Supported platforms:

  • Windows (x86, x86_64)
  • Linux (x86, x86_64)
  • Examples, the suite of sm_calc_test.in.XX.txt and sm_calc_test.out.XX.txt (also you can find the suite of sm_calc_test.in.XX.txt and sm_calc_test.out.XX.txt in directory /tests in sources):
    Examples

Verification of downloaded files:
—————-

GPG Public Key (SManSoft ECDSA Key) <info@smansoft.com> has been published here: http://smansoft.com/gpg/smansoft.pub.asc.
SM Calculator – 0.0.1.1 contains suite of [some_install_file].asc files.
Please, use:
gpg --import ./smansoft.pub.asc
for importing of key and
gpg --verify ./[some_install_file].asc ./[some_install_file]
or
gpg --verify ./[some_install_file].asc
for verification of files, published on this site.
Public GPG ECDSA Key can be imported, using
gpg --keyserver hkp://pgp.mit.edu --recv-keys A408B0FCFD774649
too.

Features of the sm_calculator (SM Calculator) tool 0.0.1.1:
—————-

  • Multi-platform application: there are builds for Windows 64/32 (.zip) and Linux 64/32 (.tar.gz);
  • Various types of values (64 bits integers, 64 bits floats, strings);
  • Various float constants (pi, exp,…);
  • Solving of mathematical expressions, using basic arithmetic operators;
  • Solving of mathematical expressions, using bracket delimiters ‘(‘ and ‘)’ (in one expression) and delimiters ‘;’, ‘\n’;
  • Solving using suite of mathematical (including trigonometric, logarithm, exponentiation) functions;
  • Solving using bitwise functions and operators;
  • Various types of entering and output formats of integers (decimal, octal, hexadecimal, binary formats);
  • Various values of the unit for measuring of angles (radians, degrees, gradians), which are used by trigonometric functions;
  • Support of output properties (precision) of float values;
  • The suite of converting functions (various values of the unit for measuring of angles, various types of entering and output formats of integers);
  • the suite of commands, which provide setup of the configuration of SM Calculator;
  • Several modes of execution (processing of files, processing of expressions, obtained via command line, processing of expressions in interactive mode, using standard input/output devices);
  • Help (command: help[;] or command-line option: -h, –help);

SM Calculator tool supports following modes of execution:
—————-

  • processing of the file, that contains expression(s);
  • processing of command-line expression(s);
  • interactive mode (user enters expression(s), using standard input device/console).

A user can use the same expressions in all these modes (processing of the file,
processing of command-line expression(s), interactive mode). I.e. SM Calculator tool supports the same lexemes and grammar rules in all modes.

Please, read ReadMe.txt for more info about launching the SM Calculator tool in modes of execution.

Limitations/disadvantages of the sm_calculator (SM Calculator) tool 0.0.1.1:
—————-

  • sm_calculator (SM Calculator) tool 0.0.1.1 (after launching) creates/opens log file: ./sm_calc.log  in the current directory. I.e. user should take into account, that ./sm_calc.log  will be created/updated in the current directory;
  • sm_calculator (SM Calculator) tool 0.0.1.1  writes full log with detailed info without filtering of log messages by log level;
  • if you use Linux and launches sm_calculator from another directory, where sm_calc module is deployed (bin/sm-calc), you should copy file /lib/libgetopt_lib.so to one of the directories /usr/local/lib, /usr/lib or use follow launch of sm_calc:
    export LD_LIBRARY_PATH=/home/some_user/bin/sm_calculator/lib; /home/some_user/bin/sm_calculator/bin/sm_calc

These limitations/disadvantages of the sm_calculator (SM Calculator) tool 0.0.1.1 will be fixed/resolved in the next version.

Structure of binary archive (.zip or .tar.gz):
—————-

  • .zip (Windows):
    bin\
        sm_calc.exe
     share\smansoft\doc\
        HELP
        LICENSE
        README
  • .tar.gz (Linux):
    bin/
        sm_calc
    lib/
        libgetopt_lib.so
    share/smansoft/doc/
        HELP
        LICENSE
        README

Execution:
—————-
sm_calc[.exe]
without parameters launches SM Calculator in interactive mode (default mode):

sm_calc 0.0.1.1 Copyright (c) 2020 SManSoft
SM Calculator
     Interactive processing:
Type 'help' for more information.
In >>

User can run:
sm_calc[.exe] -h
or
sm_calc[.exe] --help
to get help output – description of command-line parameters.

Using these options a user can launch SM Calculator in various modes of execution and tune start values of the current configuration of SM Calculator (command: config[;]):

-h, --help
-i, --interactive
-f<infile>, --in_file=<infile>
-o<ofile>, --out_file=<ofile>
-x<expression_value>, --expression=<expression_value>
-p<precision_value>, --f_precision=<precision_value>
-n<i_format_value>, --i_format=<i_format_value>
-a<unit_value>, --a_unit=<unit_value>

Lexemes of SM Calculator expressions:
—————-

Available keywords:
f_precision i_format a_unit pi exp gamma phi rad deg grad grad2rad rad2grad rad2deg deg2rad grad2deg deg2grad dec oct hex bin dec2oct dec2hex dec2bin oct2dec hex2dec bin2dec sin cos tan asin acos atan ln lg log inv sqrt rand pow pow_exp^ pow_10^ pow_2^ pow_^2 abs mod mod2 and or not nand nor xor config help echo quit exit

Available operators:
+ - * / = ! <a< >a> <l< >l> <c< >c>

Available delimiters:
, ( ) ; \n (new line)

Commands (from available keywords):
f_precision i_format a_unit dec oct hex bin rad deg grad rand config help quit exit

Constants (from available keywords):
pi exp gamma phi

Output functions:
echo

Converting functions (from available keywords):
grad2rad rad2grad rad2deg deg2rad grad2deg deg2grad dec2oct dec2hex dec2bin oct2dec hex2dec bin2dec

Trigonometric functions (from available keywords):
sin cos tan asin acos atan

Logarithm functions (from available keywords):
ln lg log

Exponentiation functions:
pow pow_exp^ pow_10^ pow_2^ pow_^2

Bit functions (from available keywords):
and or not nand nor xor

Bit operators (from available operators):
<a< >a> <l< >l> <c< >c>

Base syntax of commands:
—————-
command[;]
command=arg[;]

Base syntax of functions:
—————-
function (arg1[,arg2])[;]

Base syntax of operators:
—————-
arg1 operator arg1[;]
operator arg[;]

Operator assign (‘=’) can be used only in commands (f_precision, i_format, a_unit).

Types of values:
—————-

  • Integer data (long long type – 64 bits);
  • Float data (long double type – 64 bits);
  • Strings (max length of string 1021 ASCII symbols);

Integer data:
—————-
Length of Integer data – 64 bits (including sign), i.e.
max integer value == 2^63-1;
min integer value == -(2^63-1);
Integer value can be entered and output in follow formats:

  • decimal (‘dec‘);
  • octal (‘oct‘);
  • hexadecimal (‘hex‘);
  • binary (‘bin‘);

The output format of integer value can be defined by command:
i_format = <dec|hex|oct|bin>[;]
A user can use shorter way for defining of the output format of an integer value, using commands:
dec[;]
hex[;]
oct[;]
bin[;]

The input format of an integer is defined by following rules:

  • if a user enters integer value in octal format, he should use as least one lead ‘0’ symbol (for example: ‘0712377’, ‘-0712377’);
  • if user enters integer value in hexadecimal format, he should use as lead ‘0x’ symbols (for example: ‘0x394ff’, ‘0xfffffffffffc6b01’);
  • if user enters integer value in binary format, he should use as lead ‘b’ symbol (for example:  ‘b00111001010011111111’‘b1111111111111111111111111111111111111111111111000110101100000001’);
  • if user enters integer value in decimal format, he shouldn’t use any additional symbols (for example: ‘129077’‘-129077’);

A user should take into account, that size of integer value is 64 bits (including sign), during entering value in various formats;

A user can enter negative values (in octal and hexadecimal) using as sign ‘-‘
as two’s complement format (see examples in the file ReadMe.txt):
-0712377 (oct) or 01777777777777777065401 (oct) == -234751 (dec)
-0x394ff (hex) or 0xfffffffffffc6b01 (hex) == -234751 (dec)

If user need to get current output format of integer values, he needs to use command:
i_format[;]

SM Calculator tool supports the suite of functions, which provide converting of various formats of integer values, whatever defined current output format of integer values:
dec2oct dec2hex dec2bin oct2dec hex2dec bin2dec.

Float data (long double – 64 bits):
—————-
The output format of float values always defined in decimal format. User can tune the precision of float value output, using the command:
f_precision = N[;]
, where N = [0,20]|exp, i.e. maximum precision of output of float value is ’20’.

Also, N can be defined as ‘exp’. In this case, the float value will be printed in an exponential format.

The input format of float values always defined in decimal format. A user can enter values as in floating form format as in exponential format.

If a user needs to get current output current precision of float, he needs to use the command:
f_precision[;].

Strings:
—————-
User should enter string value, using the following format:
"string_value" | 'string_value'.
Max length of the string – 1023 ASCII symbols with quotes(‘ or “)
or 1021 ASCII symbols without quotes(‘ or “).

String values aren’t used during calculations but could be used for the formatting of outputs in file processing, using the function
echo.

Default angle unit configuration:
—————-
SM calculator supports some suite of trigonometrical functions:
sin cos tan asin acos atan.
Also, SM calculator supports follow units for measuring of angles:

  • radians (‘rad‘)
  • degrees(‘deg‘)
  • gradians(‘grad‘)

SM Calculator tool contains the current configuration of the unit for measuring of angles. This parameter defines, which unit for measuring of angles will be used by trigonometric functions, i.e. if the current configuration of the unit for measuring of angles is radians, a user should use radians as parameters of trigonometric functions: sin(3.1415926536) or sin(pi), cos(1.5707963268) or cos(pi/2.0), if the current configuration of the unit for measuring of angles is degrees, a user should use degrees as parameters of trigonometric functions: sin(180.0), cos(90), same issue with the usage of gradians.
The current configuration of the unit for measuring of angles can be defined by the following command:
a_unit=<deg|rad|grad>[;]

Also use can setup current configuration of the unit for measuring of angles, just using following commands:
deg[;]
rad[;]
grad[;]

User can get current configuration of the unit for measuring of angles using the command:
a_unit[;]

SM Calculator tool supports the suite of functions, which provide converting of the various unit for measuring of angles, whatever defined current configuration of the unit for measuring:

grad2rad rad2grad rad2deg deg2rad grad2deg deg2grad

Current configuration:
—————-
A user always can get current configuration, using the command:
config[;]
The result of the command config[;]:
Current Configuration :
---------------------------------------------
Current double precision : EXPONENTIAL;
Current output format of integers : dec;
Unit of measurement of an angle : rad;

Constants:
—————-
SM Calculator supports follow float (64 bits) constants:
pi
exp
gamma
phi

Constants return float values. They can be used in expressions as arguments of functions and operators.

Examples:
—————-
User can find here suite of files which contain suite examples of usage of operators, functions, commands,
constants, various types of data:

Examples

Examples of expressions: Results of execution of expressions:
sm_calc_test.in.01.txt sm_calc_test.out.01.txt
sm_calc_test.in.02.txt sm_calc_test.out.02.txt
sm_calc_test.in.03.txt sm_calc_test.out.03.txt
sm_calc_test.in.04.txt sm_calc_test.out.04.txt
sm_calc_test.in.05.txt sm_calc_test.out.05.txt
sm_calc_test.in.06.txt sm_calc_test.out.06.txt

ReadMe.txt:
—————-
For more info about the sm_calculator (SM Calculator) tool 0.0.1.1 (description, examples, reference of commands, constants, functions, operators), please see file:
ReadMe.txt

Help.txt:
—————-
The short reference of commands, constants, functions, operators of the sm_calculator (SM Calculator) tool 0.0.1.1 is published here:
Help.txt

Demo of the sm_calculator (SM Calculator) tool 0.0.1.1 (Windows):
—————-

Here are the results of the execution of the sm_calculator (SM Calculator) tool 0.0.1.1 on Microsoft Windows 10 x64.

The sm_calculator (SM Calculator) tool 0.0.1.1 has been launched 4 times:

  1. sm_calc --help
  2. sm_calc --expression="pow_^2(sin(pi/2))+pow_^2(cos(pi/2));"
  3. sm_calc --in_file="./sm_calc_test.in.01.txt" --out_file="./sm_calc_test.out.01.txt"
  4. sm_calc

Files:
sm_calc_test.in.01.txt
sm_calc_test.out.01.txt

Results of execution (log file and screenshots) below:
sm_calc.log

sm_calc.win.01.jpeg

Demo of the sm_calculator (SM Calculator) tool 0.0.1.1 (Linux):
—————-

Here are the results of the execution of the sm_calculator (SM Calculator) tool 0.0.1.1 on Linux Debian 10 (Buster) x64.

The sm_calculator (SM Calculator) tool 0.0.1.1 has been launched 4 times:

  1. sm_calc --help
  2. sm_calc --expression="pow_^2(sin(pi/2))+pow_^2(cos(pi/2));"
  3. sm_calc --in_file="./sm_calc_test.in.02.txt" --out_file="./sm_calc_test.out.02.txt"
  4. sm_calc

Files:
sm_calc_test.in.02.txt
sm_calc_test.out.02.txt

Results of execution (log file and screenshots) below:
sm_calc.log

sm_calc.lnx.01.jpeg

sm_calc.lnx.02.jpeg

License.txt
—————-
The sm_calculator (SM Calculator) tool 0.0.1.1 is free software distributed under MIT License. Read License.txt for more information about the license.

Please, send your notes and questions to info@smansoft.com.

sm_calculator (SM Calculator) tool 0.0.1.1 ® Copyright © 2020 by SManSoft.

File Exchanger Tool 0.0.11.11

File Exchanger Tool 0.0.11.11 has been released.

Supported platforms:

  • Windows (x86, x86_64)
  • Linux (x86_64)

File Exchanger – 0.0.11.11 – Linux
File Exchanger Tool – 0.0.11.11 – Windows

Please, see screenshots here: screenshots.
Here are: demo (screenshots (.jpg), video demo (install, run) (.mp4)).

File Exchanger (file_exchanger) Tool is a peer-to-peer files exchanger for Windows/Linux platform.

Overview
—————-
The main features of File Exchanger (file_exchanger) Tool:

  • transfer of files from client to server, using open socket connections;
  • transfer of files from client to server, using SSL connections;
  • control of entirety of received files, comparing of checksum values sent and received files, using CRC-32 algorithm;
  • using transfer of files from client to server, using SSL connections;
  • using follow SSL mode/algorithms (TLSv1.2), if SSL connection is used:
    • ECDHE-ECDSA-AES256-GCM-SHA384
    • TLSv1.2 – version
    • TLS – the protocol used
    • ECDHE – the key exchange mechanism
    • ECDSA – the algorithm of the authentication key
    • AES – the symmetric encryption algorithm
    • 256 – the key size of AES
    • GCM – the mode of AES
    • SHA384 – the MAC used by the algorithm
    • prime256v1 (NIST P-256, secp256r1) – Elliptic Curve, that is used by ECDHE and ECDSA
  • using unique CA of client and server certificates;
  • user can update CA, client/server/gui keys/certificates, using suite of scripts ssl.ecdsa.tar.gz (ReadMe.txt in ssl.ecdsa.tar.gz);
  • using of xml configuration files, which can be updated by user and will be applied without restart of processes (sm_file_send_clns, sm_file_send_srvs);
  • scanning of configured directories, where sent files can be copied;
  • copying of sub-directories with files, saving of sub-directories tree at the server side;
  • support of unicode symbols in file/directory names;
  • backup (with rolling) of sent/received files;
  • server and client modules can be launched as Services (Windows)/Daemons (Linux);
  • console command line control application (only Windows) of client/server Services (requires Administrator permissions);
  • Windows gui application (asynchronous multi-thread GUI), that allows to monitor states of client/server Services, control of client/server Services and change parameters of client/server Services;
  • Linux gui application (Qt-based) (asynchronous multi-thread GUI), that allows to monitor states of client/server Daemons, control of client/server Daemons (when it’s possible, according to users permissions) and change parameters of client/server Deamons;
  • using ECDSA (NIST P-256, secp256r1) for signing/verification parameters, which are sent between client/server and gui applications (Windows/Linux);
  • tool applications don’t use any intermediate servers and transfer files directly between client and server;

Windows gui application: Screenshot 1
Windows gui application: Screenshot 2
Linux gui application (Qt-based): Screenshot 1
Linux gui application (Qt-based): Screenshot 2

Please, see more screenshots here: screenshots.

Read ReadMe.txt for more info.

File Exchanger (file_exchanger) Tool is a free software distributed under the MIT.
Read License.txt for more information about license.

Please, send your notes and questions to info@smansoft.com.

File Exchanger (file_exchanger) Tool ® Copyright © 2018-2019 by SManSoft.

File Exchanger Tool 0.0.9.9

File Exchanger Tool 0.0.9.9 has been released.

Supported platforms:

  • Windows (x86, x86_64)
  • Linux (x86_64)

File Exchanger – 0.0.9.9 – Linux
File Exchanger Tool – 0.0.9.9 – Windows

File Exchanger (file_exchanger) Tool is a peer-to-peer files exchanger for Windows/Linux platform.

Overview
—————-
The main features of File Exchanger (file_exchanger) Tool:

  • transfer of files from client to server, using open socket connections;
  • transfer of files from client to server, using SSL connections;
  • control of entirety of received files, comparing of checksum values sent and received files, using CRC-32 algorithm;
  • using transfer of files from client to server, using SSL connections;
  • using follow SSL mode/algorithms (TLSv1.2), if SSL connection is used:
    • ECDHE-ECDSA-AES256-GCM-SHA384
    • TLSv1.2 – version
    • TLS – the protocol used
    • ECDHE – the key exchange mechanism
    • ECDSA – the algorithm of the authentication key
    • AES – the symmetric encryption algorithm
    • 256 – the key size of AES
    • GCM – the mode of AES
    • SHA384 – the MAC used by the algorithm
    • prime256v1 (NIST P-256, secp256r1) – Elliptic Curve, that is used by ECDHE and ECDSA
  • using unique CA of client and server certificates;
  • user can update CA, client/server keys/certificates, using suite of scripts ssl.ecdsa.tar.gz (ReadMe.txt in ssl.ecdsa.tar.gz);
  • using of xml configuration files, which can be updated by user and will be applied without restart of processes (sm_file_send_clns, sm_file_send_srvs);
  • scanning of configured directories, where sent files can be copied;
  • copying of sub-directories with files, saving of sub-directories tree at the server side;
  • support of unicode symbols in file/directory names;
  • backup (with rolling) of sent/received files;
  • server and client modules can be launched as Services (Windows)/Daemons (Linux);
  • tool applications don’t use any intermediate servers and transfer files directly between client and server;

Read ReadMe.txt for more info.
File Exchanger (file_exchanger) Tool is a free software distributed under the MIT.
Read License.txt for more information about license.

Please, send your notes and questions to info@smansoft.com.

File Exchanger (file_exchanger) Tool ® Copyright © 2018-2019 by SManSoft.

Number Pattern #1

Here is the solution of simple algorithmic task – generation of integer sequences. There is a some challenge (easy level) at the site codenirvana.in :

CHALLENGE DESCRIPTION:
Write a program that prints out the pattern generated according to the input (number) from the user.
Pattern input and output sample is given below, check the input and the following pattern generated for that condition (number). Make sure you program follow the same pattern logic for every input.

INPUT SAMPLE:
Your program should ask for a number F first and than print the pattern accordingly. E.g.

Enter a number: 4

OUTPUT SAMPLE:
For the input N=4 output will be

4444444
4333334
4322234
4321234
4322234
4333334
4444444

Here is my solution (“С” for Windows). I’ve implemented two sequences generators – iterative and recursive:

// lines_gen.cpp : Defines the entry point for the console application.
//

#include <stdio.h>
#include <tchar.h>
#include <windows.h>

VOID init_line                          (PUINT	punLine, UINT unN);
VOID print_line                         (PUINT	punLine, UINT unN);
UINT proc_elem                          (PUINT	punLine, UINT unN, UINT unIdx);
UINT proc_array_rec                     (PUINT	punLine, UINT unN);
UINT proc_array_iter                    (PUINT	punLine, UINT unN);
UINT proc_array_iter_bak                (PUINT	punLine, UINT unN);

VOID init_line(PUINT	punLine, UINT unN)
{
  UINT unIdx;
  for(unIdx = 0; unIdx < unN; unIdx++)
    punLine[unIdx] = unIdx+1;
}

VOID print_line(PUINT	punLine, UINT unN)
{
  UINT unIdx;
  _tprintf(_T("line = "));
  for(unIdx = 0; unIdx < unN; unIdx++)
    _tprintf(_T("%d "),punLine[unIdx]);
  _tprintf(_T("\n"));
  return;
}

UINT proc_elem(PUINT	punLine, UINT unN, UINT unIdx)
{
  UINT unRes = 0;

  if((unIdx + 1) >= unN)
    return 0;

  if(punLine[unIdx] >= punLine[unIdx+1])
    unRes = proc_elem(punLine, unN, unIdx+1);
  else
    unRes = punLine[unIdx+1];

  if(unRes)
  {
    punLine[unIdx] = unRes;
    return punLine[unIdx];
  }
  else
    return 0;
}

UINT proc_array_rec(PUINT	punLine, UINT unN)
{
  UINT unCount = 0;

  print_line(punLine, unN);
  while(TRUE)
  {
    unCount++;
    if(!proc_elem	(punLine, unN, 0))
      break;
    print_line(punLine, unN);
  }

  return unCount;
}

UINT proc_array_iter(PUINT punLine, UINT unN)
{
  UINT unIdx;
  UINT unIdxIn;

  print_line(punLine, unN);
  for(unIdx = 1; unIdx < unN; unIdx++)
  {
    for(unIdxIn = 0; unIdxIn <= unIdx; unIdxIn++)
      punLine[unIdxIn] = unIdx+1;
    print_line(punLine, unN);
  }
  return unIdx;
}

UINT proc_array_iter_bak(PUINT punLine, UINT unN)
{
  UINT unIdx;
  UINT unIdxIn;

  print_line(punLine, unN);
  for(unIdx = 1; unIdx < unN; unIdx++)
  {
    UINT unBackIdx = unN-unIdx;
    for(unIdxIn = 0; unIdxIn <= (unBackIdx-1); unIdxIn++)
      punLine[unIdxIn] = unBackIdx;
    print_line(punLine, unN);
  }
  return unIdx;
}

INT _tmain(int argc, _TCHAR* argv[])
{
  UINT	unN		= 0;
  PUINT	punLine	= NULL;
  UINT	unCount;

  _tprintf(_T("Enter a number : "));
  _tscanf_s(_T("%d"), &unN);

  if(!unN)
    return 0;

  punLine = (PUINT) malloc(unN*sizeof(UINT));

  init_line(punLine, unN);
  unCount = proc_array_iter(punLine, unN);
  _tprintf(_T("Total count = %d\n"), unCount);
  _tprintf(_T("-----------------\n"));
  unCount = proc_array_iter_bak(punLine, unN);
  _tprintf(_T("Total count = %d\n"), unCount);
  _tprintf(_T("-----------------\n"));
  unCount = proc_array_rec(punLine, unN);
  _tprintf(_T("Total count = %d\n"), unCount);

  free(punLine);

  return 0;
}

Output:

Enter a number : 5
line = 1 2 3 4 5
line = 2 2 3 4 5
line = 3 3 3 4 5
line = 4 4 4 4 5
line = 5 5 5 5 5
Total count = 5
-----------------
line = 5 5 5 5 5
line = 4 4 4 4 5
line = 3 3 3 4 5
line = 2 2 3 4 5
line = 1 2 3 4 5
Total count = 5
-----------------
line = 1 2 3 4 5
line = 2 2 3 4 5
line = 3 3 3 4 5
line = 4 4 4 4 5
line = 5 5 5 5 5
Total count = 5

lines_gen.c
output.txt

Java:

/**
 * 
 */
package com.smansoft;

/**
 * @author SMan
 * 
 */
public class LinesGen {

  /**
   * 
   */
  int line[] = null;
  
  /**
   * @param args
   */
  public static void main(String[] args) {
    int inNum = Integer.parseInt(args[0]);		
    
    System.out.printf("Number = %d\n", inNum);

    LinesGen linesGen = new LinesGen(inNum);
    linesGen.initLine();

    int count = linesGen.procArrayIter();
    System.out.printf("Total count = %d\n", count);
    count = linesGen.procArrayIterBak();
    System.out.printf("Total count = %d\n", count);
    count = linesGen.procArrayRec();
    System.out.printf("Total count = %d\n", count);
  }

  /**
   * 
   * @param size
   */
  public LinesGen(int size) {
    line = new int[size];
  }

  /**
   * 
   */
  public void initLine() {
    for (int idx = 0; idx < line.length; idx++) {
      line[idx] = (idx + 1);
    }
  }

  /**
   * 
   */
  public void printLine() {
    System.out.print("line = ");
    for (int idx = 0; idx < line.length; idx++) {
      System.out.printf("%d ", line[idx]);
    }
    System.out.println("");
  }

  /**
   * 
   * @return
   */
  public int procArrayRec() {
    int count = 0;
    printLine();
    while (true) {
      count++;
      if (procElem(0) == 0)
        break;
      printLine();
    }
    return count;
  }

  /**
   * 
   * @return
   */
  public int procArrayIter() {
    int idx;
    printLine();
    for (idx = 1; idx < line.length; idx++) {
      for (int idxIn = 0; idxIn <= idx; idxIn++) {
        line[idxIn] = idx + 1;
      }
      printLine();
    }
    return idx;
  }

  /**
   * 
   * @return
   */
  public int procArrayIterBak() {
    int idx;
    printLine();
    for (idx = 1; idx < line.length; idx++) {
      for (int idxIn = 0; idxIn <= (line.length - idx - 1); idxIn++) {
        line[idxIn] = line.length - idx;
      }
      printLine();
    }
    return idx;
  }
  
  /**
   * 
   * @param idx
   * @return
   */
  private int procElem(int idx) {
    int res = 0;

    if ((idx + 1) >= line.length)
      return 0;

    if (line[idx] >= line[idx + 1])
      res = procElem(idx + 1);
    else
      res = line[idx + 1];

    if (res > 0) {
      line[idx] = res;
      return line[idx];
    } else
      return 0;
  }
}

Output (ant run.LinesGen):

run.LinesGen:
[java] Number = 5
[java] line = 1 2 3 4 5
[java] line = 2 2 3 4 5
[java] line = 3 3 3 4 5
[java] line = 4 4 4 4 5
[java] line = 5 5 5 5 5
[java] Total count = 5
[java] line = 5 5 5 5 5
[java] line = 4 4 4 4 5
[java] line = 3 3 3 4 5
[java] line = 2 2 3 4 5
[java] line = 1 2 3 4 5
[java] Total count = 5
[java] line = 1 2 3 4 5
[java] line = 2 2 3 4 5
[java] line = 3 3 3 4 5
[java] line = 4 4 4 4 5
[java] line = 5 5 5 5 5
[java] Total count = 5

LinesGen.java
LinesGen.zip (including ant script)
joutput.txt

SManSoft Ltd.

SManSoft Ltd.

This site has been created and supported by Sergey Manoylo to document software development activity in Software Development (C/C++, Java, Windows, Linux, Android, Kernel Level).

Blog Mirrors:

mirror: http://blog.smansoft.com
mirror: http://smansoft.wordpress.com

 

Contact info:

Sergey Manoylo

mobile phone: +380-67-150-2244
e-mail: sman(at)smansoft.com
e-mail: blog(at)smansoft.com
e-mail: smansoft(at)ukr.net
Skype ID: smansoft.net
Telegram: https://t.me/smansoft (+380671502244)
GitHub: https://github.com/smansoft

Kharkov (Kharkiv), Ukraine