Skip to content

max22-/uxnbruteforce

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

15 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Uxnbruteforce

A small C program to optimize little pieces of uxntal code. It is a work in progress, a little bit messy for the moment :)

I had the idea to do this because I remembered seeing this concerning the Joy programming language : A Brute-force Automated Construction Finder And I thought it would be cool to do the same for uxn.

How to use it ?

git clone https://github.com/max22-/uxnbruteforce
cd uxnbruteforce
make run

The current example solves %MIN2 (finds the minimum of 2 shorts). The first solution is not that correct (it generates a correct answer, but jumps in the middle of nowhere...). This one looks better : LTH2k JMP SWP2 POP2

To solve a different problem, you need to edit

  • TESTS : number of tests
  • inputs[TESTS][] : input data
  • init_tests() : fills outputs[TESTS]
  • check() --> loads inputs, runs uxn_eval, and checks working stack is equal to the expected output, etc
  • check_instructions() : if you want to discard some opcodes from the search space

A quick and dirty hack is made in uxn-fast.c, to avoid infinite loops. (the main loop in uxn_eval is limited to 100 iterations).

TODO / Ideas

  • Find a better way to load the data (inputs and expected outputs). It is quite painful now with the actual implementation !
  • Use other techniques like genetic programming ? (suggestion of Sigrid)

Bugs

  • LIT won't be well decoded in the disassembler output
  • There is a trailing "1" opcode in the generated programs, but it is not a big deal since there are some BRK before.

Contact

Mastodon: @maxime_andre@mastodon.xyz

About

Optimize small uxntal programs via brute-force

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published