Raspberry BASIC

Author Topic: Just REM  (Read 622 times)

John Spikowski

  • BASIC Developer
  • **
  • Posts: 81
    • View Profile
    • ScriptBasic
Re: Just REM
« Reply #30 on: November 29, 2019, 02:24:05 AM »
PHP

Code: PHP
  1. <?php
  2.  
  3. # PHP -1mil3.php
  4.  
  5. $s = "";
  6. $t = "";
  7. $a = array();
  8.  
  9. for ($x = 1; $x <= 1000000; $x++) {
  10.   $s = $s . chr((($x - 1) % 26) + 65);
  11.   $a[$x] = $x;
  12.   if(strlen($s) == 26) {
  13.     $t = $t . $s;
  14.     $s = "";
  15.   }
  16. }
  17.  
  18. $r = strrev($t);
  19.  
  20. echo "r LEN: ", strlen($r), "\n";
  21. echo "Front: ", substr($r, 0, 26), "\n";
  22. echo "Back:  ", substr($r, -26), "\n";
  23. echo "UBVal: ", $a[1000000],"\n";
  24.  
  25. ?>
  26.  


pi@RPi4B:~/php-dev/examples $ /usr/bin/time php 1mil3.php
r LEN: 999986
Front: ZYXWVUTSRQPONMLKJIHGFEDCBA
Back:  ZYXWVUTSRQPONMLKJIHGFEDCBA
UBVal: 1000000
9.28user 0.10system 0:09.39elapsed 99%CPU (0avgtext+0avgdata 39220maxresident)k
0inputs+0outputs (0major+9799minor)pagefaults 0swaps
pi@RPi4B:~/php-dev/examples $

« Last Edit: November 29, 2019, 02:25:47 AM by John Spikowski »
ScriptBasic Project Manager/Facilitator

John Spikowski

  • BASIC Developer
  • **
  • Posts: 81
    • View Profile
    • ScriptBasic
Re: Just REM
« Reply #31 on: November 29, 2019, 11:45:38 PM »
Python 3

Code: Python
  1. # Python 3 - 1mil3.py
  2.  
  3. s = ""
  4. t = ""
  5. a = [None] * 1000001
  6.  
  7. for x in range(1000001):
  8.   s += chr(((x) % 26) + 65)
  9.   a[x] = x
  10.   if len(s) == 26:
  11.     t += s
  12.     s = ""
  13.  
  14. r = "".join(reversed(t))
  15.  
  16. print("r LEN: {}".format(len(r)))
  17. print("Front: {}".format(r[:26]))
  18. print("Back:  {}".format(r[-26:]))
  19. print("UBVal: {}".format(a[1000000]))
  20.  


pi@RPi4B:~/python-dev/examples $ /usr/bin/time python3 1mil3,py
r LEN: 999986
Front: ZYXWVUTSRQPONMLKJIHGFEDCBA
Back:  ZYXWVUTSRQPONMLKJIHGFEDCBA
UBVal: 1000000
1.87user 0.09system 0:01.97elapsed 99%CPU (0avgtext+0avgdata 32660maxresident)k
0inputs+0outputs (0major+7192minor)pagefaults 0swaps
pi@RPi4B:~/python-dev/examples $

« Last Edit: November 30, 2019, 11:56:07 PM by John Spikowski »
ScriptBasic Project Manager/Facilitator

John Spikowski

  • BASIC Developer
  • **
  • Posts: 81
    • View Profile
    • ScriptBasic
Re: Just REM
« Reply #32 on: November 30, 2019, 07:42:29 PM »
The Swift round two post has been updated. The compiler now correctly prints middle.

The swift-5.1.2_armv7.tgz file is 206 MB.  I will have to upload it to the server and provide a link to download. This build is the current release with the latest updates as of build time.

AIR submitted an improvement to the Python script to not require numpy.

« Last Edit: November 30, 2019, 11:57:42 PM by John Spikowski »
ScriptBasic Project Manager/Facilitator

John Spikowski

  • BASIC Developer
  • **
  • Posts: 81
    • View Profile
    • ScriptBasic
Re: Just REM
« Reply #33 on: November 30, 2019, 09:26:43 PM »
8th (Jalih submission)

Code: Text
  1. 1000000 constant LIMIT
  2.  
  3. a:new 0 a:push var, a
  4. "" var, s
  5. "" var, t
  6.  
  7. : rev  \ s -- s
  8.   b:new b:rev >s ;
  9.  
  10. : iterate
  11.   s @ over n:1- 26 n:mod 65 n:+ s:+ s !
  12.   s @ s:len 26 n:< not if
  13.     t @ swap s:+ t !
  14.     "" s !
  15.   else
  16.     drop
  17.   then
  18.   a:push ;
  19.  
  20. : app:main
  21.   a @ ' iterate 1 LIMIT loop
  22.   t @ rev s:len "r LEN: %d\n" s:strfmt .
  23.   dup 26 s:lsub "Front: %s\n" s:strfmt .
  24.   26 s:rsub "Back:  %s\n" s:strfmt .
  25.   LIMIT a:@ nip "UBVal: %d\n" s:strfmt .
  26.   bye ;
  27.  


pi@RPi4B:~/8th-dev/examples $ /usr/bin/time ./1mil3
r LEN: 999986
Front: ZYXWVUTSRQPONMLKJIHGFEDCBA
Back:  ZYXWVUTSRQPONMLKJIHGFEDCBA
UBVal: 1000000
10.33user 30.38system 0:40.75elapsed 99%CPU (0avgtext+0avgdata 61464maxresident)k
0inputs+0outputs (0major+3677030minor)pagefaults 0swaps
pi@RPi4B:~/8th-dev/examples $

ScriptBasic Project Manager/Facilitator

John Spikowski

  • BASIC Developer
  • **
  • Posts: 81
    • View Profile
    • ScriptBasic
Re: Just REM
« Reply #34 on: December 01, 2019, 07:28:32 PM »
C (AIR submission)

Code: C
  1. // C - 1mil3.c - AIR
  2.  
  3. #define _GNU_SOURCE
  4.  
  5. #include <stdio.h>
  6. #include <stdlib.h>
  7. #include <string.h>
  8.  
  9. #define join(write_to,  ...) {           \
  10.     char *tmp_string_for_extend = (write_to); \
  11.     asprintf(&(write_to), __VA_ARGS__);       \
  12.     free(tmp_string_for_extend);              \
  13. }
  14.  
  15. char *strrev(char *str)
  16. {
  17.     if (!str || ! *str)
  18.         return str;
  19.  
  20.     int i = strlen(str) - 1, j = 0;
  21.  
  22.     char ch;
  23.     while (i > j) {
  24.         ch = str[i];
  25.         str[i] = str[j];
  26.         str[j] = ch;
  27.         i--;
  28.         j++;
  29.     }
  30.     return str;
  31. }
  32.  
  33.  
  34. int main() {
  35.     int a[1000001] = {0};
  36.     int i;
  37.     char *s=NULL,*t=NULL;
  38.  
  39.     join(s,"");
  40.     join(t,"");
  41.  
  42.     for (int x = 0; x < 1000001; x++) {
  43.         a[x] = x;
  44.  
  45.         join(s,"%s%c",s,(x%26)+65);
  46.  
  47.         if (strlen(s) == 26) {
  48.             join(t,"%s%s",t,s);
  49.             join(s,"");
  50.         }
  51.     }
  52.  
  53.     free(s);
  54.     strrev(t);
  55.  
  56.     printf("r LEN: %lu\n",strlen(t));
  57.     printf("Front: %.*s\n", 26, t);
  58.     printf("Back: %s\n", t + strlen(t) - 26);
  59.     printf("UBVal: %d\n",a[1000000]);
  60.  
  61. }
  62.  


pi@RPi4B:~/c-dev/examples $ gcc -O3 1mil3.c -o 1mil3
pi@RPi4B:~/c-dev/examples $ ls -l 1mil3
-rwxr-xr-x 1 pi pi 8140 Dec  1 11:23 1mil3
pi@RPi4B:~/c-dev/examples $ /usr/bin/time ./1mil3
r LEN: 999986
Front: ZYXWVUTSRQPONMLKJIHGFEDCBA
Back: ZYXWVUTSRQPONMLKJIHGFEDCBA
UBVal: 1000000
45.56user 63.56system 1:49.17elapsed 99%CPU (0avgtext+0avgdata 23956maxresident)k
0inputs+0outputs (0major+7535448minor)pagefaults 0swaps
pi@RPi4B:~/c-dev/examples $

« Last Edit: December 01, 2019, 07:34:08 PM by John Spikowski »
ScriptBasic Project Manager/Facilitator

John Spikowski

  • BASIC Developer
  • **
  • Posts: 81
    • View Profile
    • ScriptBasic
Re: Just REM
« Reply #35 on: December 01, 2019, 09:45:22 PM »
Swift 5.1.2

Looking for a faster string reverse.

Code: Text
  1. // Swift 5.1.2 - 1mil3.swift
  2.  
  3. var s = ""
  4. var t = ""
  5. var a = [Int]()
  6. var r = ""
  7.  
  8. for x in 1...1000000 {
  9.   s += String(UnicodeScalar(UInt8(((x - 1) % 26) + 65)))
  10.     a.append(x)
  11.   if s.count == 26 {
  12. //  t += s
  13.     r += s  
  14.     s = ""
  15.   }
  16. }
  17.  
  18. // let r = String(t.reversed())
  19.  
  20. print("r LEN: ", r.count)
  21. print("Front: \(r.prefix(26))")
  22. print("Back:  \(r.suffix(26))")
  23. print("UBVal: ", a[100000 - 1])
  24.  

with string reverse

pi@RPi4B:~/swift-dev/examples $ /usr/bin/time ./main
r LEN:  999986
Front: ZYXWVUTSRQPONMLKJIHGFEDCBA
Back:  ZYXWVUTSRQPONMLKJIHGFEDCBA
UBVal:  100000
322.51user 0.07system 5:22.70elapsed 99%CPU (0avgtext+0avgdata 13836maxresident)k
0inputs+0outputs (0major+3470minor)pagefaults 0swaps
pi@RPi4B:~/swift-dev/examples $


without string reverse

pi@RPi4B:~/swift-dev/examples $ /usr/bin/time ./main
r LEN:  999986
Front: ABCDEFGHIJKLMNOPQRSTUVWXYZ
Back:  ABCDEFGHIJKLMNOPQRSTUVWXYZ
UBVal:  100000
36.12user 0.04system 0:36.17elapsed 99%CPU (0avgtext+0avgdata 12800maxresident)k
0inputs+0outputs (0major+2925minor)pagefaults 0swaps
pi@RPi4B:~/swift-dev/examples $


ScriptBasic Project Manager/Facilitator

John Spikowski

  • BASIC Developer
  • **
  • Posts: 81
    • View Profile
    • ScriptBasic
Re: Just REM
« Reply #36 on: December 02, 2019, 12:50:07 AM »
GO Update (AIR submission)

Code: Go
  1. // GO - 1mil3-2.go - AIR
  2.  
  3. package main
  4.  
  5. import (
  6.     "fmt"
  7.     "strings"
  8. )
  9.  
  10. // Reverse returns its argument string reversed rune-wise left to right.
  11. // From: https://github.com/golang/example/blob/master/stringutil/reverse.go
  12. func Reverse(s string) string {
  13.     r := []rune(s)
  14.     for i, j := 0, len(r)-1; i < len(r)/2; i, j = i+1, j-1 {
  15.         r[i], r[j] = r[j], r[i]
  16.     }
  17.     return string(r)
  18. }
  19.  
  20. func main() {
  21.     var s strings.Builder
  22.     var r = ""
  23.     var t strings.Builder
  24.     var a [1000001]int
  25.  
  26.     for x := 0; x < 1000001; x++ {
  27.         a[x] = x
  28.  
  29.         s.WriteByte(byte((x % 26) + 65))
  30.  
  31.         if s.Len() == 26 {
  32.             t.WriteString(s.String())
  33.             s.Reset()
  34.         }
  35.     }
  36.  
  37.     r = Reverse(t.String())
  38.  
  39.     fmt.Println("r LEN: ", len(r))
  40.     fmt.Println("Front: ", r[0:26])
  41.     fmt.Println("Back:  ", r[len(r)-26:])
  42.     fmt.Println("UBVal: ", a[1000000])
  43.  
  44. }
  45.  


pi@RPi4B:~/go-dev/examples $ go build 1mil3-2.go
pi@RPi4B:~/go-dev/examples $ ls -l 1mil3-2
-rwxr-xr-x 1 pi pi 1763559 Dec  4 18:33 1mil3-2
pi@RPi4B:~/go-dev/examples $ /usr/bin/time ./1mil3-2
r LEN:  999986
Front:  ZYXWVUTSRQPONMLKJIHGFEDCBA
Back:   ZYXWVUTSRQPONMLKJIHGFEDCBA
UBVal:  1000000
0.10user 0.08system 0:00.16elapsed 112%CPU (0avgtext+0avgdata 16868maxresident)k
0inputs+0outputs (0major+4032minor)pagefaults 0swaps
pi@RPi4B:~/go-dev/examples $

« Last Edit: December 05, 2019, 02:39:59 AM by John Spikowski »
ScriptBasic Project Manager/Facilitator

John Spikowski

  • BASIC Developer
  • **
  • Posts: 81
    • View Profile
    • ScriptBasic
Re: Just REM
« Reply #37 on: December 02, 2019, 05:26:34 AM »
Nim (AIR submission)

Code: Text
  1. proc reverse*(str: string): string =
  2.   result = ""
  3.   for index in countdown(str.high, 0):
  4.     result.add(str[index])
  5.  
  6. type
  7.     milarray = array[1000001, int]
  8.  
  9. var
  10.     s = ""
  11.     t = ""
  12.     r:string
  13.     a:milarray
  14.  
  15. for x in 0..1000000:
  16.     a[x] = x
  17.  
  18.     s &= chr((x mod 26) + 65)
  19.  
  20.     if s.len == 26:
  21.         t &= s
  22.         s = ""
  23.  
  24.  
  25. r = t.reverse
  26. echo "r Len: ",r.len
  27. echo "Front: ",r[0..25]
  28. echo "Back:  ",r[r.len-26..r.len-1]
  29. echo "UBVal: ",a[1000000]
  30.  


pi@RPi4B:~/nim-dev/examples $ nim c -d:release onemil3.nim
Hint: used config file '/etc/nim/nim.cfg' [Conf]
Hint: system [Processing]
Hint: onemil3 [Processing]
Hint:  [Link]
Hint: operation successful (12410 lines compiled; 0.566 sec total; 10.754MiB peakmem; Release Build) [SuccessX]
pi@RPi4B:~/nim-dev/examples $ ls -l onemil3
-rwxr-xr-x 1 pi pi 57548 Dec  1 21:21 onemil3
pi@RPi4B:~/nim-dev/examples $ /usr/bin/time ./onemil3
r Len: 999986
Front: ZYXWVUTSRQPONMLKJIHGFEDCBA
Back:  ZYXWVUTSRQPONMLKJIHGFEDCBA
UBVal: 1000000
0.06user 0.05system 0:00.12elapsed 99%CPU (0avgtext+0avgdata 10048maxresident)k
0inputs+0outputs (0major+2294minor)pagefaults 0swaps
pi@RPi4B:~/nim-dev/examples $

ScriptBasic Project Manager/Facilitator

John Spikowski

  • BASIC Developer
  • **
  • Posts: 81
    • View Profile
    • ScriptBasic
Re: Just REM
« Reply #38 on: December 03, 2019, 01:42:35 AM »
JavaScript

Code: Javascript
  1. // JavaScript - 1mil3.js
  2.  
  3. function reverseString(str){
  4.     let strn ="";
  5.     for(let char of str){
  6.         strn = char + strn;
  7.     }
  8.     return strn;
  9. }
  10.  
  11. var s = "";
  12. var t = "";
  13. var a = [1000001];
  14.  
  15. for (x = 1; x <= 1000000; x++) {
  16.   s += String.fromCharCode(((x - 1) % 26) + 65);
  17.   a[x] = x;
  18.   if(s.length == 26) {
  19.         t += s;
  20.         s = "";
  21.   }
  22. }
  23.  
  24. r = reverseString(t);
  25.  
  26. console.log("r LEN: " + r.length);
  27. console.log("Front: " + r.substring(0, 26));
  28. console.log("Back:  " + r.substring(-0, 26));
  29. console.log("UBVal: " + a[1000000]);
  30.  


pi@RPi4B:~/javascript-dev/examples $ /usr/bin/time node 1mil3.js
r LEN: 999986
Front: ZYXWVUTSRQPONMLKJIHGFEDCBA
Back:  ZYXWVUTSRQPONMLKJIHGFEDCBA
UBVal: 1000000
2.50user 0.27system 0:03.13elapsed 88%CPU (0avgtext+0avgdata 78340maxresident)k
38664inputs+0outputs (153major+19367minor)pagefaults 0swaps
pi@RPi4B:~/javascript-dev/examples $

ScriptBasic Project Manager/Facilitator

John Spikowski

  • BASIC Developer
  • **
  • Posts: 81
    • View Profile
    • ScriptBasic
Re: Just REM
« Reply #39 on: December 03, 2019, 05:01:29 AM »
JADE (AIR submission)

Code: C++
  1. #include <jade.hpp>
  2.  
  3. MAIN
  4.     STRING s,t,r;
  5.     ARRAY<int> a;
  6.  
  7.     FOR( VAR x = 0 TO x<1000001 STEP x++ ) DO
  8.         a.push_back(x);
  9.         s += (CHAR)(x%26)+65;
  10.  
  11.         IF ( LEN(s) == 26 ) THEN
  12.             t += s;
  13.             s = "";
  14.         END
  15.     END
  16.  
  17.     r = REVERSE$(t);
  18.  
  19.     PRINT("r LEN: ",LEN(t));
  20.     PRINT("Front: ", LEFT$(r,26));
  21.     PRINT("Back:  ", RIGHT$(r,26));
  22.     PRINT("UBVal: ",a[1000000]);
  23. END
  24.  


pi@RPi4B:~/jade-dev/examples $ g++ -O3 -std=c++11 mil.cpp -ljade -o mil
pi@RPi4B:~/jade-dev/examples $ /usr/bin/time ./mil
r LEN: 999986
Front: ZYXWVUTSRQPONMLKJIHGFEDCBA
Back:  ZYXWVUTSRQPONMLKJIHGFEDCBA
UBVal: 1000000
0.08user 0.04system 0:00.12elapsed 98%CPU (0avgtext+0avgdata 9012maxresident)k
0inputs+0outputs (0major+3762minor)pagefaults 0swaps
pi@RPi4B:~/jade-dev/examples $

ScriptBasic Project Manager/Facilitator

John Spikowski

  • BASIC Developer
  • **
  • Posts: 81
    • View Profile
    • ScriptBasic
Re: Just REM
« Reply #40 on: December 03, 2019, 07:35:46 PM »
C Update  (AIR submission)

Code: C
  1. // C Update - 1mil3.c - AIR
  2.  
  3. #include <stdio.h>
  4. #include <stdlib.h>
  5. #include <string.h>
  6.  
  7. char *strrev(char *str)
  8. {
  9.     if (!str || ! *str)
  10.         return str;
  11.  
  12.     int i = strlen(str) - 1, j = 0;
  13.  
  14.     char ch;
  15.     while (i > j) {
  16.         ch = str[i];
  17.         str[i] = str[j];
  18.         str[j] = ch;
  19.         i--;
  20.         j++;
  21.     }
  22.     return str;
  23. }
  24.  
  25.  
  26. int main() {
  27.     int a[1000001] = {0};
  28.     char *t=NULL;
  29.     char tmp[2] = {0};
  30.     char s[27] = {0};
  31.     FILE *t_stream;
  32.     size_t len;
  33.  
  34.     t_stream = open_memstream(&t, &len);
  35.  
  36.     for (int x = 0; x < 1000001; x++) {
  37.         a[x] = x;
  38.         tmp[0] = (char)(x%26)+65;
  39.  
  40.         strncat(s,tmp,2);
  41.  
  42.         if (strlen(s) == 26) {
  43.             fprintf(t_stream, "%s",s);
  44.             s[0] = '\0';
  45.         }
  46.  
  47.     }
  48.  
  49.     fclose(t_stream);
  50.  
  51.     strrev(t);
  52.  
  53.     printf("r LEN: %lu\n",strlen(t));
  54.     printf("Front: %.*s\n", 26, t);
  55.     printf("Back:  %s\n", t + strlen(t) - 26);
  56.     printf("UBVal: %d\n",a[1000000]);
  57.  
  58.     free(t);
  59.  
  60. }
  61.  


pi@RPi4B:~/c-dev/examples $ gcc -O3 1mil3.2.c -o 1mil3.2
pi@RPi4B:~/c-dev/examples $ ls -l 1mil3.2
-rwxr-xr-x 1 pi pi 8296 Dec  3 11:31 1mil3.2
pi@RPi4B:~/c-dev/examples $ /usr/bin/time ./1mil3.2
r LEN: 999986
Front: ZYXWVUTSRQPONMLKJIHGFEDCBA
Back:  ZYXWVUTSRQPONMLKJIHGFEDCBA
UBVal: 1000000
0.14user 0.02system 0:00.18elapsed 97%CPU (0avgtext+0avgdata 5888maxresident)k
0inputs+0outputs (0major+1565minor)pagefaults 0swaps
pi@RPi4B:~/c-dev/examples $

ScriptBasic Project Manager/Facilitator

John Spikowski

  • BASIC Developer
  • **
  • Posts: 81
    • View Profile
    • ScriptBasic
Re: Just REM
« Reply #41 on: December 04, 2019, 01:29:49 AM »
Perl

Code: Perl
  1. # Perl - 1mil3.pl
  2.  
  3. my $s = "";
  4. my $t = "";
  5. my $a = [1000000];
  6.  
  7. for (my $x = 1; $x <= 1000000; $x++) {
  8.   $s = $s . chr((($x - 1) % 26) + 65);
  9.   $a[$x] = $x;
  10.   if (length($s) == 26) {
  11.     $t = $t . $s;
  12.     $s = "";
  13.   }
  14. }
  15.  
  16.  
  17. my $r = scalar reverse $t;
  18.  
  19. printf("r LEN: %d\n", length($r));
  20. printf("Front: %s\n", substr($r, 0, 26));
  21. printf("Back:  %s\n", substr($r, -26));
  22. printf("UBVal: %d\n", $a[1000000]);
  23.  


pi@RPi4B:~/perl-dev/examples $ /usr/bin/time perl 1mil3.pl
r LEN: 999986
Front: ZYXWVUTSRQPONMLKJIHGFEDCBA
Back:  ZYXWVUTSRQPONMLKJIHGFEDCBA
UBVal: 1000000
1.13user 0.07system 0:01.22elapsed 99%CPU (0avgtext+0avgdata 33636maxresident)k
0inputs+0outputs (0major+7705minor)pagefaults 0swaps
pi@RPi4B:~/perl-dev/examples $

ScriptBasic Project Manager/Facilitator

John Spikowski

  • BASIC Developer
  • **
  • Posts: 81
    • View Profile
    • ScriptBasic
Re: Just REM
« Reply #42 on: December 04, 2019, 06:23:02 AM »
Java

Code: Java
  1. // Java - 1mil3.java
  2.  
  3. class onemil3
  4.   {
  5.   public static void main(String args[])
  6.   {
  7.   String s = "";
  8.   String t = "";
  9.   int c = 0;
  10.   int[] a = new int[1000001];
  11.  
  12.   for (int x = 1; x <= 1000000; x++) {
  13.     c = ((x - 1) % 26) + 65;          
  14.     s = s + (char) c;
  15.     a[x] = x;
  16.     if(s.length() == 26) {
  17.       t = t + s;
  18.       s = "";
  19.     }
  20.   }
  21.  
  22.   StringBuilder r = new StringBuilder();
  23.   r.append(t);
  24.   r = r.reverse();
  25.  
  26.   System.out.println("r LEN: " + r.length());
  27.   System.out.println("Front: " + r.substring(0, 26));
  28.   System.out.println("Back:  " + r.substring(r.length() - 26));  
  29.   System.out.println("UBVal: " + a[1000000]);
  30.   }
  31. }
  32.  


pi@RPi4B:~/java-dev/examples $ /usr/bin/time java onemil3
r LEN: 999986
Front: ZYXWVUTSRQPONMLKJIHGFEDCBA
Back:  ZYXWVUTSRQPONMLKJIHGFEDCBA
UBVal: 1000000
43.79user 2.03system 0:34.78elapsed 131%CPU (0avgtext+0avgdata 144432maxresident)k
0inputs+96outputs (0major+33910minor)pagefaults 0swaps
pi@RPi4B:~/java-dev/examples $



This version is using the StringBuilder class rather than adding a character or alphabet string to the result string. Night and day.

Code: Java
  1. // Java - 1mil3.java
  2.  
  3. class onemil3
  4.   {
  5.   public static void main(String args[])
  6.   {
  7.   StringBuilder s = new StringBuilder();
  8.   StringBuilder t = new StringBuilder();
  9.   int c = 0;
  10.   int[] a = new int[1000001];
  11.  
  12.   for (int x = 1; x <= 1000000; x++) {
  13.     c = ((x - 1) % 26) + 65;          
  14.     s.append((char) c);
  15.     a[x] = x;
  16.     if(s.length() == 26) {
  17.       t.append(s);
  18.       s.delete(0, s.length());
  19.     }
  20.   }
  21.  
  22.   StringBuilder r = new StringBuilder();
  23.   r.append(t);
  24.   r = r.reverse();
  25.  
  26.   System.out.println("r LEN: " + r.length());
  27.   System.out.println("Front: " + r.substring(0, 26));
  28.   System.out.println("Back:  " + r.substring(r.length() - 26));  
  29.   System.out.println("UBVal: " + a[1000000]);
  30.   }
  31. }
  32.  


pi@RPi4B:~/java-dev/examples $ javac 1mil3.java
pi@RPi4B:~/java-dev/examples $ /usr/bin/time java onemil3
r LEN: 999986
Front: ZYXWVUTSRQPONMLKJIHGFEDCBA
Back:  ZYXWVUTSRQPONMLKJIHGFEDCBA
UBVal: 1000000
0.49user 0.14system 0:00.53elapsed 119%CPU (0avgtext+0avgdata 31948maxresident)k
0inputs+64outputs (0major+5024minor)pagefaults 0swaps
pi@RPi4B:~/java-dev/examples $

« Last Edit: December 04, 2019, 07:18:20 AM by John Spikowski »
ScriptBasic Project Manager/Facilitator

John Spikowski

  • BASIC Developer
  • **
  • Posts: 81
    • View Profile
    • ScriptBasic
Re: Just REM
« Reply #43 on: December 04, 2019, 08:40:38 PM »
Here is the String / Array language challenge results table.

« Last Edit: December 05, 2019, 02:50:09 AM by John Spikowski »
ScriptBasic Project Manager/Facilitator

John Spikowski

  • BASIC Developer
  • **
  • Posts: 81
    • View Profile
    • ScriptBasic
Re: Just REM
« Reply #44 on: Today at 03:06:32 AM »
I was curious if I expanded out the expression to concatenate strings in ScriptBasic would it help?  NOT and good to know for future use.

Example

Was:  t &= s

Changed  To:  t = t & s

&= seems to be ScriptBasic's StringBuilder function.

Code: Script BASIC
  1. ' ScriptBasic - 1mil.sb
  2.  
  3. s = ""
  4. t = ""
  5. SPLITA STRING(1000001,"0") BY "" TO a
  6.  
  7. FOR x = 1 TO 1000000
  8.   s = s & CHR(((x - 1) % 26) + 65)
  9.   a[x] = x
  10.   IF LEN(s) = 26 THEN
  11.     t = t & s
  12.     s = ""
  13.   END IF
  14. NEXT
  15. t = STRREVERSE(t)
  16. PRINT "t LEN: ",LEN(t),"\n"
  17. PRINT "Front: ",LEFT(t, 26),"\n"
  18. PRINT "Back:  ",RIGHT(t, 26),"\n"
  19. PRINT "UBVal: ",a[1000000],"\n"
  20.  


pi@RPi4B:~/sbrt/examples $ timex scriba  1mil3.sb
t LEN: 999986
Front: ZYXWVUTSRQPONMLKJIHGFEDCBA
Back:  ZYXWVUTSRQPONMLKJIHGFEDCBA
UBVal: 1000000
127.51user 35.17system 2:42.93elapsed 99%CPU (0avgtext+0avgdata 171488maxresident)k
0inputs+0outputs (0major+4122875minor)pagefaults 0swaps
pi@RPi4B:~/sbrt/examples $

 
« Last Edit: Today at 03:41:48 AM by John Spikowski »
ScriptBasic Project Manager/Facilitator