Reptorian

joined 1 year ago
[–] Reptorian 2 points 2 weeks ago* (last edited 2 weeks ago)

G'MIC solution

spoiler

it day2
crop. 0,0,0,{h#-1-2}
split. -,{_'\n'}
foreach { replace_str. " ",";" ({t}) rm.. }

safe_0,safe_1=0
foreach {
	({h}) a[-2,-1] y
	num_of_attempts:=da_size(#-1)+1
	store temp

	repeat $num_of_attempts {

		$temp

		if $> eval da_remove(#-1,$>-1) fi

		eval "
			safe=1;
			i[#-1,1]>i[#-1,0]?(
				for(p=1,p<da_size(#-1),++p,
					if(!inrange(i[#-1,p]-i[#-1,p-1],1,3,1,1),safe=0;break(););
				);
			):(
				for(p=1,p<da_size(#-1),++p,
					if(!inrange(i[#-1,p-1]-i[#-1,p],1,3,1,1),safe=0;break(););
				);
			);
			safe;"

		rm

		if $>
			if ${} safe_1+=1 break fi
		else
			if ${} safe_0,safe_1+=1 break fi
		fi

	}

}

echo Day" "2:" "${safe_0}" :: "${safe_1}

[–] Reptorian 3 points 3 weeks ago

I guess I can try this again in G'MIC.

[–] Reptorian 3 points 4 weeks ago

People should use less Ai, and learn more how to program

Yes. Once you know how, you can see pitfalls with AI.

[–] Reptorian 7 points 4 weeks ago (1 children)

Interesting, but I never needed AI for coding. Well, twice, and I had to do changes, but would not use AI to generate code.

[–] Reptorian 2 points 4 weeks ago* (last edited 4 weeks ago)

My small Python (~100 lines of codes) codes aren't maintainable, but I'm happy with them. I don't ever plan to work on serious projects with Python, so I can't say much about it's maintainability. But, from limited experience, I'd rather use C++, C#, or in my special case, G'MIC if maintainability matters to me.

[–] Reptorian 2 points 4 weeks ago* (last edited 4 weeks ago)

In my experience, it is.

I had converted a Python code into G'MIC, and then some one else did a Python version of my own code. G'MIC is interpretative with JIT math parser. The results:

Reversing digits in a 1024x1024 RGB image.

Python: Without lookup table and numpy - 3+ minutes

Python: With lookup table and numpy - 6.5 s (Some one else machine, but it shouldn't take that long)

G'MIC: Without lookup table - .3 s

G'MIC: With lookup table - .005 s

And I did Lavander Binary Map on my machine, you can find code for Python version in github/gmic-community/include/reptorian.gmic:

Python: 3 s (Without lookup table)

G'MIC:.15 s (Without lookup table)

G'MIC: .05 s (With lookup table)

Honestly, I find Python pretty bad for image processing in general.

[–] Reptorian 2 points 1 month ago* (last edited 1 month ago) (1 children)

I use Levels filter tool for that in Krita. Already non-destructive.

[–] Reptorian 2 points 1 month ago* (last edited 1 month ago)

Scala does look nice. Just a quick syntax view makes me want to give it a whirl when I want an alternative to Python. I used to code in C++, and C#. I use G'MIC (DSL) as my main. Scala seems right up my alley.

[–] Reptorian 1 points 2 months ago (1 children)

Yes. <center></center> isn't part of HTML5. It is part of HTML4 though.

[–] Reptorian 2 points 2 months ago (1 children)

Yes, something like that. I provided a spoiler example recently. And I would definitely like to be able to adjust what's going to be rendered by editing on the rendered viewport.

 

cross-posted from: https://programming.dev/post/20450422

Right now, I would like a easy editor that allows me to not worry about HTML4 syntax, and simply adjust the rendered text, while I can see the HTML source code.

The reason I need something like this is that I sometimes do make note() in G'MIC which looks like this:

#@gui:_=separator(),_=note("<center><b>- Additional Information -</b></center>")

See that inside note("")? That's HTML4. And while I can do without a editor, I feel that it would be better to use an actual editor where I can copy and paste.

6
submitted 2 months ago* (last edited 2 months ago) by Reptorian to c/html
 

Right now, I would like a easy editor that allows me to not worry about HTML4 syntax, and simply adjust the rendered text, while I can see the HTML source code.

The reason I need something like this is that I sometimes do make note() in G'MIC which looks like this:

#@gui:_=separator(),_=note("<center><b>- Additional Information -</b></center>")

See that inside note("")? That's HTML4. And while I can do without a editor, I feel that it would be better to use an actual editor where I can copy and paste.

My code can look something like this (Without wrap lines):

spoiler

<b>Palette CLI Information</b>\n\n <i>Main Source of Palettes - </i><a href=\"https://lospec.com/palette-list\"> LoSpec Palette List</a>\n\nPalette Number -- pal number_id = pal name_id -- Full Palette Name by Author[if mentioned]\n\n1 -- +pal 0 = +pal bw -- Black & White\n2 -- +pal 1 = +pal rgb -- Red-Green-Blue\n3 -- +pal 2 = +pal b_rgb -- Black with Red-Green-Blue\n4 -- +pal 3 = +pal bw_rgb -- Black & White with Red-Green-Blue\n5 -- +pal 4 = +pal cmy -- Cyan-Magenta-Yellow\n6 -- +pal 5 = +pal cmyk -- Cyan-Magenta-Yellow-Black\n7 -- +pal 6 = +pal w_cmyk -- White-Cyan-Magenta-Yellow-Black\n8 -- +pal 7 = +pal rgbcmy -- Red-Green-Blue with Cyan-Magenta-Yellow\n9 -- +pal 8 = +pal 1bitrgb -- 1-Bit RGB\n10 -- +pal 9 = +pal aurora -- Aurora by GrafxKid\n11 -- +pal 10 = +pal zenit -- Zenit-241 by Zenit40\n12 -- +pal 11 = +pal gbg -- Game Builder Garage: Texture-Sprite Editor Palette\n13 -- +pal 12 = +pal duel -- Duel by Arilyn\n14 -- +pal 13 = +pal hocuspocus -- Hocus Pocus Palette by Apogee Software,Ltd.\n15 -- +pal 14 = +pal playpal -- PLAYPAL by id Tech 1 | DOOM Engine\n16 -- +pal 15 = +pal srb2 -- Sonic Robo Blast 2\n17 -- +pal 16 = +pal uzebox -- Uzebox from Uzebox console\n18 -- +pal 17 = +pal kens16 -- Andrew Kensler - 16 by Andrew Kensler\n19 -- +pal 18 = +pal kens32 -- Andrew Kensler - 32 by Andrew Kensler\n20 -- +pal 19 = +pal kens54 -- Andrew Kensler - 54 by Andrew Kensler\n21 -- +pal 20 = +pal aap12 -- AAP-Micro 12 by Adigun A. Polack\n22 -- +pal 21 = +pal aap16 -- AAP-16 by Adigun A. Polack\n23 -- +pal 22 = +pal aap64 -- AAP-64 by Adigun A. Polack

[–] Reptorian 2 points 2 months ago

When I do commit, I write up the title of what I did, and describe it, and then use periods for related commits. Just easier.

5
submitted 9 months ago* (last edited 9 months ago) by Reptorian to c/shell
 

At the moment, I am stuck with using single-precision float, and double-precision float. So, the maximum represent-able value for single is 1<<24 while for double, it is 1<<53.

Because of this, I made the following script here - https://gist.github.com/Reptorian1125/71e3eec41e44e2e3d896a10f2a51448e .

Allow me to clarify on the script above. On the first part, rep_bin2dec does is to return the converted values into the status. So, when I do ${} or variable=${rep_bin2dec\ ???}, I get the status string.

On the second part, rep_bin2dec_base is the basis for getting rep_bin2dec to work. _rep_bin2dec_base prints the base_10M array into a string.

So, how does rep_bin2dec_base converts a big binary into big decimal?

  1. If the binary image is less than dimension of 54, then the script will use 0b{} which allows me to directly convert binary to decimal, and 0b is a binary literal much in the same way that Python and C++ does it. From this point, it's pretty obvious on what to do there. So, if it less than dimension 54, this step 1 is pretty much done. If not, move on to step 2.

  2. Convert the binary image as a image of base (1<<24) representing the value of that image. Note that there are two channels "[ output_value , y ]". y in this case represents the digit position in base (1<<24).

  3. Make the converted image as a dynamic array image. This allows us to remove unused digits. You can look at step 2, and step 3 as converting a binary string into an array of base (1<<24) into a dynamic array. Also, note that start_value is stored. That's the very first digit.

  4. Note that the number_of_decimals is the predicted number of characters after conversion of binary to decimal. And the, there's multi-threading that gets activated depending on the size of dynamic array image. decimal_conversion_array_size,result_conversion_array_size is used to define array size as they're temporary arrays to convert from base (1<<24) into base 10M. Finally, there's a new image which is going to be using base 10 million for easy printing, and set is used to add the first digit of base (1<<24) which will then be converted to base 10M.

  5. On eval[-2], we are now processing the base (1<<24) image, and then convert it into base 10M. There's a implicit loop, so you can add a "for y" after begin(), and begin() can be seen as the setup code.

Some notes, copy() basically allows me to alter an array. In this case, opacity is negative, so it will add the multiplication of the positive opacity. If opacity was between 0-1, then it will get treated similar to how opacity of one layer alters a image. And the multiplication algorithm being used to convert between bases is SchΓΆnhage-Strassen multiplication, but without the FFT part.

So, here how that works.

   9   9
x  1   9
_________
  81  81
9  9
_________
1  8  8 1

Basically, it's long multiplication, and you can see that there's carrying of the remainder. 81 -> 1 (Remainder 8). 81 + 9 + R8 = 89 + 9 = 8 R ( 1+ 8 ) = 8 R 9. Then 9 + 9 is 18. So, you can see how this results in 1881.

  1. After the conversion to base 10M, depending on your inputs, it'll set the status value to the decimal representation or preserves it as a base 10M for easy printing with _rep_bin2dec_base after alteration.

There's some more details, but I find it really hard to explain this.

So, my question is what are some good algorithm to print out huge binaries as decimal? I know Python is insanely good at that, but I can't seem to understand how it does that so well. I know that they do involve conversion to base 2^30 or 1<<30.

At the moment, I can convert a 90000 digits binary in .35 s, and that's bad to what I seen in Python. It's really bad with 1M binary digits.

 

Three things before I'll get to the relevant details.

  1. Brainfuck is a esoteric languages which uses 8 characters. I'll leave details here - https://en.wikipedia.org/wiki/Brainfuck
  2. G'MIC is a language largely inspired by bash languages and one other shell scripting language, and partly inspired by C++ for JIT compilation. It's two languages in one as in one outside of JIT and one inside of JIT. It's main purpose is image processing, and it can do 3D things too, basically image-related things. It's turing-complete, so making files has been done with it. Even making a executable compiled program is possible in practice (but, I would point to doing C++ and compile there instead).
  3. I am a G'MIC filters developer.

Anyways, I taken some time to code up a Brainfuck interpreter within G'MIC. It wasn't that hard to do once I understood what Brainfuck is as a language. I did one earlier than this, but I had to have users define inputs beforehand. Recently, I created rep_cin command to relieve users of doing that, and that is the closest to input() within Python or std::cin via C++.

Anyways, here's the code to my Brainfuck interpreter:

#@cli run_brainfuck_it: brainfuck_file,'_enforce_numbers_input={ 0=false | 1=true },_size_of_array>0
#@cli : Interprets Brainfuck code file within G'MIC brainfuck_interpreter.
#@cli : Default values: ,'_enforce_numbers_input=0','_size_of_array=512'
run_brainfuck_it:
    skip ${2=0},${3=512}
    it $1
    _brainfuck_interpreter $2,$3
    um run_brainfuck_it,run_brainfuck,_brainfuck_interpreter,_brainfuck_interpreter_byte_input
#@cli run_brainfuck: brainfuck_code,'_enforce_numbers_input={ 0=false | 1=true },_size_of_array>0
#@cli : Interprets Brainfuck code within G'MIC brainfuck_interpreter.
#@cli : Default values: ,'_enforce_numbers_input=0','_size_of_array=512'
run_brainfuck:
    skip ${2=0},${3=512}
    ('$1')
    _brainfuck_interpreter $2,$3
    um run_brainfuck_it,run_brainfuck,_brainfuck_interpreter,_brainfuck_interpreter_byte_input
_brainfuck_interpreter:
    # 1. Convert image into dynamic image
    resize 1,{whd#-1},1,1,-1 ({h}) append y # Convert string images into dynamic image
    name[-1] brainfuck_code                 # Name image into brainfuck_code

    # 2. Remove unused characters
    eval "
        const brainfuck_code=$brainfuck_code;
        for(p=h#brainfuck_code-2,p>-1,--p,
            char=i[#brainfuck_code,p];
            if(!(inrange(char,_'+',_'.',1,1)||(find('<>[]',char,0,1)!=-1)),
                da_remove(#brainfuck_code,p);
            );
        );
        if(!da_size(#brainfuck_code),
            run('error inval_code');
        );
        da_freeze(#brainfuck_code);
        "

    # 3. Evaluate brackets
    eval[brainfuck_code] >"
        begin(level=0;);
        i==_'['?++level:
        i==_']'?--level;
        if(level<0,run('error inv_bracks'););
        end(if(level,run('error inv_bracks');););"

    1x2  # Create 2 images of 1x1x1x1. One image is for storing print out characters, and the other is to allow inputs.
    _arg_level=1

    # 4. Create JIT code for executing brainfuck code.
    repeat h#$brainfuck_code {
        idx:=i[#0,$>]

        if $idx==_',' code_str.=run('$0_byte_input[-2]\ $1');ind_list[ind]=i#-2;                continue fi
        if $idx==_'.' code_str.=da_push(#-1,ind_list[ind]);                                     continue fi
        if $idx==_'+' code_str.=ind_list[ind]++;ind_list[ind]%=256;                             continue fi
        if $idx==_'-' code_str.=ind_list[ind]--;ind_list[ind]%=256;                             continue fi
        if $idx==_'<' code_str.=if(!inrange(--ind,0,$2,1,0),run("'error out_of_bound'"););      continue fi
        if $idx==_'>' code_str.=if(!inrange(++ind,0,$2,1,0),run("'error out_of_bound'"););      continue fi
        if $idx==_'[' code_str.=repeat(inf,if(!ind_list[ind],break(););                         continue fi
        if $idx==_']' code_str.=);                                                                       fi
    }

    # 5. Execute created JIT code. v + and v - is used to change verbosity level, not part of JIT execution. e[] is used to print into console.
    v +
    eval >begin(ind=0;ind_list=vector$2(););$code_str;end(da_freeze(#-1););
    v -

    # 6. Print out executed code result
    v + e[$^] "Brainfuck Output: "{t} v -
    remove
_brainfuck_interpreter_byte_input:
    repeat inf {
        wait         # For some reason, I had to add this to make this code work!

        if $> rep_cin "Brainfuck Interpreter - Wrong Input! Insert Integer for Argument#"$_arg_level": "
        else  rep_cin "Brainfuck Interpreter - Enter Argument#"$_arg_level" (Integers Only): "
        fi

        if $1 input:=(${}%208)+_'0'
        else  input=${}
        fi

        if isint($input) break fi
    }

    if $1 
        v + e[$^] "Brainfuck Interpreter Inserted Argument#"$_arg_level": "{$input-_'0'} v -
    else
        input%=256
        v + e[$^] "Brainfuck Interpreter Inserted Argument#"$_arg_level": "$input" :: "{`$input`} v -
    fi

    _arg_level+=1
    f[-1] $input

And the CLI test:

C:\Users\User\Documents\G'MIC\Brainfuck Interpreter>gmic "brainfuck_interpreter.gmic" run_brainfuck \">,>,<<++++++[>-------->--------<<-]>[>[>+>+<<-]>[<+>-]<<-]>[-]>+>>++++++++++<[->-[>>>]++++++++++<<+[<<<]>>>>]<-<++++++++++>>>[-<<<->>>]<<<<++++++[>++++++++>[++++++++>]<[<]>-]>>[.<<]<[<<]>>.\",1
[gmic]./ Start G'MIC interpreter (v.3.3.3).
[gmic]./ Input custom command file 'brainfuck_interpreter.gmic' (4 new, total: 4806).
[gmic]./ Brainfuck Interpreter Inserted Argument#1: 31
[gmic]./ Brainfuck Interpreter Inserted Argument#2: 3
[gmic]./ Brainfuck Output: 93
[gmic]./ End G'MIC interpreter.
 

Basically just the title said. The situation is basically I use a Domain-Specific Language called G'MIC, and to this day, I haven't found a satisfactory answer to the issue of lack of syntax highlighting. At the moment, I am using KDE Kate as it's pretty good at structuring the code with their find/replace feature, tab indicators, and multi-window support.

view more: next β€Ί