WeixiangYan/CodeTransOcean huggingface dataset:
Task: Kronecker product







Python: 


a1 = [[1, 2], [3, 4]]
b1 = [[0, 5], [6, 7]]


a2 = [[0, 1, 0], [1, 1, 1], [0, 1, 0]]
b2 = [[1, 1, 1, 1], [1, 0, 0, 1], [1, 1, 1, 1]]

def kronecker(matrix1, matrix2):
    final_list = []
    sub_list = []

    count = len(matrix2)

    for elem1 in matrix1:
        counter = 0
        check = 0
        while check < count:
            for num1 in elem1:
                for num2 in matrix2[counter]:
                    sub_list.append(num1 * num2)
            counter += 1
            final_list.append(sub_list)
            sub_list = []
            check +=1
            
    return final_list


result1 = kronecker(a1, b1)
for elem in result1:
    print(elem)

print("")


result2 = kronecker(a2, b2)
for elem in result2:
    print(elem)
Task: Kronecker product








VB: 
dim a(),b(),r()
 
sub kroneckerproduct 
    m=ubound(a,1): n=ubound(a,2)
    p=ubound(b,1): q=ubound(b,2)
    rtn=m*p
    ctn=n*q
    redim r(rtn,ctn) 
    for i=1 to m
        for j=1 to n
            for k=1 to p
                for l=1 to q
                    r(p*(i-1)+k,q*(j-1)+l)=a(i,j)*b(k,l)  
    next: next: next: next
end sub 
 
sub printmatrix(text,m,w)
    wscript.stdout.writeline text
    select case m
        case "a": ni=ubound(a,1): nj=ubound(a,2)
        case "b": ni=ubound(b,1): nj=ubound(b,2)
        case "r": ni=ubound(r,1): nj=ubound(r,2)
    end select
    for i=1 to ni
        for j=1 to nj
            select case m
                case "a": k=a(i,j)
                case "b": k=b(i,j)
                case "r": k=r(i,j)
            end select
            wscript.stdout.write right(space(w)&k,w)
        next
        wscript.stdout.writeline
    next
end sub 
 
sub printall(w)
    printmatrix "matrix a:", "a", w 
    printmatrix "matrix b:", "b", w 
    printmatrix "kronecker product:", "r", w  
end sub 
 
sub main()
    xa=array( 1, 2, _
              3, 4)
    redim a(2,2)
    k=0: for i=1 to ubound(a,1): for j=1 to ubound(a,1)
        a(i,j)=xa(k): k=k+1
    next:next
    xb=array( 0, 5, _ 
              6, 7)
    redim b(2,2)
    k=0: for i=1 to ubound(b,1): for j=1 to ubound(b,1)
        b(i,j)=xb(k): k=k+1
    next:next
    kroneckerproduct
    printall 3
 
    xa=array( 0, 1, 0, _ 
              1, 1, 1, _ 
              0, 1, 0)
    redim a(3,3)
    k=0: for i=1 to ubound(a,1): for j=1 to ubound(a,1)
        a(i,j)=xa(k): k=k+1
    next:next
    xb=array( 1, 1, 1, 1, _ 
              1, 0, 0, 1, _ 
              1, 1, 1, 1) 
    redim b(3,4)
    k=0: for i=1 to ubound(b,1): for j=1 to ubound(b,1)
        b(i,j)=xb(k): k=k+1
    next:next
    kroneckerproduct
    printall 2
end sub 

main
Task: Kronecker product




Go: package main

import (
    "fmt"
    "strings"
)

type uintMatrix [][]uint

func (m uintMatrix) String() string {
    var max uint
    for _, r := range m {
        for _, e := range r {
            if e > max {
                max = e
            }
        }
    }
    w := len(fmt.Sprint(max))
    b := &strings.Builder{}
    for _, r := range m {
        fmt.Fprintf(b, "|%*d", w, r[0])
        for _, e := range r[1:] {
            fmt.Fprintf(b, " %*d", w, e)
        }
        fmt.Fprintln(b, "|")
    }
    return b.String()
}

func kronecker(m1, m2 uintMatrix) uintMatrix {
    p := make(uintMatrix, len(m1)*len(m2))
    for r1i, r1 := range m1 {
        for r2i, r2 := range m2 {
            rp := make([]uint, len(r1)*len(r2))
            for c1i, e1 := range r1 {
                for c2i, e2 := range r2 {
                    rp[c1i*len(r2)+c2i] = e1 * e2
                }
            }
            p[r1i*len(m2)+r2i] = rp
        }
    }
    return p
}

func sample(m1, m2 uintMatrix) {
    fmt.Println("m1:")
    fmt.Print(m1)
    fmt.Println("m2:")
    fmt.Print(m2)
    fmt.Println("m1 ⊗ m2:")
    fmt.Print(kronecker(m1, m2))
}

func main() {
    sample(uintMatrix{
        {1, 2},
        {3, 4},
    }, uintMatrix{
        {0, 5},
        {6, 7},
    })
    sample(uintMatrix{
        {0, 1, 0},
        {1, 1, 1},
        {0, 1, 0},
    }, uintMatrix{
        {1, 1, 1, 1},
        {1, 0, 0, 1},
        {1, 1, 1, 1},
    })
}
Task: Kronecker product







Python: 


a1 = [[1, 2], [3, 4]]
b1 = [[0, 5], [6, 7]]


a2 = [[0, 1, 0], [1, 1, 1], [0, 1, 0]]
b2 = [[1, 1, 1, 1], [1, 0, 0, 1], [1, 1, 1, 1]]

def kronecker(matrix1, matrix2):
    final_list = []
    sub_list = []

    count = len(matrix2)

    for elem1 in matrix1:
        counter = 0
        check = 0
        while check < count:
            for num1 in elem1:
                for num2 in matrix2[counter]:
                    sub_list.append(num1 * num2)
            counter += 1
            final_list.append(sub_list)
            sub_list = []
            check +=1
            
    return final_list


result1 = kronecker(a1, b1)
for elem in result1:
    print(elem)

print("")


result2 = kronecker(a2, b2)
for elem in result2:
    print(elem)




Fortran:       MODULE ARRAYMUSH	
       CONTAINS		
        SUBROUTINE KPRODUCT(A,B,AB)	
Considers the arrays to be addressed as A(row,column), despite any storage order arrangements.        .
Creating array AB to fit here, adjusting the caller's array AB, may not work on some compilers.
         INTEGER A(:,:),B(:,:)		
         INTEGER, ALLOCATABLE:: AB(:,:)	
         INTEGER R,RA,RB,C,CA,CB,I	
          RA = UBOUND(A,DIM = 1)	
          CA = UBOUND(A,DIM = 2)	
          RB = UBOUND(B,DIM = 1)	
          CB = UBOUND(B,DIM = 2)	
          WRITE (6,1) "A",RA,CA,"B",RB,CB,"A.k.B",RA*RB,CA*CB	
    1     FORMAT (3(A," is ",I0,"x",I0,1X))	
          IF (ALLOCATED(AB)) DEALLOCATE(AB)	
          ALLOCATE (AB(RA*RB,CA*CB))		
          R = 0		
          DO I = 1,RA	
            C = 0		
            DO J = 1,CA		
              AB(R + 1:R + RB,C + 1:C + CB) = A(I,J)*B	
              C = C + CB		
            END DO		
            R = R + RB		
          END DO	
        END SUBROUTINE KPRODUCT	

        SUBROUTINE SHOW(F,A)	
         INTEGER F	
         INTEGER A(:,:)	
         INTEGER R	
          DO R = 1,UBOUND(A,DIM = 1)	
            WRITE (F,1) A(R,:)		
    1       FORMAT (666I3)		
          END DO			
        END SUBROUTINE SHOW	
      END MODULE ARRAYMUSH	

      PROGRAM POKE
      USE ARRAYMUSH
      INTEGER A(2,2),B(2,2)		
      INTEGER, ALLOCATABLE:: AB(:,:)	
      INTEGER C(3,3),D(3,4)		
      DATA A/1,3, 2,4/,B/0,6, 5,7/	
      DATA C/0,1,0, 1,1,1, 0,1,0/	
      DATA D/1,1,1, 1,0,1, 1,0,1, 1,1,1/

      WRITE (6,*) "First test..."
      CALL KPRODUCT(A,B,AB)
      CALL SHOW (6,AB)

      WRITE (6,*)
      WRITE (6,*) "Second test..."
      CALL KPRODUCT(C,D,AB)
      CALL SHOW (6,AB)

      END
Task: Split a character string based on change of character



C#: using System;
using System.Linq;
using System.Collections.Generic;

public class Program
{
    string s = @"gHHH5YY++
    Console.WriteLine(s.RunLengthSplit().Delimit(", "));
}

public static class Extensions
{
    public static IEnumerable<string> RunLengthSplit(this string source) {
        using (var enumerator = source.GetEnumerator()) {
            if (!enumerator.MoveNext()) yield break;
            char previous = enumerator.Current;
            int count = 1;
            while (enumerator.MoveNext()) {
                if (previous == enumerator.Current) {
                    count++;
                } else {
                    yield return new string(Enumerable.Repeat(previous, count).ToArray());
                    previous = enumerator.Current;
                    count = 1;
                }
            }
            yield return new string(Enumerable.Repeat(previous, count).ToArray());
        }
    }

    public static string Delimit<T>(this IEnumerable<T> source, string separator = "") => string.Join(separator ?? "", source);
}









Ada: with Ada.Text_IO;
procedure Split is 
  procedure Print_Tokens (s : String) is
    i, j : Integer := s'First;
  begin
    loop
      while j<=s'Last and then s(j)=s(i) loop j := j + 1; end loop;
      if i/=s'first then Ada.Text_IO.Put (", "); end if;
      Ada.Text_IO.Put (s(i..j-1));
      i := j;
      exit when j>s'last;
    end loop;
  end Print_Tokens;
begin
  Print_Tokens ("gHHH5YY+++");
end split;
Task: Split a character string based on change of character

C: #include <stdio.h>
#include <stdlib.h>
#include <string.h>
char *split(char *str);
int main(int argc,char **argv)
{
	char input[13]="gHHH5YY++
	printf("%s\n",split(input));
}
char *split(char *str)
{
	char last=*str,*result=malloc(3*strlen(str)),*counter=result;
	for (char *c=str;*c;c++) {
		if (*c!=last) {
			strcpy(counter,", ");
			counter+=2;
			last=*c;
		}
		*counter=*c;
		counter++;
	}
	*(counter--)='\0';
	return realloc(result,strlen(result));
}











Ada: with Ada.Text_IO;
procedure Split is 
  procedure Print_Tokens (s : String) is
    i, j : Integer := s'First;
  begin
    loop
      while j<=s'Last and then s(j)=s(i) loop j := j + 1; end loop;
      if i/=s'first then Ada.Text_IO.Put (", "); end if;
      Ada.Text_IO.Put (s(i..j-1));
      i := j;
      exit when j>s'last;
    end loop;
  end Print_Tokens;
begin
  Print_Tokens ("gHHH5YY+++");
end split;
Task: Split a character string based on change of character


C++: 
#include<string>
#include<iostream>

auto split(const std::string& input, const std::string& delim){
	std::string res;
	for(auto ch : input){
		if(!res.empty() && ch != res.back())
			res += delim;
		res += ch;
	}
	return res;
}

int main(){
	std::cout << split("gHHH5  ))YY++,,,
}










Ada: with Ada.Text_IO;
procedure Split is 
  procedure Print_Tokens (s : String) is
    i, j : Integer := s'First;
  begin
    loop
      while j<=s'Last and then s(j)=s(i) loop j := j + 1; end loop;
      if i/=s'first then Ada.Text_IO.Put (", "); end if;
      Ada.Text_IO.Put (s(i..j-1));
      i := j;
      exit when j>s'last;
    end loop;
  end Print_Tokens;
begin
  Print_Tokens ("gHHH5YY+++");
end split;
Task: Split a character string based on change of character




Go: package main

import (
    "fmt"
    "strings"
)

func main() {
    fmt.Println(scc(`gHHH5YY++
}

func scc(s string) string {
    if len(s) < 2 {
        return s
    }
    var b strings.Builder
    p := s[0]
    b.WriteByte(p)
    for _, c := range []byte(s[1:]) {
        if c != p {
            b.WriteString(", ")
        }
        b.WriteByte(c)
        p = c
    }
    return b.String()
}








Ada: with Ada.Text_IO;
procedure Split is 
  procedure Print_Tokens (s : String) is
    i, j : Integer := s'First;
  begin
    loop
      while j<=s'Last and then s(j)=s(i) loop j := j + 1; end loop;
      if i/=s'first then Ada.Text_IO.Put (", "); end if;
      Ada.Text_IO.Put (s(i..j-1));
      i := j;
      exit when j>s'last;
    end loop;
  end Print_Tokens;
begin
  Print_Tokens ("gHHH5YY+++");
end split;
Task: Split a character string based on change of character





Java: package org.rosettacode;

import java.util.ArrayList;
import java.util.List;



public class SplitStringByCharacterChange {
    
    public static void main(String... args){
        for (String string : args){
            
            List<String> resultStrings = splitStringByCharacter(string);
            String output = formatList(resultStrings);
            System.out.println(output);
        }
    }
    
    
    public static List<String> splitStringByCharacter(String string){
        
        List<String> resultStrings = new ArrayList<>();
        StringBuilder currentString = new StringBuilder();
        
        for (int pointer = 0; pointer < string.length(); pointer++){
            
            currentString.append(string.charAt(pointer));
            
            if (pointer == string.length() - 1 
                    || currentString.charAt(0) != string.charAt(pointer + 1)) {
                resultStrings.add(currentString.toString());
                currentString = new StringBuilder();
            }
        }
        
        return resultStrings;
    }
    
    
    public static String formatList(List<String> list){
        
        StringBuilder output = new StringBuilder();
        
        for (int pointer = 0; pointer < list.size(); pointer++){
            output.append(list.get(pointer));
            
            if (pointer != list.size() - 1){
                output.append(", ");
            }
        }
        
        return output.toString();
    }
}







Ada: with Ada.Text_IO;
procedure Split is 
  procedure Print_Tokens (s : String) is
    i, j : Integer := s'First;
  begin
    loop
      while j<=s'Last and then s(j)=s(i) loop j := j + 1; end loop;
      if i/=s'first then Ada.Text_IO.Put (", "); end if;
      Ada.Text_IO.Put (s(i..j-1));
      i := j;
      exit when j>s'last;
    end loop;
  end Print_Tokens;
begin
  Print_Tokens ("gHHH5YY+++");
end split;
Task: Split a character string based on change of character







Python: from itertools import groupby

def splitter(text):
    return ', '.join(''.join(group) for key, group in groupby(text))

if __name__ == '__main__':
    txt = 'gHHH5YY++///\\'      
    print(f'Input: {txt}\nSplit: {splitter(txt)}')





Ada: with Ada.Text_IO;
procedure Split is 
  procedure Print_Tokens (s : String) is
    i, j : Integer := s'First;
  begin
    loop
      while j<=s'Last and then s(j)=s(i) loop j := j + 1; end loop;
      if i/=s'first then Ada.Text_IO.Put (", "); end if;
      Ada.Text_IO.Put (s(i..j-1));
      i := j;
      exit when j>s'last;
    end loop;
  end Print_Tokens;
begin
  Print_Tokens ("gHHH5YY+++");
end split;
Task: Split a character string based on change of character








VB: Option Explicit

Sub Split_string_based_on_change_character()
Dim myArr() As String, T As String

Const STRINPUT As String = "gHHH5YY++///\"
Const SEP As String = ", "
    
    myArr = Split_Special(STRINPUT)
    T = Join(myArr, SEP)
    Debug.Print Left(T, Len(T) - Len(SEP))
End Sub

Function Split_Special(Ch As String) As String()

Dim tb, i&, st As String, cpt As Long, R() As String

    tb = Split(StrConv(Ch, vbUnicode), Chr(0))
    st = tb(LBound(tb))
    ReDim R(cpt)
    R(cpt) = st
    For i = 1 To UBound(tb)
        If tb(i) = st Then
            R(cpt) = R(cpt) & st
        Else
            st = tb(i)
            cpt = cpt + 1
            ReDim Preserve R(cpt)
            R(cpt) = st
        End If
    Next
    Split_Special = R
End Function




Ada: with Ada.Text_IO;
procedure Split is 
  procedure Print_Tokens (s : String) is
    i, j : Integer := s'First;
  begin
    loop
      while j<=s'Last and then s(j)=s(i) loop j := j + 1; end loop;
      if i/=s'first then Ada.Text_IO.Put (", "); end if;
      Ada.Text_IO.Put (s(i..j-1));
      i := j;
      exit when j>s'last;
    end loop;
  end Print_Tokens;
begin
  Print_Tokens ("gHHH5YY+++");
end split;
Task: Split a character string based on change of character

C: #include <stdio.h>
#include <stdlib.h>
#include <string.h>
char *split(char *str);
int main(int argc,char **argv)
{
	char input[13]="gHHH5YY++
	printf("%s\n",split(input));
}
char *split(char *str)
{
	char last=*str,*result=malloc(3*strlen(str)),*counter=result;
	for (char *c=str;*c;c++) {
		if (*c!=last) {
			strcpy(counter,", ");
			counter+=2;
			last=*c;
		}
		*counter=*c;
		counter++;
	}
	*(counter--)='\0';
	return realloc(result,strlen(result));
}
Task: Split a character string based on change of character



C#: using System;
using System.Linq;
using System.Collections.Generic;

public class Program
{
    string s = @"gHHH5YY++
    Console.WriteLine(s.RunLengthSplit().Delimit(", "));
}

public static class Extensions
{
    public static IEnumerable<string> RunLengthSplit(this string source) {
        using (var enumerator = source.GetEnumerator()) {
            if (!enumerator.MoveNext()) yield break;
            char previous = enumerator.Current;
            int count = 1;
            while (enumerator.MoveNext()) {
                if (previous == enumerator.Current) {
                    count++;
                } else {
                    yield return new string(Enumerable.Repeat(previous, count).ToArray());
                    previous = enumerator.Current;
                    count = 1;
                }
            }
            yield return new string(Enumerable.Repeat(previous, count).ToArray());
        }
    }

    public static string Delimit<T>(this IEnumerable<T> source, string separator = "") => string.Join(separator ?? "", source);
}
Task: Split a character string based on change of character


C++: 
#include<string>
#include<iostream>

auto split(const std::string& input, const std::string& delim){
	std::string res;
	for(auto ch : input){
		if(!res.empty() && ch != res.back())
			res += delim;
		res += ch;
	}
	return res;
}

int main(){
	std::cout << split("gHHH5  ))YY++,,,
}
Task: Split a character string based on change of character





Java: package org.rosettacode;

import java.util.ArrayList;
import java.util.List;



public class SplitStringByCharacterChange {
    
    public static void main(String... args){
        for (String string : args){
            
            List<String> resultStrings = splitStringByCharacter(string);
            String output = formatList(resultStrings);
            System.out.println(output);
        }
    }
    
    
    public static List<String> splitStringByCharacter(String string){
        
        List<String> resultStrings = new ArrayList<>();
        StringBuilder currentString = new StringBuilder();
        
        for (int pointer = 0; pointer < string.length(); pointer++){
            
            currentString.append(string.charAt(pointer));
            
            if (pointer == string.length() - 1 
                    || currentString.charAt(0) != string.charAt(pointer + 1)) {
                resultStrings.add(currentString.toString());
                currentString = new StringBuilder();
            }
        }
        
        return resultStrings;
    }
    
    
    public static String formatList(List<String> list){
        
        StringBuilder output = new StringBuilder();
        
        for (int pointer = 0; pointer < list.size(); pointer++){
            output.append(list.get(pointer));
            
            if (pointer != list.size() - 1){
                output.append(", ");
            }
        }
        
        return output.toString();
    }
}
Task: Split a character string based on change of character







Python: from itertools import groupby

def splitter(text):
    return ', '.join(''.join(group) for key, group in groupby(text))

if __name__ == '__main__':
    txt = 'gHHH5YY++///\\'      
    print(f'Input: {txt}\nSplit: {splitter(txt)}')
Task: Split a character string based on change of character








VB: Option Explicit

Sub Split_string_based_on_change_character()
Dim myArr() As String, T As String

Const STRINPUT As String = "gHHH5YY++///\"
Const SEP As String = ", "
    
    myArr = Split_Special(STRINPUT)
    T = Join(myArr, SEP)
    Debug.Print Left(T, Len(T) - Len(SEP))
End Sub

Function Split_Special(Ch As String) As String()

Dim tb, i&, st As String, cpt As Long, R() As String

    tb = Split(StrConv(Ch, vbUnicode), Chr(0))
    st = tb(LBound(tb))
    ReDim R(cpt)
    R(cpt) = st
    For i = 1 To UBound(tb)
        If tb(i) = st Then
            R(cpt) = R(cpt) & st
        Else
            st = tb(i)
            cpt = cpt + 1
            ReDim Preserve R(cpt)
            R(cpt) = st
        End If
    Next
    Split_Special = R
End Function
Task: Split a character string based on change of character




Go: package main

import (
    "fmt"
    "strings"
)

func main() {
    fmt.Println(scc(`gHHH5YY++
}

func scc(s string) string {
    if len(s) < 2 {
        return s
    }
    var b strings.Builder
    p := s[0]
    b.WriteByte(p)
    for _, c := range []byte(s[1:]) {
        if c != p {
            b.WriteString(", ")
        }
        b.WriteByte(c)
        p = c
    }
    return b.String()
}
Task: Split a character string based on change of character



C#: using System;
using System.Linq;
using System.Collections.Generic;

public class Program
{
    string s = @"gHHH5YY++
    Console.WriteLine(s.RunLengthSplit().Delimit(", "));
}

public static class Extensions
{
    public static IEnumerable<string> RunLengthSplit(this string source) {
        using (var enumerator = source.GetEnumerator()) {
            if (!enumerator.MoveNext()) yield break;
            char previous = enumerator.Current;
            int count = 1;
            while (enumerator.MoveNext()) {
                if (previous == enumerator.Current) {
                    count++;
                } else {
                    yield return new string(Enumerable.Repeat(previous, count).ToArray());
                    previous = enumerator.Current;
                    count = 1;
                }
            }
            yield return new string(Enumerable.Repeat(previous, count).ToArray());
        }
    }

    public static string Delimit<T>(this IEnumerable<T> source, string separator = "") => string.Join(separator ?? "", source);
}








Fortran:       SUBROUTINE SPLATTER(TEXT)	
Can't display the inserted commas in a different colour so as not to look like any commas in TEXT.
       CHARACTER*(*) TEXT	
       INTEGER L	
       CHARACTER*1 C	
        IF (LEN(TEXT).LE.0) RETURN	
        C = TEXT(1:1)			
        DO L = 1,LEN(TEXT)	
          IF (C.NE.TEXT(L:L)) THEN	
            C = TEXT(L:L)			
            WRITE (6,1) ", "			
          END IF			
          WRITE (6,1) C			
    1     FORMAT (A,$)			
        END DO			
        WRITE (6,1)	
      END SUBROUTINE SPLATTER	

      PROGRAM POKE
      CALL SPLATTER("gHHH5YY++///\")	
      END
Task: Split a character string based on change of character


C++: 
#include<string>
#include<iostream>

auto split(const std::string& input, const std::string& delim){
	std::string res;
	for(auto ch : input){
		if(!res.empty() && ch != res.back())
			res += delim;
		res += ch;
	}
	return res;
}

int main(){
	std::cout << split("gHHH5  ))YY++,,,
}









Fortran:       SUBROUTINE SPLATTER(TEXT)	
Can't display the inserted commas in a different colour so as not to look like any commas in TEXT.
       CHARACTER*(*) TEXT	
       INTEGER L	
       CHARACTER*1 C	
        IF (LEN(TEXT).LE.0) RETURN	
        C = TEXT(1:1)			
        DO L = 1,LEN(TEXT)	
          IF (C.NE.TEXT(L:L)) THEN	
            C = TEXT(L:L)			
            WRITE (6,1) ", "			
          END IF			
          WRITE (6,1) C			
    1     FORMAT (A,$)			
        END DO			
        WRITE (6,1)	
      END SUBROUTINE SPLATTER	

      PROGRAM POKE
      CALL SPLATTER("gHHH5YY++///\")	
      END
Task: Split a character string based on change of character

C: #include <stdio.h>
#include <stdlib.h>
#include <string.h>
char *split(char *str);
int main(int argc,char **argv)
{
	char input[13]="gHHH5YY++
	printf("%s\n",split(input));
}
char *split(char *str)
{
	char last=*str,*result=malloc(3*strlen(str)),*counter=result;
	for (char *c=str;*c;c++) {
		if (*c!=last) {
			strcpy(counter,", ");
			counter+=2;
			last=*c;
		}
		*counter=*c;
		counter++;
	}
	*(counter--)='\0';
	return realloc(result,strlen(result));
}










Fortran:       SUBROUTINE SPLATTER(TEXT)	
Can't display the inserted commas in a different colour so as not to look like any commas in TEXT.
       CHARACTER*(*) TEXT	
       INTEGER L	
       CHARACTER*1 C	
        IF (LEN(TEXT).LE.0) RETURN	
        C = TEXT(1:1)			
        DO L = 1,LEN(TEXT)	
          IF (C.NE.TEXT(L:L)) THEN	
            C = TEXT(L:L)			
            WRITE (6,1) ", "			
          END IF			
          WRITE (6,1) C			
    1     FORMAT (A,$)			
        END DO			
        WRITE (6,1)	
      END SUBROUTINE SPLATTER	

      PROGRAM POKE
      CALL SPLATTER("gHHH5YY++///\")	
      END