WeixiangYan/CodeTransOcean huggingface dataset:
Task: Munchausen numbers








VB: Option Explicit

Sub Main_Munchausen_numbers()
Dim i&

    For i = 1 To 5000
        If IsMunchausen(i) Then Debug.Print i & " is a munchausen number."
    Next i
End Sub

Function IsMunchausen(Number As Long) As Boolean
Dim Digits, i As Byte, Tot As Long

    Digits = Split(StrConv(Number, vbUnicode), Chr(0))
    For i = 0 To UBound(Digits) - 1
        Tot = (Digits(i) ^ Digits(i)) + Tot
    Next i
    IsMunchausen = (Tot = Number)
End Function


COBOL:        IDENTIFICATION DIVISION.
       PROGRAM-ID.  MUNCHAUSEN.
 
       DATA DIVISION.
       WORKING-STORAGE SECTION.
       01 VARIABLES.
          03 CANDIDATE   PIC 9(4).
          03 DIGITS      PIC 9 OCCURS 4 TIMES, REDEFINES CANDIDATE.
          03 DIGIT       PIC 9.
          03 POWER-SUM   PIC 9(5).

       01 OUTPUT-LINE.
          03 OUT-NUM     PIC ZZZ9.

       PROCEDURE DIVISION.
       BEGIN.
           PERFORM MUNCHAUSEN-TEST VARYING CANDIDATE FROM 1 BY 1
               UNTIL CANDIDATE IS GREATER THAN 6000.
           STOP RUN.

       MUNCHAUSEN-TEST.
           MOVE ZERO TO POWER-SUM.
           MOVE 1 TO DIGIT.
           INSPECT CANDIDATE TALLYING DIGIT FOR LEADING '0'.
           PERFORM ADD-DIGIT-POWER VARYING DIGIT FROM DIGIT BY 1
               UNTIL DIGIT IS GREATER THAN 4.
           IF POWER-SUM IS EQUAL TO CANDIDATE,
               MOVE CANDIDATE TO OUT-NUM,
               DISPLAY OUTPUT-LINE.
        
       ADD-DIGIT-POWER.
           COMPUTE POWER-SUM = 
                     POWER-SUM + DIGITS(DIGIT) ** DIGITS(DIGIT)
Task: Munchausen numbers




Go: package main

import(
    "fmt"
    "math"
)

var powers [10]int

func isMunchausen(n int) bool {
    if n < 0 { return false }
    n64 := int64(n)
    nn  := n64
    var sum int64 = 0
    for nn > 0 {
        sum += int64(powers[nn % 10])
        if sum > n64 { return false }
        nn /= 10
    }
    return sum == n64
}

func main() {
    
    for i := 1; i <= 9; i++ {
        d := float64(i)  
        powers[i] = int(math.Pow(d, d))
    }
 
    
    fmt.Println("The Munchausen numbers between 0 and 500 million are:")
    for i := 0; i <= 500000000; i++ {
        if isMunchausen(i) { fmt.Printf("%d ", i) }
    }
    fmt.Println()
}






COBOL:        IDENTIFICATION DIVISION.
       PROGRAM-ID.  MUNCHAUSEN.
 
       DATA DIVISION.
       WORKING-STORAGE SECTION.
       01 VARIABLES.
          03 CANDIDATE   PIC 9(4).
          03 DIGITS      PIC 9 OCCURS 4 TIMES, REDEFINES CANDIDATE.
          03 DIGIT       PIC 9.
          03 POWER-SUM   PIC 9(5).

       01 OUTPUT-LINE.
          03 OUT-NUM     PIC ZZZ9.

       PROCEDURE DIVISION.
       BEGIN.
           PERFORM MUNCHAUSEN-TEST VARYING CANDIDATE FROM 1 BY 1
               UNTIL CANDIDATE IS GREATER THAN 6000.
           STOP RUN.

       MUNCHAUSEN-TEST.
           MOVE ZERO TO POWER-SUM.
           MOVE 1 TO DIGIT.
           INSPECT CANDIDATE TALLYING DIGIT FOR LEADING '0'.
           PERFORM ADD-DIGIT-POWER VARYING DIGIT FROM DIGIT BY 1
               UNTIL DIGIT IS GREATER THAN 4.
           IF POWER-SUM IS EQUAL TO CANDIDATE,
               MOVE CANDIDATE TO OUT-NUM,
               DISPLAY OUTPUT-LINE.
        
       ADD-DIGIT-POWER.
           COMPUTE POWER-SUM = 
                     POWER-SUM + DIGITS(DIGIT) ** DIGITS(DIGIT)
Task: Munchausen numbers






PHP: <?php 

$pwr = array_fill(0, 10, 0);

function isMunchhausen($n)
{
    global $pwr;
    $sm = 0;
    $temp = $n;
    while ($temp) {
        $sm= $sm + $pwr[($temp % 10)];
        $temp = (int)($temp / 10);
    }
    return $sm == $n;
}

for ($i = 0; $i < 10; $i++) {
    $pwr[$i] = pow((float)($i), (float)($i));
}

for ($i = 1; $i < 5000 + 1; $i++) {
    if (isMunchhausen($i)) {
        echo $i . PHP_EOL;
    }
}
Task: Munchausen numbers






PHP: <?php 

$pwr = array_fill(0, 10, 0);

function isMunchhausen($n)
{
    global $pwr;
    $sm = 0;
    $temp = $n;
    while ($temp) {
        $sm= $sm + $pwr[($temp % 10)];
        $temp = (int)($temp / 10);
    }
    return $sm == $n;
}

for ($i = 0; $i < 10; $i++) {
    $pwr[$i] = pow((float)($i), (float)($i));
}

for ($i = 1; $i < 5000 + 1; $i++) {
    if (isMunchhausen($i)) {
        echo $i . PHP_EOL;
    }
}






Ada: with Ada.Text_IO;

procedure Munchausen is

   function Is_Munchausen (M : in Natural) return Boolean is
      Table : constant array (Character range '0' .. '9') of Natural :=
        (0**0, 1**1, 2**2, 3**3, 4**4,
         5**5, 6**6, 7**7, 8**8, 9**9);
      Image : constant String := M'Image;
      Sum   : Natural := 0;
   begin
      for I in Image'First + 1 .. Image'Last loop
         Sum := Sum + Table (Image (I));
      end loop;
      return Image = Sum'Image;
   end Is_Munchausen;

begin
   for M in 1 .. 5_000 loop
      if Is_Munchausen (M) then
         Ada.Text_IO.Put (M'Image);
      end if;
   end loop;
   Ada.Text_IO.New_Line;
end Munchausen;
Task: Munchausen numbers






PHP: <?php 

$pwr = array_fill(0, 10, 0);

function isMunchhausen($n)
{
    global $pwr;
    $sm = 0;
    $temp = $n;
    while ($temp) {
        $sm= $sm + $pwr[($temp % 10)];
        $temp = (int)($temp / 10);
    }
    return $sm == $n;
}

for ($i = 0; $i < 10; $i++) {
    $pwr[$i] = pow((float)($i), (float)($i));
}

for ($i = 1; $i < 5000 + 1; $i++) {
    if (isMunchhausen($i)) {
        echo $i . PHP_EOL;
    }
}




COBOL:        IDENTIFICATION DIVISION.
       PROGRAM-ID.  MUNCHAUSEN.
 
       DATA DIVISION.
       WORKING-STORAGE SECTION.
       01 VARIABLES.
          03 CANDIDATE   PIC 9(4).
          03 DIGITS      PIC 9 OCCURS 4 TIMES, REDEFINES CANDIDATE.
          03 DIGIT       PIC 9.
          03 POWER-SUM   PIC 9(5).

       01 OUTPUT-LINE.
          03 OUT-NUM     PIC ZZZ9.

       PROCEDURE DIVISION.
       BEGIN.
           PERFORM MUNCHAUSEN-TEST VARYING CANDIDATE FROM 1 BY 1
               UNTIL CANDIDATE IS GREATER THAN 6000.
           STOP RUN.

       MUNCHAUSEN-TEST.
           MOVE ZERO TO POWER-SUM.
           MOVE 1 TO DIGIT.
           INSPECT CANDIDATE TALLYING DIGIT FOR LEADING '0'.
           PERFORM ADD-DIGIT-POWER VARYING DIGIT FROM DIGIT BY 1
               UNTIL DIGIT IS GREATER THAN 4.
           IF POWER-SUM IS EQUAL TO CANDIDATE,
               MOVE CANDIDATE TO OUT-NUM,
               DISPLAY OUTPUT-LINE.
        
       ADD-DIGIT-POWER.
           COMPUTE POWER-SUM = 
                     POWER-SUM + DIGITS(DIGIT) ** DIGITS(DIGIT)
Task: Strip block comments

C: #include <stdio.h>
#include <string.h>
#include <stdlib.h>

const char *ca = "";
int al = 2, bl = 2;

char *loadfile(const char *fn) {
    FILE *f = fopen(fn, "rb");
    int l;
    char *s;

    if (f != NULL) {
	fseek(f, 0, SEEK_END);
	l = ftell(f);
	s = malloc(l+1);
	rewind(f);
	if (s)
	    fread(s, 1, l, f);
	fclose(f);
    }
    return s;
}

void stripcomments(char *s) {
    char *a, *b;
    int len = strlen(s) + 1;

    while ((a = strstr(s, ca)) != NULL) {
	b = strstr(a+al, cb);
	if (b == NULL)
	    break;
	b += bl;
	memmove(a, b, len-(b-a));
    }
}

int main(int argc, char **argv) {
    const char *fn = "input.txt";
    char *s;

    if (argc >= 2)
	fn = argv[1];
    s = loadfile(fn);
    if (argc == 4) {
	al = strlen(ca = argv[2]);
	bl = strlen(cb = argv[3]);
    }
    stripcomments(s);
    puts(s);
    free(s);
    return 0;
}
Task: Strip block comments



C#: using System;

    class Program
    {
        private static string BlockCommentStrip(string commentStart, string commentEnd, string sampleText)
        {
            while (sampleText.IndexOf(commentStart) > -1 && sampleText.IndexOf(commentEnd, sampleText.IndexOf(commentStart) + commentStart.Length) > -1)
            {
                int start = sampleText.IndexOf(commentStart);
                int end = sampleText.IndexOf(commentEnd, start + commentStart.Length);
                sampleText = sampleText.Remove(
                    start,
                    (end + commentEnd.Length) - start
                    );
            }
            return sampleText;
        }
    }
Task: Strip block comments


C++: #include <string>
#include <iostream> 
#include <iterator>
#include <fstream>
#include <boost/regex.hpp>

int main( ) {
    std::ifstream codeFile( "samplecode.txt" ) ;
    if ( codeFile ) {
       boost::regex commentre( "/\\*.*?\\*/" ) ;
       std::string my_erase( "" ) ;             
       std::string stripped ;
       std::string code( (std::istreambuf_iterator<char>( codeFile ) ) ,
	     std::istreambuf_iterator<char>( ) ) ;
       codeFile.close( ) ;
       stripped = boost::regex_replace( code , commentre , my_erase ) ;
       std::cout << "Code unstripped:\n" << stripped << std::endl ;
       return 0 ;
    }
    else {
       std::cout << "Could not find code file!" << std::endl ;
       return 1 ;
    }
}
Task: Strip block comments





Java: import java.io.*;

public class StripBlockComments{
    public static String readFile(String filename) {
	BufferedReader reader = new BufferedReader(new FileReader(filename));
	try {
	    StringBuilder fileContents = new StringBuilder();
	    char[] buffer = new char[4096];
	    while (reader.read(buffer, 0, 4096) > 0) {
		fileContents.append(buffer);
	    }
	    return fileContents.toString();
	} finally {
	    reader.close();
	}
    }

    public static String stripComments(String beginToken, String endToken,
				       String input) {
	StringBuilder output = new StringBuilder();
	while (true) {
	    int begin = input.indexOf(beginToken);
	    int end = input.indexOf(endToken, begin+beginToken.length());
	    if (begin == -1 || end == -1) {
		output.append(input);
		return output.toString();
	    }
	    output.append(input.substring(0, begin));
	    input = input.substring(end + endToken.length());
	}
    }

    public static void main(String[] args) {
	if (args.length < 3) {
	    System.out.println("Usage: BeginToken EndToken FileToProcess");
	    System.exit(1);
	}

	String begin = args[0];
	String end = args[1];
	String input = args[2];

	try {
	    System.out.println(stripComments(begin, end, readFile(input)));
	} catch (Exception e) {
	    e.printStackTrace();
	    System.exit(1);
	}
    }
}
Task: Strip block comments







Python: def _commentstripper(txt, delim):
    'Strips first nest of block comments'
    
    deliml, delimr = delim
    out = ''
    if deliml in txt:
        indx = txt.index(deliml)
        out += txt[:indx]
        txt = txt[indx+len(deliml):]
        txt = _commentstripper(txt, delim)
        assert delimr in txt, 'Cannot find closing comment delimiter in ' + txt
        indx = txt.index(delimr)
        out += txt[(indx+len(delimr)):]
    else:
        out = txt
    return out

def commentstripper(txt, delim=('/*', '*/')):
    'Strips nests of block comments'
    
    deliml, delimr = delim
    while deliml in txt:
        txt = _commentstripper(txt, delim)
    return txt
Task: Strip block comments




Go: package main

import (
    "fmt"
    "strings"
)



func newStripper(start, end string) func(string) string {
    
    if start == "" || end == "" {
        start, end = ""
    }
    
    return func(source string) string {
        for {
            cs := strings.Index(source, start)
            if cs < 0 {
                break
            }
            ce := strings.Index(source[cs+2:], end)
            if ce < 0 {
                break
            }
            source = source[:cs] + source[cs+ce+4:]
        }
        return source
    }
}

func main() {
    
    stripC := newStripper("", "")

    
    
    fmt.Println(stripC(`  
   function subroutine() {
    a =  b + c ;
   }
   

   
    function something() {
    }`))
}
Task: Strip block comments



C#: using System;

    class Program
    {
        private static string BlockCommentStrip(string commentStart, string commentEnd, string sampleText)
        {
            while (sampleText.IndexOf(commentStart) > -1 && sampleText.IndexOf(commentEnd, sampleText.IndexOf(commentStart) + commentStart.Length) > -1)
            {
                int start = sampleText.IndexOf(commentStart);
                int end = sampleText.IndexOf(commentEnd, start + commentStart.Length);
                sampleText = sampleText.Remove(
                    start,
                    (end + commentEnd.Length) - start
                    );
            }
            return sampleText;
        }
    }








Fortran:       SUBROUTINE UNBLOCK(THIS,THAT)	
Copies from file INF to file OUT, record by record, except skipping null output records.
       CHARACTER*(*) THIS,THAT	
       INTEGER LOTS			
       PARAMETER (LOTS = 6666)		
       CHARACTER*(LOTS) ACARD,ALINE	
       INTEGER LC,LL,L		
       INTEGER L1,L2		
       INTEGER NC,NL		
       LOGICAL BLAH		
       INTEGER MSG,KBD,INF,OUT		
       COMMON /IODEV/MSG,KBD,INF,OUT	
        NC = 0		
        NL = 0		
        BLAH = .FALSE.	
Chug through the input.
   10   READ(INF,11,END = 100) LC,ACARD(1:MIN(LC,LOTS))	
   11   FORMAT (Q,A)		
        NC = NC + 1		
        IF (LC.GT.LOTS) THEN	
          WRITE (MSG,12) NC,LC,LOTS	
   12     FORMAT ("Record ",I0," has length ",I0,"
          LC = LOTS			
        END IF			
Chew through ACARD according to mood.
        LL = 0		
        L2 = 0		
   20   L1 = L2 + 1	
        IF (L1.LE.LC) THEN	
          L2 = L1		
          IF (BLAH) THEN	
   21       IF (L2 + LEN(THAT) - 1 .LE. LC) THEN	
              IF (ACARD(L2:L2 + LEN(THAT) - 1).EQ.THAT) THEN	
                BLAH = .FALSE.		
                L2 = L2 + LEN(THAT) - 1	
                GO TO 20		
              END IF		
              L2 = L2 + 1	
              GO TO 21		
            END IF	
           ELSE		
   22       IF (L2 + LEN(THIS) - 1 .LE. LC) THEN	
              IF (ACARD(L2:L2 + LEN(THIS) - 1).EQ.THIS) THEN	
                BLAH = .TRUE.		
                L = L2 - L1		
                ALINE(LL + 1:LL + L) = ACARD(L1:L2 - 1)	
                LL = LL + L		
                L2 = L2 + LEN(THIS) - 1	
                GO TO 20		
              END IF		
              L2 = L2 + 1	
              GO TO 22		
            END IF	
            L = LC - L1 + 1	
            ALINE(LL + 1:LL + L) = ACARD(L1:LC)	
            LL = LL + L		
          END IF	
        END IF	
Cast forth some output.
        IF (LL.GT.0) THEN	
          WRITE (OUT,23) ALINE(1:LL)	
   23     FORMAT (">",A,"<") 		
          NL = NL + 1			
        END IF        		
        GO TO 10	
Completed.
  100   WRITE (MSG,101) NC,NL	
  101   FORMAT (I0," read, ",I0," written.")
      END       

      PROGRAM TEST
      INTEGER MSG,KBD,INF,OUT
      COMMON /IODEV/MSG,KBD,INF,OUT
      KBD = 5
      MSG = 6
      INF = 10
      OUT = 11
      OPEN (INF,FILE="Source.txt",STATUS="OLD",ACTION="READ")
      OPEN (OUT,FILE="Src.txt",STATUS="REPLACE",ACTION="WRITE")

      CALL UNBLOCK("/*","*/")

      END
Task: Strip block comments


C++: #include <string>
#include <iostream> 
#include <iterator>
#include <fstream>
#include <boost/regex.hpp>

int main( ) {
    std::ifstream codeFile( "samplecode.txt" ) ;
    if ( codeFile ) {
       boost::regex commentre( "/\\*.*?\\*/" ) ;
       std::string my_erase( "" ) ;             
       std::string stripped ;
       std::string code( (std::istreambuf_iterator<char>( codeFile ) ) ,
	     std::istreambuf_iterator<char>( ) ) ;
       codeFile.close( ) ;
       stripped = boost::regex_replace( code , commentre , my_erase ) ;
       std::cout << "Code unstripped:\n" << stripped << std::endl ;
       return 0 ;
    }
    else {
       std::cout << "Could not find code file!" << std::endl ;
       return 1 ;
    }
}









Fortran:       SUBROUTINE UNBLOCK(THIS,THAT)	
Copies from file INF to file OUT, record by record, except skipping null output records.
       CHARACTER*(*) THIS,THAT	
       INTEGER LOTS			
       PARAMETER (LOTS = 6666)		
       CHARACTER*(LOTS) ACARD,ALINE	
       INTEGER LC,LL,L		
       INTEGER L1,L2		
       INTEGER NC,NL		
       LOGICAL BLAH		
       INTEGER MSG,KBD,INF,OUT		
       COMMON /IODEV/MSG,KBD,INF,OUT	
        NC = 0		
        NL = 0		
        BLAH = .FALSE.	
Chug through the input.
   10   READ(INF,11,END = 100) LC,ACARD(1:MIN(LC,LOTS))	
   11   FORMAT (Q,A)		
        NC = NC + 1		
        IF (LC.GT.LOTS) THEN	
          WRITE (MSG,12) NC,LC,LOTS	
   12     FORMAT ("Record ",I0," has length ",I0,"
          LC = LOTS			
        END IF			
Chew through ACARD according to mood.
        LL = 0		
        L2 = 0		
   20   L1 = L2 + 1	
        IF (L1.LE.LC) THEN	
          L2 = L1		
          IF (BLAH) THEN	
   21       IF (L2 + LEN(THAT) - 1 .LE. LC) THEN	
              IF (ACARD(L2:L2 + LEN(THAT) - 1).EQ.THAT) THEN	
                BLAH = .FALSE.		
                L2 = L2 + LEN(THAT) - 1	
                GO TO 20		
              END IF		
              L2 = L2 + 1	
              GO TO 21		
            END IF	
           ELSE		
   22       IF (L2 + LEN(THIS) - 1 .LE. LC) THEN	
              IF (ACARD(L2:L2 + LEN(THIS) - 1).EQ.THIS) THEN	
                BLAH = .TRUE.		
                L = L2 - L1		
                ALINE(LL + 1:LL + L) = ACARD(L1:L2 - 1)	
                LL = LL + L		
                L2 = L2 + LEN(THIS) - 1	
                GO TO 20		
              END IF		
              L2 = L2 + 1	
              GO TO 22		
            END IF	
            L = LC - L1 + 1	
            ALINE(LL + 1:LL + L) = ACARD(L1:LC)	
            LL = LL + L		
          END IF	
        END IF	
Cast forth some output.
        IF (LL.GT.0) THEN	
          WRITE (OUT,23) ALINE(1:LL)	
   23     FORMAT (">",A,"<") 		
          NL = NL + 1			
        END IF        		
        GO TO 10	
Completed.
  100   WRITE (MSG,101) NC,NL	
  101   FORMAT (I0," read, ",I0," written.")
      END       

      PROGRAM TEST
      INTEGER MSG,KBD,INF,OUT
      COMMON /IODEV/MSG,KBD,INF,OUT
      KBD = 5
      MSG = 6
      INF = 10
      OUT = 11
      OPEN (INF,FILE="Source.txt",STATUS="OLD",ACTION="READ")
      OPEN (OUT,FILE="Src.txt",STATUS="REPLACE",ACTION="WRITE")

      CALL UNBLOCK("/*","*/")

      END
Task: Strip block comments







Python: def _commentstripper(txt, delim):
    'Strips first nest of block comments'
    
    deliml, delimr = delim
    out = ''
    if deliml in txt:
        indx = txt.index(deliml)
        out += txt[:indx]
        txt = txt[indx+len(deliml):]
        txt = _commentstripper(txt, delim)
        assert delimr in txt, 'Cannot find closing comment delimiter in ' + txt
        indx = txt.index(delimr)
        out += txt[(indx+len(delimr)):]
    else:
        out = txt
    return out

def commentstripper(txt, delim=('/*', '*/')):
    'Strips nests of block comments'
    
    deliml, delimr = delim
    while deliml in txt:
        txt = _commentstripper(txt, delim)
    return txt




Fortran:       SUBROUTINE UNBLOCK(THIS,THAT)	
Copies from file INF to file OUT, record by record, except skipping null output records.
       CHARACTER*(*) THIS,THAT	
       INTEGER LOTS			
       PARAMETER (LOTS = 6666)		
       CHARACTER*(LOTS) ACARD,ALINE	
       INTEGER LC,LL,L		
       INTEGER L1,L2		
       INTEGER NC,NL		
       LOGICAL BLAH		
       INTEGER MSG,KBD,INF,OUT		
       COMMON /IODEV/MSG,KBD,INF,OUT	
        NC = 0		
        NL = 0		
        BLAH = .FALSE.	
Chug through the input.
   10   READ(INF,11,END = 100) LC,ACARD(1:MIN(LC,LOTS))	
   11   FORMAT (Q,A)		
        NC = NC + 1		
        IF (LC.GT.LOTS) THEN	
          WRITE (MSG,12) NC,LC,LOTS	
   12     FORMAT ("Record ",I0," has length ",I0,"
          LC = LOTS			
        END IF			
Chew through ACARD according to mood.
        LL = 0		
        L2 = 0		
   20   L1 = L2 + 1	
        IF (L1.LE.LC) THEN	
          L2 = L1		
          IF (BLAH) THEN	
   21       IF (L2 + LEN(THAT) - 1 .LE. LC) THEN	
              IF (ACARD(L2:L2 + LEN(THAT) - 1).EQ.THAT) THEN	
                BLAH = .FALSE.		
                L2 = L2 + LEN(THAT) - 1	
                GO TO 20		
              END IF		
              L2 = L2 + 1	
              GO TO 21		
            END IF	
           ELSE		
   22       IF (L2 + LEN(THIS) - 1 .LE. LC) THEN	
              IF (ACARD(L2:L2 + LEN(THIS) - 1).EQ.THIS) THEN	
                BLAH = .TRUE.		
                L = L2 - L1		
                ALINE(LL + 1:LL + L) = ACARD(L1:L2 - 1)	
                LL = LL + L		
                L2 = L2 + LEN(THIS) - 1	
                GO TO 20		
              END IF		
              L2 = L2 + 1	
              GO TO 22		
            END IF	
            L = LC - L1 + 1	
            ALINE(LL + 1:LL + L) = ACARD(L1:LC)	
            LL = LL + L		
          END IF	
        END IF	
Cast forth some output.
        IF (LL.GT.0) THEN	
          WRITE (OUT,23) ALINE(1:LL)	
   23     FORMAT (">",A,"<") 		
          NL = NL + 1			
        END IF        		
        GO TO 10	
Completed.
  100   WRITE (MSG,101) NC,NL	
  101   FORMAT (I0," read, ",I0," written.")
      END       

      PROGRAM TEST
      INTEGER MSG,KBD,INF,OUT
      COMMON /IODEV/MSG,KBD,INF,OUT
      KBD = 5
      MSG = 6
      INF = 10
      OUT = 11
      OPEN (INF,FILE="Source.txt",STATUS="OLD",ACTION="READ")
      OPEN (OUT,FILE="Src.txt",STATUS="REPLACE",ACTION="WRITE")

      CALL UNBLOCK("/*","*/")

      END
Task: Strip block comments






PHP: function strip_block_comments( $test_string ) {
	$pattern = "/^.*?(\K\/\*.*?\*\/)|^.*?(\K\/\*.*?^.*\*\/)$/mXus";
	return preg_replace( $pattern, '', $test_string );
}

echo "Result: '" . strip_block_comments( "

 function subroutine() {
  a =  b + c ;
 }
 

 
  function something() {
  }
" ) . "'";





Fortran:       SUBROUTINE UNBLOCK(THIS,THAT)	
Copies from file INF to file OUT, record by record, except skipping null output records.
       CHARACTER*(*) THIS,THAT	
       INTEGER LOTS			
       PARAMETER (LOTS = 6666)		
       CHARACTER*(LOTS) ACARD,ALINE	
       INTEGER LC,LL,L		
       INTEGER L1,L2		
       INTEGER NC,NL		
       LOGICAL BLAH		
       INTEGER MSG,KBD,INF,OUT		
       COMMON /IODEV/MSG,KBD,INF,OUT	
        NC = 0		
        NL = 0		
        BLAH = .FALSE.	
Chug through the input.
   10   READ(INF,11,END = 100) LC,ACARD(1:MIN(LC,LOTS))	
   11   FORMAT (Q,A)		
        NC = NC + 1		
        IF (LC.GT.LOTS) THEN	
          WRITE (MSG,12) NC,LC,LOTS	
   12     FORMAT ("Record ",I0," has length ",I0,"
          LC = LOTS			
        END IF			
Chew through ACARD according to mood.
        LL = 0		
        L2 = 0		
   20   L1 = L2 + 1	
        IF (L1.LE.LC) THEN	
          L2 = L1		
          IF (BLAH) THEN	
   21       IF (L2 + LEN(THAT) - 1 .LE. LC) THEN	
              IF (ACARD(L2:L2 + LEN(THAT) - 1).EQ.THAT) THEN	
                BLAH = .FALSE.		
                L2 = L2 + LEN(THAT) - 1	
                GO TO 20		
              END IF		
              L2 = L2 + 1	
              GO TO 21		
            END IF	
           ELSE		
   22       IF (L2 + LEN(THIS) - 1 .LE. LC) THEN	
              IF (ACARD(L2:L2 + LEN(THIS) - 1).EQ.THIS) THEN	
                BLAH = .TRUE.		
                L = L2 - L1		
                ALINE(LL + 1:LL + L) = ACARD(L1:L2 - 1)	
                LL = LL + L		
                L2 = L2 + LEN(THIS) - 1	
                GO TO 20		
              END IF		
              L2 = L2 + 1	
              GO TO 22		
            END IF	
            L = LC - L1 + 1	
            ALINE(LL + 1:LL + L) = ACARD(L1:LC)	
            LL = LL + L		
          END IF	
        END IF	
Cast forth some output.
        IF (LL.GT.0) THEN	
          WRITE (OUT,23) ALINE(1:LL)	
   23     FORMAT (">",A,"<") 		
          NL = NL + 1			
        END IF        		
        GO TO 10	
Completed.
  100   WRITE (MSG,101) NC,NL	
  101   FORMAT (I0," read, ",I0," written.")
      END       

      PROGRAM TEST
      INTEGER MSG,KBD,INF,OUT
      COMMON /IODEV/MSG,KBD,INF,OUT
      KBD = 5
      MSG = 6
      INF = 10
      OUT = 11
      OPEN (INF,FILE="Source.txt",STATUS="OLD",ACTION="READ")
      OPEN (OUT,FILE="Src.txt",STATUS="REPLACE",ACTION="WRITE")

      CALL UNBLOCK("/*","*/")

      END
Task: Strip block comments






PHP: function strip_block_comments( $test_string ) {
	$pattern = "/^.*?(\K\/\*.*?\*\/)|^.*?(\K\/\*.*?^.*\*\/)$/mXus";
	return preg_replace( $pattern, '', $test_string );
}

echo "Result: '" . strip_block_comments( "

 function subroutine() {
  a =  b + c ;
 }
 

 
  function something() {
  }
" ) . "'";