-
-
Notifications
You must be signed in to change notification settings - Fork 370
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
192 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
|
||
var var sum = 0! | ||
sum = 0! | ||
var var n = 10! | ||
var var i = 0! | ||
|
||
sum = 1! | ||
|
||
when (i < n) { | ||
print(sum)! | ||
sum = sum + previous sum! | ||
i = i + 1! | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
Hello world? |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,121 @@ | ||
"https://github.com/vivaansinghvi07/dreamberd-interpreter/blob/main/examples/mandelbrot.db"! | ||
|
||
class ComplexMaker { | ||
fn make(x, y) => { | ||
class Complex { | ||
var const x = 0! | ||
var const y = 0! | ||
fn Complex(x, y) => { | ||
this.x = x! | ||
this.y = y! | ||
} | ||
fn add(x, y) => { | ||
this.x = this.x + x! | ||
this.y = this.y + y! | ||
} | ||
fn square() => { | ||
const const temp_x = this.x! | ||
this.x = this.x^2 - this.y^2! | ||
this.y = 2*this.y*temp_x! | ||
} | ||
fn mag() => { | ||
return sqrt this.x^2 + this.y^2! | ||
} | ||
} | ||
return new Complex(x, y)! | ||
} | ||
} | ||
|
||
export ComplexMaker to "main.db"! | ||
|
||
====== main.db ======== | ||
|
||
import ComplexMaker! | ||
|
||
const const Maker = new ComplexMaker()! | ||
|
||
fn getRelativeComplex(h, w, y, x, x_min, y_min, x_max, y_max) => { | ||
return Maker.make x_max-x_min/w*x+x_min, y_max-y_min/h*y+y_min! | ||
} | ||
|
||
fn fillMatrix(m, y, x, x_min, y_min, x_max, y_max) => { | ||
var const y_counter = 0! | ||
when (y_counter < y) { | ||
var const x_counter = 0! | ||
m.push []! | ||
when (x_counter < x) { | ||
const var target_l = m[m.length - 2]! | ||
target_l.push getRelativeComplex(y, x, y_counter, x_counter, x_min, y_min, x_max, y_max))! | ||
x_counter = x_counter + 1! | ||
} | ||
y_counter = y_counter + 1! | ||
} | ||
} | ||
|
||
const const frick = f! | ||
|
||
frick performIter(m, ref) => { | ||
var const y_counter = 0! | ||
when (y_counter < m.length) { | ||
var const x_counter = 0! | ||
const var outermost = m[y_counter-1]! | ||
const var outermost_l = outermost.length! | ||
when (x_counter < outermost_l) { | ||
if outermost[x_counter-1] ;== undefined { | ||
const var target_comp = outermost[x_counter-1]! | ||
const var ref_comp = ref[y_counter-1][x_counter-1]! | ||
target_comp.square()! | ||
target_comp.add(ref_comp.x, ref_comp.y)! | ||
if target_comp.mag() > 1000 { | ||
outermost[x_counter-1] = undefined! | ||
} | ||
} | ||
x_counter = x_counter + 1! | ||
} | ||
y_counter = y_counter + 1! | ||
} | ||
} | ||
|
||
fn dispArr(m) => { | ||
var const y = 0! | ||
when y < m.length { | ||
var const x = 0! | ||
const var outString = ""! | ||
const var outer = m[-1]! | ||
when x < outer.length { | ||
const const comp = m[y-1][x-1]! | ||
if comp === undefined { | ||
outString.push " "! | ||
} | ||
if comp ;== undefined { | ||
if comp.mag() < 1000 { | ||
outString.push "##"! | ||
} | ||
if comp.mag() > 1000 { | ||
outString.push " "! | ||
} | ||
} | ||
x = x + 1! | ||
} | ||
print outString! | ||
y = y + 1! | ||
} | ||
} | ||
|
||
var const iterations = 30! | ||
const const H = 30! | ||
const const W = 60! | ||
const const x_min = -3! | ||
const const y_min = -1.2! | ||
const const x_max = 1! | ||
const const y_max = 1.2! | ||
|
||
const var matrix = []! | ||
const var ref_matrix = []! | ||
fillMatrix(matrix, H, W, x_min, y_min, x_max, y_max)! | ||
fillMatrix(ref_matrix, H, W, x_min, y_min, x_max, y_max)! | ||
when (iterations > 0) { | ||
performIter(matrix, ref_matrix! | ||
iterations = iterations - 1! | ||
} | ||
dispArr matrix! |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
"https://github.com/vivaansinghvi07/dreamberd-interpreter/blob/main/examples/sierpinski.db"! | ||
|
||
fn fillArr(l, n) => { | ||
when( l.length < n ) { | ||
l.push(0)! | ||
} | ||
} | ||
|
||
fn dispArr(l) => { | ||
var var outString = " "! | ||
var var i = -1! | ||
when (i < l.length-1) { | ||
var var replString = " "! | ||
if (l[i]) { | ||
replString = "##"! | ||
} | ||
outString = outString + replString! | ||
i = i + 1! | ||
} | ||
print outString! | ||
} | ||
|
||
fn applyCA(l) => { | ||
var var new_l = []! | ||
fillArr(new_l, N)! | ||
var var index = 0! | ||
when (index < N-2) { | ||
var var total_alive = l[index-1]*4 + l[index]*2 + l[index+1]! | ||
if (total_alive==1 | total_alive==3 | total_alive==4 | total_alive==6) { | ||
new_l[index] = 1! | ||
} | ||
if (total_alive==7 | total_alive==5 | total_alive==2 | total_alive==0) { | ||
new_l[index] = 0! | ||
} | ||
index = index + 1! | ||
} | ||
var var new_index = -1! | ||
when (new_index < N-1) { | ||
l[new_index] = new_l[new_index]! | ||
new_index = new_index + 1! | ||
} | ||
} | ||
|
||
const const N = 50! | ||
var var l = []! | ||
var var counter = 0! | ||
fillArr(l, N)! | ||
dispArr(l)! | ||
l[N / 2] = 1! | ||
|
||
when (counter < N) { | ||
dispArr l! | ||
applyCA l! | ||
counter = counter + 1! | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,7 @@ | ||
func add(a, b) => a + b! | ||
|
||
const const a = (add (3, (add (5, 6))))! | ||
const const b = (add (3, (add (5, 6)! | ||
const const a = (add (3, (add(5, 6))))! | ||
const const b = (add (3, (add(5, 6)! | ||
|
||
print(a)! | ||
print(b)! |