Ring programs on Rosetta Code

392 views
Skip to first unread message

Fuad Omari

unread,
Mar 10, 2023, 9:01:09 AM3/10/23
to The Ring Programming Language
the articles is by  CalmoSoft

CalmoSoft

unread,
Mar 10, 2023, 9:20:15 AM3/10/23
to The Ring Programming Language
Hello Mahmoud et All,

I added the Erdős-Nicolas_numbers task to Rosetta Code
----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
Definition

An Erdős–Nicolas number is a positive integer which is not perfect but is equal to the sum of its first k divisors (arranged in ascending order and including one) for some value of k greater than one.

Examples

24 is an Erdős–Nicolas number because the sum of its first 6 divisors (1, 2, 3, 4, 6 and 8) is equal to 24 and it is not perfect because 12 is also a divisor.

6 is not an Erdős–Nicolas number because it is perfect (1 + 2 + 3 = 6).

48 is not an Erdős–Nicolas number because its divisors are: 1, 2, 3, 4, 6, 8, 12, 16, 24 and 48. The first seven of these add up to 36, but the first eight add up to 52 which is more than 48.

----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
Code:
see "works..." + nl
erdos = []
limit = 1600000
for n = 1 to limit
      num = 0
      sum = 0
      erdos = []
      for m = 1 to n/2
            if n%m = 0
                add(erdos,m)
            ok
      next
      lenErdos = len(erdos)
      for p = 1 to lenErdos
            sum = sum + erdos[p]
            if sum = n and p < lenErdos
                num++
                see "" + n + " equals the sum of its first " + p + " divisors" + nl
               exit
            ok
       next
       if num = 8
          exit
       ok
next
see "done..." + nl
----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
Output:
works...
          24 equals the sum of its first 6 divisors
      2016 equals the sum of its first 31 divisors
      8190 equals the sum of its first 43 divisors
    42336 equals the sum of its first 66 divisors
    45864 equals the sum of its first 66 divisors
  714240 equals the sum of its first 113 divisors
  392448 equals the sum of its first 68 divisors
1571328 equals the sum of its first 115 divisors
done...
----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
Have a nice day, good work and a pleasant rest.

Greetings,
Gal Zsolt
(~ CalmoSoft ~)

On Friday, 10 March 2023 at 15:01:09 UTC+1 Fuad Omari wrote:
the articles is by  CalmoSoft
ErdosNicolasNumbers.ring

CalmoSoft

unread,
Mar 19, 2023, 9:05:48 AM3/19/23
to The Ring Programming Language
Hello Mahmoud et All,

I added the Calmo numbers task to Rosetta Code
----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
Definition
Let n be a natural number. Let the real divisors of n be: d(1),d(2),d(3),...,d(k), where k is divisible by 3.
Add the first three divisors, then the next three, and so on. If the partial sums are prime numbers, then n is called a Calmo number

Example
n = 165
divisors = [3 5 11 15 33 55]
3 + 5 + 11 = 19 is prime number
15 + 33 + 55 = 103 is prime number

Task
let's find Calmo numbers under 1000.
----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
Code:
see "works..." + nl
numCalmo = 0
limit = 1000

for n = 1 to limit
    Calmo = []
    for m = 2 to n/2
        if n % m = 0
           add(Calmo,m)
        ok
    next
    flag = 1
    lenCalmo = len(Calmo)
    if (lenCalmo > 5) and (lenCalmo % 3 = 0)
        for p = 1 to lenCalmo - 2 step 3
            sum = Calmo[p] + Calmo[p+1] + Calmo[p+2]
            if not isPrime(sum)
               flag = 0
               exit
            ok
        next
        if flag = 1
           numCalmo++
           see "n(" + numCalmo + ") = " + n + nl
           see "divisors = ["
           for p = 1 to lenCalmo - 2 step 3
               sumCalmo = Calmo[p] + Calmo[p+1] + Calmo[p+2]
               if not isPrime(sumCalmo)
                  exit
               else
                  if p = 1
                     see "" + Calmo[p] + " " + Calmo[p+1] + " " + Calmo[p+2]
                  else
                     see " " + Calmo[p] + " " + Calmo[p+1] + " " + Calmo[p+2]
                  ok
               ok
            next
            see "]" + nl
            for p = 1 to lenCalmo - 2 step 3
                sumCalmo = Calmo[p] + Calmo[p+1] + Calmo[p+2]
                if isPrime(sumCalmo)
                   see "" + Calmo[p] + " + " + Calmo[p+1] + " + " + Calmo[p+2] + " = " + sumCalmo + " is prime" + nl
                ok
            next
            see nl
        ok
     ok
next
see "Found " + numCalmo + " Calmo numbers" + nl
see "done..." + nl

func isPrime num
     if (num <= 1) return 0 ok
     if (num % 2 = 0 and num != 2) return 0 ok
     for i = 3 to floor(num / 2) -1 step 2
         if (num % i = 0) return 0 ok
     next
     return 1
----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
Output:
works...
n(1) = 165
divisors = [3 5 11 15 33 55]
3 + 5 + 11 = 19 is prime
15 + 33 + 55 = 103 is prime

n(2) = 273
divisors = [3 7 13 21 39 91]
3 + 7 + 13 = 23 is prime
21 + 39 + 91 = 151 is prime

n(3) = 385
divisors = [5 7 11 35 55 77]
5 + 7 + 11 = 23 is prime
35 + 55 + 77 = 167 is prime

n(4) = 399
divisors = [3 7 19 21 57 133]
3 + 7 + 19 = 29 is prime
21 + 57 + 133 = 211 is prime

n(5) = 561
divisors = [3 11 17 33 51 187]
3 + 11 + 17 = 31 is prime
33 + 51 + 187 = 271 is prime

n(6) = 595
divisors = [5 7 17 35 85 119]
5 + 7 + 17 = 29 is prime
35 + 85 + 119 = 239 is prime

n(7) = 665
divisors = [5 7 19 35 95 133]
5 + 7 + 19 = 31 is prime
35 + 95 + 133 = 263 is prime

n(8) = 715
divisors = [5 11 13 55 65 143]
5 + 11 + 13 = 29 is prime
55 + 65 + 143 = 263 is prime

n(9) = 957
divisors = [3 11 29 33 87 319]
3 + 11 + 29 = 43 is prime
33 + 87 + 319 = 439 is prime

Found 9 Calmo numbers

done...
----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
Have a nice day, good work and a pleasant rest.

Greetings,
Gal Zsolt
(~ CalmoSoft ~)
CalmoNumbers.ring

Mahmoud Fayed

unread,
Mar 19, 2023, 1:49:12 PM3/19/23
to The Ring Programming Language
Hello Gal

Thanks for adding more samples :D

Greetings,
Mahmoud

CalmoSoft

unread,
Mar 19, 2023, 2:40:18 PM3/19/23
to The Ring Programming Language
Hello Mahmoud,

Thanks for your kind words.
Have a nice day, good work and a pleasant rest.


Greetings,
Gal Zsolt
(~ CalmoSoft ~)

CalmoSoft

unread,
Mar 24, 2023, 4:05:14 PM3/24/23
to The Ring Programming Language
Hello Mahmoud et All,

I added the Double Twin Primes task to Rosetta Code
----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
Definition
Let (p1,p2) and (p3,p4) be twin primes where p3 - p2 = 4.
Such primes called Double Twin Primes

Example
[5,7,11,13]

Task
Find and show here all Double Twin Primes under 1000.
----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
Code:
see "works..." + nl
primes = []

limit = 1000
for n =1 to limit
    if isPrime(n)
       add(primes,n)
    ok
next
lenPrimes = len(primes)-3
for m = 1 to lenPrimes
    if isPrime(primes[m]) and isPrime(primes[m+1]) and
       isPrime(primes[m+2]) and isPrime(primes[m+3])
       if (primes[m+1] - primes[m] = 2) and (primes[m+2] - primes[m+1] = 4) and
          (primes[m+3] - primes[m+2] = 2)
          see " " + primes[m]+ " " + primes[m+1] + " " +
          primes[m+2] + " " + primes[m+3] + nl
       ok
    ok
next

see "done..." + nl

func isPrime num
     if (num <= 1) return 0 ok
     if (num % 2 = 0 and num != 2) return 0 ok
     for i = 3 to floor(num / 2) -1 step 2
         if (num % i = 0) return 0 ok
     next
     return 1
----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
Output:
works...
5 7 11 13
11 13 17 19
101 103 107 109
191 193 197 199
821 823 827 829
done...

----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
Have a nice day, good work and a pleasant rest.

Greetings,
Gal Zsolt
(~ CalmoSoft ~)
DoubleTwinPrimes.ring

CalmoSoft

unread,
Apr 2, 2023, 10:34:36 AM4/2/23
to The Ring Programming Language
Hello Mahmoud et All,

I added the Ultra Useful Numbers task to Rosetta Code
----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

Code:
see "works..." + nl
limit = 10

for n = 1 to limit
    k = 0
    flag = 0
    while true
          k++
          num = pow(2,pow(2,n)) - k
          if isPrime(num)
             flag = 1
             exit
          ok
    end
    if flag = 1
       see "n = " + n + " k = " + k + nl
    ok
next
see "done.." + nl


func isPrime num
     if (num <= 1) return 0 ok
     if (num % 2 = 0 and num != 2) return 0 ok
     for i = 3 to floor(num / 2) -1 step 2
         if (num % i = 0) return 0 ok
     next
     return 1
----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
Output:
works...
n = 1 k = 1
n = 2 k = 3
n = 3 k = 5
n = 4 k = 15
n = 5 k = 5
n = 6 k = 59
n = 7 k = 159
n = 8 k = 189
n = 9 k = 569
n = 10 k = 105
done...

----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
Have a nice day, good work and a pleasant rest.

Greetings,
Gal Zsolt
(~ CalmoSoft ~)
UlltraUsefulNumbers.ring

Mahmoud Fayed

unread,
Apr 3, 2023, 10:48:58 PM4/3/23
to The Ring Programming Language
Hello Gal

Thanks for adding more samples

Note:
(1) Using if flag=1 can be replace with if flag (i.e. no need to use = 1)
(2) Using see "message" + nl can be replaced with ? "message"
(3) The code set flag=1 the uses exit to end a loop and after the loop,  we have if flag=1
This if statement is not necessary, Also, the flag variable is not necessary
Just use
if isPrime(num)
    see "n = " + n + " k = " + k + nl
    exit
ok

Greetings,
Mahmoud

CalmoSoft

unread,
Apr 4, 2023, 1:00:08 AM4/4/23
to The Ring Programming Language
Hello Mahmoud,

Thank you very much for the congratulations and the suggestions, I did them. See on Rosetta Code

Have a nice day, good work and a pleasant rest.

Greetings,
Gal Zsolt
(~ CalmoSoft ~)

Mahmoud Fayed

unread,
Apr 4, 2023, 5:09:35 AM4/4/23
to The Ring Programming Language
Hello Gal

You are welcome :D

Greetings,
Mahmoud

CalmoSoft

unread,
Apr 7, 2023, 6:20:12 AM4/7/23
to The Ring Programming Language
Hello Mahmoud et All,

I added the CalmoSoft primes task to Rosetta Code
----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
Code:
see "works..." + nl
limit = 100
Primes = []
OldPrimes = []
NewPrimes = []
for p = 1 to limit
    if isPrime(p)
       add(Primes,p)
    ok
next

lenPrimes = len(Primes)

for n = 1 to lenPrimes
    num = 0
    OldPrimes = []
    for m = n to lenPrimes  
        num = num + Primes[m]
        add(OldPrimes,Primes[m])
        if isPrime(num)
           if len(OldPrimes) > len(NewPrimes)
              NewPrimes = OldPrimes
           ok
        ok
    next
next

str = "["
for n = 1 to len(NewPrimes)
    if n = len(NewPrimes)
       str = str + newPrimes[n] + "]"
       exit
    ok
    str = str + newPrimes[n] + ", "
next

sum = 0
strsum = ""
for n = 1 to len(NewPrimes)
    sum = sum + newPrimes[n]
    if n = len(NewPrimes)
       strsum = strsum + newPrimes[n] + " = " + sum + " is prime number"
       exit
    ok
    strsum = strsum + newPrimes[n] + " + "
next

see str + nl
see strsum + nl
see " The longest sequence of CalmoSoft prime numbers = " + len(NewPrimes) + nl

see "done.." + nl

func isPrime num
     if (num <= 1) return 0 ok
     if (num % 2 = 0 and num != 2) return 0 ok
     for i = 3 to floor(num / 2) -1 step 2
         if (num % i = 0) return 0 ok
     next
     return 1
----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
Output:
works...
[7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61, 67, 71, 73, 79, 83, 89]
7 + 11 + 13 + 17 + 19 + 23 + 29 + 31 + 37 + 41 + 43 + 47 + 53 + 59 + 61 + 67 + 71 + 73 + 79 + 83 + 89 = 953 is prime number
The longest sequence of CalmoSoft primes = 21
done...

-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

Have a nice day, good work and a pleasant rest.

Greetings,
Gal Zsolt
(~ CalmoSoft ~)
CalmoSoftPrimes.ring

CalmoSoft

unread,
Apr 13, 2023, 2:45:14 PM4/13/23
to The Ring Programming Language
Hello Mahmoud et All,

I added the Ormiston pairs task to Rosetta Code
----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
Code:
see "working..." + nl
see "First 30 Ormiston pairs:" + nl
limit = 1000000
Primes = []
Primes1 = []
Primes2 = []

add(Primes,2)
pr = 1
while true
    pr = pr + 2
    if isPrime(pr) and pr < limit
       add(Primes,pr)
    ok
    if pr > limit
       exit
    ok
end

n = 0
row = 0

for n = 1 to len(Primes) - 1
    Primes1 = []
    Primes2 = []
    str1 = string(Primes[n])
    str2 = string(Primes[n+1])
    for p = 1 to len(str1)
        add(Primes1,substr(str1,p,1))
    next
    for p = 1 to len(str2)
        add(Primes2,substr(str2,p,1))
    next
    Sort1 = sort(Primes1)
    Sort2 = sort(Primes2)

    flag = 1
    if len(Sort1) = len(Sort2)
       for p = 1 to len(Sort1)
           if Sort1[p] != Sort2[p]

              flag = 0
              exit
           ok
       next
       if flag = 1
          row++
          if row < 31
             str1m = str1
             str2m = str2
             see "(" + str1 + ", " + str2 + ")  "
             if row % 3 = 0
                see nl
             ok
          ok
       ok
    ok
end
see nl + "Number of pairs < 1,000,000: " + row + nl

see "done..." + nl

func isPrime num
     if (num <= 1) return 0 ok
     if (num % 2 = 0 and num != 2) return 0 ok
     for i = 3 to floor(num / 2) -1 step 2
         if (num % i = 0) return 0 ok
     next
     return 1    ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
Output:
working...
First 30 Ormiston pairs:
( 1913, 1931) (18379, 18397) (19013, 19031)
(25013, 25031) (34613, 34631) (35617, 35671)
(35879, 35897) (36979, 36997) (37379, 37397)
(37813, 37831) (40013, 40031) (40213, 40231)
(40639, 40693) (45613, 45631) (48091, 48109)
(49279, 49297) (51613, 51631) (55313, 55331)
(56179, 56197) (56713, 56731) (58613, 58631)
(63079, 63097) (63179, 63197) (64091, 64109)
(65479, 65497) (66413, 66431) (74779, 74797)
(75913, 75931) (76213, 76231) (76579, 76597)
Number of pairs < 1,000,000: 382 done...

-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
Have a nice day, good work and a pleasant rest.

Greetings,
Gal Zsolt
(~ CalmoSoft ~)
OrmistonPairs.ring

Mahmoud Fayed

unread,
Apr 22, 2023, 8:01:19 PM4/22/23
to The Ring Programming Language
Hello Gal

Thank you very much for adding more samples

Greetings,
Mahmoud

CalmoSoft

unread,
Apr 23, 2023, 7:30:10 AM4/23/23
to The Ring Programming Language
Hello Mahmoud,

Thanks for your kind words.
Have a nice day, good work and a pleasant rest.

Greetings,
Gal Zsolt
(~ CalmoSoft ~)

Mahmoud Fayed

unread,
Apr 25, 2023, 1:17:14 AM4/25/23
to The Ring Programming Language
Hello Gal

You are welcome :D

Greetings,
Mahmoud

Message has been deleted
Message has been deleted
Message has been deleted
Message has been deleted

CalmoSoft

unread,
May 19, 2023, 1:20:10 PM5/19/23
to The Ring Programming Language
Hello Mahmoud et All,

I added the Factorial primes task to Rosetta Code

Definition

A factorial prime is a prime number that is one less or one more than a factorial.

In other words a non-negative integer n corresponds to a factorial prime if either n! - 1 or n! + 1 is prime.

----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
Code:
see "working..." + nl
load "stdlibcore.ring"

n = 0
num = 0
while true
        n++
        n1 = factorial(n) - 1
        if isPrime(n1)
           num++
           see "" + num + ": " + n + "! - 1 = " + n1 + nl
        ok
        n2 = factorial(n) + 1  
        if isPrime(n2)
           num++
           see "" + num + ": " + n + "! + 1 = " + n2 + nl
        ok
        if num = 10
           exit
        ok
end


see "done..." + nl
----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
Output:
working...
1: 1! + 1 = 2
2: 2! + 1 = 3
3: 3! - 1 = 5
4: 3! + 1 = 7
5: 4! - 1 = 23
6: 6! - 1 = 719
7: 7! - 1 = 5039
8: 11! + 1 = 39916801
9: 12! - 1 = 479001599
10: 14! - 1 = 87178291199

done...
-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
Have a nice day, good work and a pleasant rest.

Greetings,
Gal Zsolt
(~ CalmoSoft ~)

FactorialPrimes.ring

Mahmoud Fayed

unread,
May 19, 2023, 1:32:12 PM5/19/23
to The Ring Programming Language
Hello Gal

Thanks for adding more samples

Greetings,
Mahmoud

CalmoSoft

unread,
May 24, 2023, 1:25:12 PM5/24/23
to The Ring Programming Language
Hello Mahmoud et All,

I added the Giuga numbers task to Rosetta Code

----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
Code:
see "working..." + nl
see "The first 4 Giuga numbers are:" + nl
load "stdlibcore.ring"

Comp = []
num = 0
n = 1
while true
      n++
      if not isPrime(n)
         Comp = []
         for p = 1 to n
             if isPrime(p) AND (n % p = 0)
                 add(Comp,p)

             ok
         next
         flag = 1
         for ind = 1 to len(Comp)
             f = Comp[ind]
             res = (n/f)- 1
             if res % f != 0

                flag = 0
                exit
             ok
         next
         if flag = 1
            see "" + n + " "
            num++
         ok
         if num = 4
            exit
         ok
      ok
end
see nl + "done..." + nl
----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
Output:
working...
The first 4 Giuga numbers are:
30 858 1722 66198
done...
-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
Have a nice day, good work and a pleasant rest.

Greetings,
Gal Zsolt
(~ CalmoSoft ~)


GiugaNumbers.ring

CalmoSoft

unread,
Jun 10, 2023, 3:00:24 PM6/10/23
to The Ring Programming Language
Hello Mahmoud et All,

I added the Erdős-primes task to Rosetta Code

----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
Code:
load "stdlibcore.ring"
see "working..." + nl
row = 0
limit = 2500


for p = 1 to limit
    flag = 1
    if isprime(p)
       for k = 1 to p
           if factorial(k) < p
              temp = p - factorial(k)
              if not isprime(temp)
                 flag = 1
              else

                 flag = 0
                 exit
              ok
           else
              exit
           ok
        next
     else
        flag = 0
     ok

     if flag = 1
        row++
        see "" + p + " "
        if row % 5 = 0
           see nl
        ok
     ok
next

see nl + "Found " + row + " Erdos primes less than 2500" + nl
see "done..." + nl
----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
Output:
working...
2 101 211 367 409
419 461 557 673 709
769 937 967 1009 1201
1259 1709 1831 1889 2141
2221 2309 2351 2411 2437

Found 25 Erdos primes less than 2500
done...

-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
Have a nice day, good work and a pleasant rest.

Greetings,
Gal Zsolt
(~ CalmoSoft ~)
ErdosPrimes.ring

Mahmoud Fayed

unread,
Jun 10, 2023, 6:31:53 PM6/10/23
to The Ring Programming Language
Hello Gal

Thank you very much

Greetings,
Mahmoud

CalmoSoft

unread,
Jun 11, 2023, 2:35:11 AM6/11/23
to The Ring Programming Language
Hello Mahmoud,

Thanks for your kind words.
Have a nice day, good work and a pleasant rest.

Greetings,
Gal Zsolt
(~ CalmoSoft ~)


CalmoSoft

unread,
Jun 25, 2023, 8:00:26 AM6/25/23
to The Ring Programming Language
Hello Mahmoud et All,

I added the Determine sentence type task to Rosetta Code
----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
Code:

see "working..." + nl
sType = []
sent = "hi there, how are you today? I'd like to present to you the washing machine 9001. You have been nominated to win one of these! Just make sure you don't break it"

ind = 1
while true
      pos = substring(sent,"?",ind)
      if pos > 0
         add(sType,pos)
         ind = pos+1
      else
         exit
      ok
end

ind = 1
while true
      pos = substring(sent,"!",ind)
      if pos > 0
         add(sType,pos)
         ind = pos+1
      else
         exit
      ok
end

ind = 1
while true
      pos = substring(sent,".",ind)
      if pos > 0
         add(sType,pos)
         ind = pos+1
      else
         exit
      ok
end

if pos < len(sent)
   neut = "N"
else
   neut = ""
ok

sType = sort(sType)

text = ""
for n = 1 to len(sType)
    if sent[sType[n]] = "?"
       text = text + "Q" + "|"
    ok
    if sent[sType[n]] = "!"
       text = text + "E" + "|"
    ok
    if sent[sType[n]] = "."
       text = text + "S" + "|"
    ok
next
see text + neut  + nl
see "done..." + nl

func substring str,substr,n
newstr=right(str,len(str)-n+1)
nr = substr(newstr, substr)
if nr = 0
return 0
else
return n + nr -1
ok
-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
Output:
working...
Q|S|E|N
done...
-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
Have a nice day, good work and a pleasant rest.

Greetings,
Gal Zsolt
(~ CalmoSoft ~)
SentenceType.ring

Mahmoud Fayed

unread,
Jun 27, 2023, 8:58:08 AM6/27/23
to The Ring Programming Language
Hello Gal

Thanks for adding more samples

Note: if statements that uses sent[sType[n]] could be replace with (switch)

Greetings,
Mahmoud

CalmoSoft

unread,
Jun 27, 2023, 10:21:02 AM6/27/23
to The Ring Programming Language

Hello Mahmoud,

Thanks for your kind words and guidance, I followed them.
----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
Code:
see "working..." + nl
sType = []
sent = "hi there, how are you today? I'd like to present to you the washing machine 9001. You have been nominated to win one of these! How do you like this washing machine? Buy it, don't hesitate! You will be satisfied with it. Just make sure you don't break it"
    switch sent[sType[n]]
                  on "?"

                        text = text + "Q" + "|"
                  on "!"

                         text = text + "E" + "|"
                  on "."

                         text = text + "S" + "|"
    off

next
see text + neut  + nl
see "done..." + nl

func substring str,substr,n
newstr=right(str,len(str)-n+1)
nr = substr(newstr, substr)
if nr = 0
return 0
else
return n + nr -1
ok
-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
Output:
working...
Q|S|E|Q|E|S|N
done...
-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
Have a nice day, good work and a pleasant rest.

Greetings,
Gal Zsolt
(~ CalmoSoft ~)
SentenceType.ring

Mahmoud Fayed

unread,
Jun 29, 2023, 12:49:20 AM6/29/23
to The Ring Programming Language
Hello Gal

You are welcome :D

Greetings,
Mahmoud

CalmoSoft

unread,
Sep 12, 2023, 3:00:12 PM9/12/23
to The Ring Programming Language
Hello Mahmoud et All,

CalmoSoft activation in RosettaCode on Quora:
CalmoSoft on Quora
>>> There is a user by name CalmoSoft, in the Ring programming language space that has written to ResettaCode nearly all the programs in Rosetta for the Ring language (I'd say more than 200 or so, if not more). <<<
I currently have over 700 example programs on RosettaCode.

Greetings,
Gal Zsolt
CalmoSoft
Message has been deleted

CalmoSoft

unread,
Oct 13, 2023, 12:50:54 PM10/13/23
to The Ring Programming Language
Hello Mahmoud et All,

I added Hex Words sample to Rosetta Code

Greetings,
Gal Zsolt
CalmoSoft

On Saturday, 16 September 2023 at 14:46:27 UTC+2 CalmoSoft wrote:
Hello Mahmoud et All.

Sorry, but the Quora website is paid, so not everyone can see it. The text quoted from the Quora website can be found between >>>,<<< signs in my previous post.

Greetings,
Gal Zsolt
CalmoSoft
Reply all
Reply to author
Forward
0 new messages