├── .target ├── 1 ├── 2 ├── 3 ├── 4 ├── 5 ├── 6 ├── 7 ├── 8 ├── 9 ├── 10 ├── 11 ├── 12 ├── 13 ├── 14 ├── 15 ├── 16 ├── 17 ├── 18 ├── 19 ├── 20 ├── 21 ├── 22 └── 23 ├── files ├── names.csv └── books ├── .dev ├── intendedsolutions │ ├── template │ ├── example8.d │ ├── example22.d │ ├── example20.d │ ├── example1.d │ ├── example15.d │ ├── example10.d │ ├── example19.d │ ├── example2.d │ ├── example21.d │ ├── example18.d │ ├── example14.d │ ├── example9.d │ ├── example32.d │ ├── example13.d │ ├── example29.d │ ├── example12.d │ ├── example11.d │ ├── example28.d │ ├── example25.d │ ├── example17.d │ ├── example27.d │ ├── example7.d │ ├── example33.d │ ├── example5.d │ ├── example23.d │ ├── example6.d │ ├── example34.d │ ├── example3.d │ ├── example16.d │ ├── example26.d │ ├── example31.d │ ├── example4.d │ ├── example36.d │ ├── example30.d │ ├── example24.d │ └── example35.d ├── design_rants │ ├── linuxspremeecy.md │ ├── styleguide.md │ ├── overallstructure.md │ └── what to teach.md ├── unorginizedcode │ ├── 2023-01-24-174703_662x97_scrot.png │ ├── 2023-01-24-174707_651x109_scrot.png │ ├── 2023-01-24-174713_657x178_scrot.png │ ├── phobescheatsheat.md │ └── dsyntaxcheatsheet.md ├── gentests.sh ├── README.md ├── newexample.sh ├── CONTRIBUTING.md └── curriculum.md ├── .gitignore ├── source ├── example8.d ├── example22.d ├── example20.d ├── example11.d ├── example1.d ├── example15.d ├── example5.d ├── example10.d ├── example19.d ├── example2.d ├── example21.d ├── example18.d ├── example14.d ├── example32.d ├── example9.d ├── example29.d ├── example13.d ├── example12.d ├── example28.d ├── example25.d ├── example17.d ├── example7.d ├── example33.d ├── example27.d ├── example36.d ├── example6.d ├── example34.d ├── example23.d ├── example3.d ├── example16.d ├── example26.d ├── example31.d ├── example4.d ├── example30.d ├── example24.d └── example35.d ├── README.md └── dingbats.d /.target/18: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /.target/19: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /.target/21: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /.target/22: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /.target/23: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /.target/20: -------------------------------------------------------------------------------- 1 | 2 | -------------------------------------------------------------------------------- /.target/1: -------------------------------------------------------------------------------- 1 | hello world 2 | -------------------------------------------------------------------------------- /.target/8: -------------------------------------------------------------------------------- 1 | hello world 2 | -------------------------------------------------------------------------------- /.target/10: -------------------------------------------------------------------------------- 1 | foobar 2 | 100 3 | -------------------------------------------------------------------------------- /.target/15: -------------------------------------------------------------------------------- 1 | [1, 2, 3, 4, 5] 2 | [2, 3, 4] 3 | -------------------------------------------------------------------------------- /files/names.csv: -------------------------------------------------------------------------------- 1 | John,Emily,Michael,Samantha,David -------------------------------------------------------------------------------- /.target/14: -------------------------------------------------------------------------------- 1 | [1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89] 2 | -------------------------------------------------------------------------------- /.target/17: -------------------------------------------------------------------------------- 1 | [1, 2, 3] 2 | [1] 3 | [10, 11, 12] 4 | -------------------------------------------------------------------------------- /.target/11: -------------------------------------------------------------------------------- 1 | John 2 | Emily 3 | Michael 4 | Samantha 5 | David 6 | -------------------------------------------------------------------------------- /.target/13: -------------------------------------------------------------------------------- 1 | [[0, 0, 0, 0, 0], [0, 0, 0, 0, 0], [0, 0, 0, 0, 1]] 2 | -------------------------------------------------------------------------------- /.target/12: -------------------------------------------------------------------------------- 1 | [1, 2] 2 | [1, 2, 3] 3 | [true, false] 4 | [true, true, true] 5 | -------------------------------------------------------------------------------- /.target/2: -------------------------------------------------------------------------------- 1 | 1 2 | 2 3 | 3 4 | 4 5 | 5 6 | 1 7 | 2 8 | 3 9 | 4 10 | 5 11 | -------------------------------------------------------------------------------- /.target/3: -------------------------------------------------------------------------------- 1 | even 2 | odd 3 | even 4 | odd 5 | even 6 | odd 7 | even 8 | odd 9 | even 10 | odd 11 | even 12 | -------------------------------------------------------------------------------- /.dev/intendedsolutions/template: -------------------------------------------------------------------------------- 1 | /* 2 | 3 | 4 | 5 | 6 | */ 7 | import std; 8 | 9 | 10 | unittest{ 11 | 12 | 13 | 14 | } -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | *.o 2 | *.exe 3 | *.so 4 | *.dylib 5 | *.dll 6 | *.a 7 | *.lib 8 | *.exe 9 | *.pdb 10 | *.o 11 | *.obj 12 | *.lst 13 | -------------------------------------------------------------------------------- /.dev/design_rants/linuxspremeecy.md: -------------------------------------------------------------------------------- 1 | linux is the target os 2 | porting to windows should not happen until I truely and competely consider it done -------------------------------------------------------------------------------- /.dev/unorginizedcode/2023-01-24-174703_662x97_scrot.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/crazymonkyyy/dingbats/HEAD/.dev/unorginizedcode/2023-01-24-174703_662x97_scrot.png -------------------------------------------------------------------------------- /.dev/unorginizedcode/2023-01-24-174707_651x109_scrot.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/crazymonkyyy/dingbats/HEAD/.dev/unorginizedcode/2023-01-24-174707_651x109_scrot.png -------------------------------------------------------------------------------- /.dev/unorginizedcode/2023-01-24-174713_657x178_scrot.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/crazymonkyyy/dingbats/HEAD/.dev/unorginizedcode/2023-01-24-174713_657x178_scrot.png -------------------------------------------------------------------------------- /.target/4: -------------------------------------------------------------------------------- 1 | 1 2 | 2 3 | fizz 4 | 4 5 | buzz 6 | fizz 7 | 7 8 | 8 9 | fizz 10 | buzz 11 | 11 12 | fizz 13 | 13 14 | 14 15 | fizzbuzz 16 | 16 17 | 17 18 | fizz 19 | 19 20 | buzz 21 | -------------------------------------------------------------------------------- /.dev/gentests.sh: -------------------------------------------------------------------------------- 1 | for s in .dev/intendedsolutions/example*.d; do 2 | s=${s%.d} 3 | s=${s#.dev/intendedsolutions/example} 4 | echo "$s" 5 | dmd -i -run .dev/intendedsolutions/example$s > .target/$s 6 | done -------------------------------------------------------------------------------- /source/example8.d: -------------------------------------------------------------------------------- 1 | /* 2 | imports 3 | 4 | every previsous file had a line of code; idk was it important? 5 | 6 | output: 7 | print "hello world" 8 | */ 9 | 10 | void main(){ 11 | "hello world".writeln; 12 | } -------------------------------------------------------------------------------- /source/example22.d: -------------------------------------------------------------------------------- 1 | /* 2 | Asserts 3 | 4 | asserts are phases that decare a statement true or else the program dies 5 | */ 6 | 7 | unittest{ 8 | assert(false,"maybe its true idk"); 9 | } 10 | 11 | void main(){ 12 | assert(false); 13 | } -------------------------------------------------------------------------------- /.dev/intendedsolutions/example8.d: -------------------------------------------------------------------------------- 1 | /* 2 | imports 3 | 4 | every previsous file had a line of code; idk was it important? 5 | 6 | output: 7 | print "hello world" 8 | */ 9 | 10 | import std; 11 | 12 | void main(){ 13 | "hello world".writeln; 14 | } -------------------------------------------------------------------------------- /.dev/intendedsolutions/example22.d: -------------------------------------------------------------------------------- 1 | /* 2 | Asserts 3 | 4 | asserts are phases that decare a statement true or else the program dies 5 | */ 6 | 7 | unittest{ 8 | assert(false,"maybe its true idk"); 9 | } 10 | 11 | void main(){ 12 | assert(false); 13 | } -------------------------------------------------------------------------------- /source/example20.d: -------------------------------------------------------------------------------- 1 | /* 2 | Running commands 3 | 4 | Std.process has the tools to run shell commands, mostly just `executeShell.output` 5 | 6 | https://dlang.org/phobos/std_process.html 7 | 8 | output: 9 | print the output of ls 10 | */ 11 | 12 | import std; 13 | void main(){ 14 | .writeln; 15 | } -------------------------------------------------------------------------------- /.dev/intendedsolutions/example20.d: -------------------------------------------------------------------------------- 1 | /* 2 | Running commands 3 | 4 | Std.process has the tools to run shell commands, mostly just `executeShell.output` 5 | 6 | https://dlang.org/phobos/std_process.html 7 | 8 | output: 9 | print the output of ls 10 | */ 11 | 12 | import std; 13 | void main(){ 14 | .writeln; 15 | } -------------------------------------------------------------------------------- /source/example11.d: -------------------------------------------------------------------------------- 1 | /* 2 | 3 | "The genius of csv, is that values are seperated by commas, 4 | but it takes a genius to know that its simpliticly is genius" 5 | -genius who made csv 6 | 7 | output: 8 | print out the names by line 9 | */ 10 | enum csv="files/names.csv"; 11 | 12 | import std; 13 | void main(){ 14 | .writeln; 15 | } -------------------------------------------------------------------------------- /.target/16: -------------------------------------------------------------------------------- 1 | element 0: 2 | 1 is min 3 | 3 is max 4 | element 1: 5 | -5 is min 6 | 2 is max 7 | element 2: 8 | 3 is min 9 | 7 is max 10 | element 3: 11 | 4 is min 12 | 10 is max 13 | element 4: 14 | 0 is min 15 | 5 is max 16 | --- 17 | 1 is min of array1 18 | 5 is max of array1 19 | -5 is min of array2 20 | 10 is max of array2 21 | -------------------------------------------------------------------------------- /.dev/README.md: -------------------------------------------------------------------------------- 1 | ### Sercet dev zone 2 | 3 | put dev things here 4 | 5 | ### todo for beta 6 | 7 | * find contibutors 8 | * find contribtors with writing experience 9 | * debate about/finalize cirriculum 10 | * swap dev tools to handle "chapters"/"folders" 11 | * improve biuld tool in many ways 12 | * add all missing examples to this list 13 | -------------------------------------------------------------------------------- /.dev/intendedsolutions/example1.d: -------------------------------------------------------------------------------- 1 | /* 2 | Welcome to Dingbats, please fix the bugs to learn dlang. 3 | if you havnt already run ./dingbats in the main folder to test your solutions. 4 | This is a hello world with a typo 5 | output: 6 | print "hello world" with an end line 7 | */ 8 | 9 | import std; 10 | void main(){ 11 | "hello world".writeln; 12 | } -------------------------------------------------------------------------------- /source/example1.d: -------------------------------------------------------------------------------- 1 | /* 2 | Welcome to the first exersice of Dingbats! 3 | If you haven't already done so, run "rdmd dingbats" in the main folder. 4 | 5 | Description: 6 | This is a hello-world program with a typo. 7 | 8 | Expected Output: 9 | hello world 10 | */ 11 | 12 | import std; 13 | 14 | void main() { 15 | writeln("helo world"); 16 | } 17 | -------------------------------------------------------------------------------- /.dev/intendedsolutions/example15.d: -------------------------------------------------------------------------------- 1 | /* 2 | Sliceing slices of slices 3 | 4 | You can take slice from a static array(and other slices) with [0..$] 5 | and it will be a nice refernce; however when you write to it it teleports away 6 | 7 | output: 8 | idk 9 | */ 10 | 11 | import std; 12 | void main(){ 13 | int[5] foo=[1,2,3,4,5]; 14 | foo.writeln; 15 | foo[1..4].writeln; 16 | } -------------------------------------------------------------------------------- /source/example15.d: -------------------------------------------------------------------------------- 1 | /* 2 | Sliceing slices of slices 3 | 4 | You can take slice from a static array(and other slices) with [0..$] 5 | and it will be a nice refernce; however when you write to it it teleports away 6 | 7 | output: 8 | idk what to test here 9 | */ 10 | 11 | import std; 12 | void main(){ 13 | int[5] foo=[1,2,3,4,5]; 14 | foo.writeln; 15 | foo[1..4].writeln; 16 | } -------------------------------------------------------------------------------- /source/example5.d: -------------------------------------------------------------------------------- 1 | /* 2 | fizzbuzz 3 | 4 | write fizzbuzz from sratch just to see if your paying attension 5 | I suggest you reread the previsous examples to get the syntax down 6 | 7 | output 8 | 1-100 fizzbuzz 9 | %3 fizz 10 | %5 buzz 11 | */ 12 | 13 | import std; 14 | 15 | string tostring(int i){ 16 | return i.to!string;//we will get to whats happening here soon 17 | } 18 | -------------------------------------------------------------------------------- /source/example10.d: -------------------------------------------------------------------------------- 1 | /* 2 | std string 3 | 4 | Find the functions to edit strings 5 | 6 | https://dlang.org/library/std/string.html 7 | 8 | output: 9 | print "foobar" then "100" using std functions 10 | */ 11 | 12 | string a=" foobar"; 13 | string b="99"; 14 | 15 | import std; 16 | void main(){ 17 | a=a.???;//removes tabs 18 | b=b.???;//add 1 19 | a.writeln; 20 | b.writeln; 21 | } -------------------------------------------------------------------------------- /source/example19.d: -------------------------------------------------------------------------------- 1 | /* 2 | Taking command line arguments 3 | 4 | you just use main(string[] s) and note that s[0] will be not important 5 | 6 | output: 7 | reimpliment cat 8 | */ 9 | 10 | import std; 11 | void main(string[] s){ 12 | foreach(file;???){ 13 | if(file=="-v"){"considered harmful".writeln; return;} 14 | foreach(line;File(file).byLineCopy){ 15 | line.writeln; 16 | }} 17 | } -------------------------------------------------------------------------------- /source/example2.d: -------------------------------------------------------------------------------- 1 | /* 2 | loops 3 | 4 | the go to loop is foreach(element[s]; list), while c "for" loops exist theses 5 | wont be used. Generally this will only show the best tools. 6 | 7 | output: 8 | print 1-5, on different lines, twice. 9 | */ 10 | 11 | import std; 12 | 13 | void main(){ 14 | foreach(i;[1,2,3,4,5]){ 15 | //hmmm 16 | } 17 | foreach(i;1..5){ 18 | i.writeln; 19 | } 20 | } -------------------------------------------------------------------------------- /.dev/intendedsolutions/example10.d: -------------------------------------------------------------------------------- 1 | /* 2 | std string 3 | 4 | Find the functions to edit strings 5 | 6 | https://dlang.org/library/std/string.html 7 | 8 | output: 9 | print "foobar" then "100" using std functions 10 | */ 11 | 12 | string a=" foobar"; 13 | string b="99"; 14 | 15 | import std; 16 | void main(){ 17 | a=a.strip;//removes tabs 18 | b=b.succ;//add 1 19 | a.writeln; 20 | b.writeln; 21 | } -------------------------------------------------------------------------------- /.dev/newexample.sh: -------------------------------------------------------------------------------- 1 | i=0 2 | #for s in .dev/intendedsolutions/example*.d; do 3 | # s=${s%.d} 4 | # s=${s#.dev/intendedsolutions/example} 5 | # i=$s; 6 | # echo "$i" 7 | #done 8 | s=$(ls .dev/in* -v | tail -n 2 | head -n 1) 9 | echo "$s" 10 | s=${s%.d} 11 | s=${s#example} 12 | i=$s; 13 | echo "$i" 14 | ((i=i+1)) 15 | echo "$i" 16 | cp .dev/intendedsolutions/template ".dev/intendedsolutions/example${i}.d" 17 | -------------------------------------------------------------------------------- /.dev/intendedsolutions/example19.d: -------------------------------------------------------------------------------- 1 | /* 2 | Taking command line arguments 3 | 4 | you just use main(string[] s) and note that s[0] will be not important 5 | 6 | output: 7 | reimpliment cat 8 | */ 9 | 10 | import std; 11 | void main(string[] s){ 12 | foreach(file;s[1..$]){ 13 | if(file=="-v"){"considered harmful".writeln; return;} 14 | foreach(line;File(file).byLineCopy){ 15 | line.writeln; 16 | }} 17 | } -------------------------------------------------------------------------------- /source/example21.d: -------------------------------------------------------------------------------- 1 | /* 2 | Unittests 3 | 4 | You can at any point in time, add a unittest, 5 | it will run before main if pass -unittest(this is happening now) 6 | 7 | output: 8 | nothing 9 | */ 10 | 11 | import std; 12 | struct foo{ 13 | unittest{ 14 | int foo 15 | } 16 | } 17 | 18 | //void main(){} 19 | //main will no longer be used this is done with the -main flag 20 | 21 | unittest{ 22 | int bar 23 | } -------------------------------------------------------------------------------- /.dev/intendedsolutions/example2.d: -------------------------------------------------------------------------------- 1 | /* 2 | loops 3 | 4 | the go to loop is foreach(element[s]; list), while c "for" loops exist theses 5 | wont be used. Generally this will only show the best tools. 6 | 7 | output: 8 | print 1-5, on different lines, twice. 9 | */ 10 | 11 | import std; 12 | 13 | void main(){ 14 | foreach(i;[1,2,3,4,5]){ 15 | i.writeln; 16 | } 17 | foreach(i;1..5+1){ 18 | i.writeln; 19 | } 20 | } -------------------------------------------------------------------------------- /source/example18.d: -------------------------------------------------------------------------------- 1 | /* 2 | Writing files 3 | 4 | to write to a file, you use the same File struct from the std, 5 | but you add a "w" to set a write flag 6 | 7 | https://dlang.org/phobos/std_stdio.html#.File 8 | 9 | output: 10 | write 1..5 to a temp file 11 | */ 12 | import std; 13 | enum string writefile="files/temp"; 14 | void main(){ 15 | File foo=???; 16 | foreach(i;1..5+1){ 17 | foo.writeln(i); 18 | } 19 | } -------------------------------------------------------------------------------- /source/example14.d: -------------------------------------------------------------------------------- 1 | /* 2 | $ 3 | 4 | Theres some syntax sugar on arrays the $ will mean length 5 | what does that mean in a 0 index paradiem tho hmmmmm 6 | 7 | output: 8 | make an array thats the frist 10 fibinaty squence //TODO spellcheck 9 | */ 10 | 11 | import std; 12 | void main(){ 13 | int[] foo; 14 | foo~=1; 15 | foo~=foo[$]; 16 | foreach(i;0..8+1){ 17 | foo~=foo[???]+foo[???]; 18 | } 19 | foo.writeln; 20 | } -------------------------------------------------------------------------------- /.dev/intendedsolutions/example21.d: -------------------------------------------------------------------------------- 1 | /* 2 | Unittests 3 | 4 | You can at any point in time, add a unittest, 5 | it will run before main if pass -unittest(this is happening now) 6 | 7 | output: 8 | nothing 9 | */ 10 | 11 | import std; 12 | struct foo{ 13 | unittest{ 14 | int foo 15 | } 16 | } 17 | 18 | //void main(){} 19 | //main will no longer be used this is done with the -main flag 20 | 21 | unittest{ 22 | int bar 23 | } -------------------------------------------------------------------------------- /source/example32.d: -------------------------------------------------------------------------------- 1 | /* 2 | reading the range docs 3 | 4 | http://phobos.dpldocs.info/std.range.html 5 | 6 | impliment myenumerate so that you can foreach a range with a index 7 | */ 8 | import std.range:zip,iota; 9 | 10 | auto myenumerate ???{ 11 | return ???; 12 | } 13 | 14 | unittest{ 15 | int[] foo=[0,1,2,3,4,5]; 16 | import std.algorithm; 17 | foreach(i,e;foo.map!"a*a".myenumerate){ 18 | assert(e==i*i); 19 | } 20 | } -------------------------------------------------------------------------------- /source/example9.d: -------------------------------------------------------------------------------- 1 | /* 2 | Files 3 | 4 | time to learn how to read the std docs... warning they airnt great and awfully verbose 5 | 6 | take this link and make an attempt 7 | https://dlang.org/library/std/stdio/file.by_line_copy.html 8 | 9 | output: 10 | print out the book list 11 | */ 12 | import std; 13 | 14 | enum booklist="files/books"; 15 | 16 | void main(){ 17 | foreach(book; ???){ 18 | book.writeln; 19 | } 20 | } -------------------------------------------------------------------------------- /.dev/intendedsolutions/example18.d: -------------------------------------------------------------------------------- 1 | /* 2 | Writing files 3 | 4 | to write to a file, you use the same File struct from the std, 5 | but you add a "w" to set a write flag 6 | 7 | https://dlang.org/phobos/std_stdio.html#.File 8 | 9 | output: 10 | write 1..5 to a temp file 11 | */ 12 | import std; 13 | enum string writefile="files/temp"; 14 | void main(){ 15 | File foo=???; 16 | foreach(i;1..5+1){ 17 | foo.writeln(i); 18 | } 19 | } -------------------------------------------------------------------------------- /.dev/intendedsolutions/example14.d: -------------------------------------------------------------------------------- 1 | /* 2 | $ 3 | 4 | Theres some syntax sugar on arrays the $ will mean length 5 | what does that mean in a 0 index paradiem tho hmmmmm 6 | 7 | output: 8 | make an array thats the frist 10 fibinaty squence //TODO spellcheck 9 | */ 10 | 11 | import std; 12 | void main(){ 13 | int[] foo; 14 | foo~=1; 15 | foo~=foo[$-1]; 16 | foreach(i;0..8+1){ 17 | foo~=foo[$-2]+foo[$-1]; 18 | } 19 | foo.writeln; 20 | } -------------------------------------------------------------------------------- /source/example29.d: -------------------------------------------------------------------------------- 1 | /* 2 | functions as 2nd class parameters 3 | 4 | You can pass functions to another with "alias" as its type; 5 | this doesnt make sense to me either. 6 | 7 | Note this can get you into trouble if you over use it 8 | */ 9 | import std; 10 | 11 | void call3times(??? F)(){ 12 | F;F;F; 13 | } 14 | 15 | 16 | unittest{ 17 | int[] foo; 18 | void addtofoo(){ 19 | foo~=1; 20 | } 21 | ??? 22 | assert(foo==[1,1,1]); 23 | } -------------------------------------------------------------------------------- /.dev/intendedsolutions/example9.d: -------------------------------------------------------------------------------- 1 | /* 2 | Files 3 | 4 | time to learn how to read the std docs... warning they airnt great and awfully verbose 5 | 6 | take this link and make an attempt 7 | https://dlang.org/library/std/stdio/file.by_line_copy.html 8 | 9 | output: 10 | print out the book list 11 | */ 12 | import std; 13 | 14 | enum booklist="files/books"; 15 | 16 | void main(){ 17 | foreach(book; File(booklist).byLineCopy){ 18 | book.writeln; 19 | } 20 | } -------------------------------------------------------------------------------- /source/example13.d: -------------------------------------------------------------------------------- 1 | /* 2 | Arrays 3 | 4 | static arrays exist as well BUT time to cry about d's type system 5 | defination is backwards from use ;__; 6 | 7 | if you ask why youll get an answer saying its better then "cdecl", which fair; 8 | but also no, bad design :spray_bottle: 9 | 10 | output: 11 | define a 3x5 int array and set the 2,4 value to 1 12 | */ 13 | 14 | import std; 15 | void main(){ 16 | int[3][5] foo; 17 | foo[2][4]=1; 18 | foo.writeln; 19 | } -------------------------------------------------------------------------------- /.dev/intendedsolutions/example32.d: -------------------------------------------------------------------------------- 1 | /* 2 | reading the range docs 3 | 4 | http://phobos.dpldocs.info/std.range.html 5 | 6 | impliment myenumerate so that you can foreach a range with a index 7 | */ 8 | import std.range:zip,iota; 9 | 10 | auto myenumerate(R)(R r){ 11 | return zip(iota(r.length),r); 12 | } 13 | 14 | unittest{ 15 | int[] foo=[0,1,2,3,4,5]; 16 | import std.algorithm; 17 | foreach(i,e;foo.map!"a*a".myenumerate){ 18 | assert(e==i*i); 19 | } 20 | } -------------------------------------------------------------------------------- /source/example12.d: -------------------------------------------------------------------------------- 1 | /* 2 | 3 | Slices 4 | 5 | d has biult in "dynmaic arrays"/"vector"/etc. called slices 6 | syntax is just `int[]`, `[0]` access and `~=` append 7 | 8 | 9 | output: 10 | eh.... todo 11 | */ 12 | 13 | import std; 14 | void main(){ 15 | int[] foo; 16 | foo~=1; 17 | foo~=2; 18 | foo.writeln; 19 | foo~=3; 20 | foo.writeln; 21 | 22 | ??? bar; 23 | bar~=true; 24 | ???; 25 | bar.writeln; 26 | bar[1]=???; 27 | bar~=???; 28 | bar.writeln; 29 | } -------------------------------------------------------------------------------- /.dev/intendedsolutions/example13.d: -------------------------------------------------------------------------------- 1 | /* 2 | Arrays 3 | 4 | static arrays exist as well BUT time to cry about d's type system 5 | defination is backwards from use ;__; 6 | 7 | if you ask why youll get an answer saying its better then "cdecl", which fair; 8 | but also no, bad design :spray_bottle: 9 | 10 | output: 11 | define a 3x5 int array and set the 2,4 value to 1 12 | */ 13 | 14 | import std; 15 | void main(){ 16 | int[5][3] foo; 17 | foo[2][4]=1; 18 | foo.writeln; 19 | } -------------------------------------------------------------------------------- /.dev/intendedsolutions/example29.d: -------------------------------------------------------------------------------- 1 | /* 2 | functions as 2nd class parameters 3 | 4 | You can pass functions to another with "alias" as its type; 5 | this doesnt make sense to me either. 6 | 7 | Note this can get you into trouble if you over use it 8 | */ 9 | import std; 10 | 11 | void call3times(alias F)(){ 12 | F;F;F; 13 | } 14 | 15 | 16 | unittest{ 17 | int[] foo; 18 | void addtofoo(){ 19 | foo~=1; 20 | } 21 | call3times!addtofoo; 22 | assert(foo==[1,1,1]); 23 | } -------------------------------------------------------------------------------- /.dev/intendedsolutions/example12.d: -------------------------------------------------------------------------------- 1 | /* 2 | 3 | Slices 4 | 5 | d has biult in "dynmaic arrays"/"vector"/etc. called slices 6 | syntax is just `int[]`, `[0]` access and `~=` append 7 | 8 | 9 | output: 10 | eh.... todo 11 | */ 12 | 13 | import std; 14 | void main(){ 15 | int[] foo; 16 | foo~=1; 17 | foo~=2; 18 | foo.writeln; 19 | foo~=3; 20 | foo.writeln; 21 | 22 | bool[] bar; 23 | bar~=true; 24 | bar~=false; 25 | bar.writeln; 26 | bar[1]=true; 27 | bar~=true; 28 | bar.writeln; 29 | } -------------------------------------------------------------------------------- /source/example28.d: -------------------------------------------------------------------------------- 1 | /* 2 | voldemore types, auto and typeof 3 | 4 | you can define structs inside functions, you can return them with auto 5 | then use typeof to gain access to it in meta code "without having its name" 6 | 7 | this is called the voldemore pattern 8 | */ 9 | import std; 10 | 11 | auto foo(){ 12 | struct mystruct{int i;} 13 | return mystruct; 14 | } 15 | unittest{ 16 | auto bar=foo; 17 | typeof(bar)[] bararray=[bar]; 18 | } 19 | 20 | unittest{ 21 | assert(0,"idk how to test this"); 22 | } -------------------------------------------------------------------------------- /source/example25.d: -------------------------------------------------------------------------------- 1 | /* 2 | Templates for containers 3 | 4 | You can pass "arguments" to "structs", using the same headers as you did for 5 | genertic functions and "!" when calling. 6 | */ 7 | 8 | struct mynullable(T){ 9 | bool isnull=true; 10 | T me; 11 | } 12 | unittest{ 13 | mynullable!int foo; 14 | foo.isnull=false; 15 | foo.me=10; 16 | } 17 | 18 | struct myarray(???){ 19 | T[n] me; 20 | } 21 | unittest{ 22 | myarray!(int,10) foo; 23 | foo.me[9]=1; 24 | myarray!(float,5) bar; 25 | bar.me[5]=1; 26 | } -------------------------------------------------------------------------------- /.dev/intendedsolutions/example11.d: -------------------------------------------------------------------------------- 1 | /* 2 | 3 | "The genius of csv, is that values are seperated by commas, 4 | but it takes a genius to know that its simpliticly is genius" 5 | -genius who made csv 6 | 7 | output: 8 | print out the names by line 9 | */ 10 | enum csv="files/names.csv"; 11 | 12 | import std; 13 | void main(){ 14 | //foreach(s;File(csv).byLineCopy.front.split(',')){ 15 | // s.writeln; 16 | //} 17 | foreach(list;File(csv).byLineCopy){ 18 | foreach(s;list.split(',')){ 19 | s.writeln; 20 | }} 21 | } -------------------------------------------------------------------------------- /.dev/intendedsolutions/example28.d: -------------------------------------------------------------------------------- 1 | /* 2 | voldemore types, auto and typeof 3 | 4 | you can define structs inside functions, you can return them with auto 5 | then use typeof to gain access to it in meta code "without having its name" 6 | 7 | this is called the voldemore pattern 8 | */ 9 | import std; 10 | 11 | auto foo(){ 12 | struct mystruct{int i;} 13 | return mystruct(); 14 | } 15 | unittest{ 16 | auto bar=foo; 17 | typeof(bar)[] bararray=[bar]; 18 | } 19 | 20 | unittest{ 21 | assert(1,"idk how to test this"); 22 | } -------------------------------------------------------------------------------- /.dev/design_rants/styleguide.md: -------------------------------------------------------------------------------- 1 | the writing should be concise, informal and above all else written in human 2 | the offical sytle guide has no power here 3 | all else is not yet decided 4 | 5 | only contributiters who join quickly will have any say 6 | if ive written 50 examples and you tell me to not say "the std has shitty names" in some comment about canFind I will ignore you 7 | if you want to say "odd number lines should be tabs, even number lines should be 7 spaces" but you submitted 20 examples, welcome please write the style guide -------------------------------------------------------------------------------- /.dev/intendedsolutions/example25.d: -------------------------------------------------------------------------------- 1 | /* 2 | Templates for containers 3 | 4 | You can pass "arguments" to "structs", using the same headers as you did for 5 | genertic functions and "!" when calling. 6 | */ 7 | 8 | struct mynullable(T){ 9 | bool isnull=true; 10 | T me; 11 | } 12 | unittest{ 13 | mynullable!int foo; 14 | foo.isnull=false; 15 | foo.me=10; 16 | } 17 | 18 | struct myarray(T,int n){ 19 | T[n] me; 20 | } 21 | unittest{ 22 | myarray!(int,10) foo; 23 | foo.me[9]=1; 24 | myarray!(float,6) bar; 25 | bar.me[5]=1; 26 | } -------------------------------------------------------------------------------- /source/example17.d: -------------------------------------------------------------------------------- 1 | /* 2 | $ abuse 3 | 4 | I dont understand why this isnt well know, but if you have access tothe length 5 | inside the [], and thats an expression, you can use math functions inside the []s 6 | 7 | output: 8 | print out the frist 3 elements of the 3 arrays 9 | */ 10 | 11 | import std.algorithm.comparison : min; 12 | import std; 13 | void main(){ 14 | int[] array1=[1,2,3,4,5]; 15 | int[] array2=[1]; 16 | int[] array3=[10,11,12,13,14]; 17 | foreach(array;[array1,array2,array3]){ 18 | array[0..3].writeln; 19 | } 20 | } -------------------------------------------------------------------------------- /.dev/intendedsolutions/example17.d: -------------------------------------------------------------------------------- 1 | /* 2 | $ abuse 3 | 4 | I dont understand why this isnt well know, but if you have access tothe length 5 | inside the [], and thats an expression, you can use math functions inside the []s 6 | 7 | output: 8 | print out the frist 3 elements of the 3 arrays 9 | */ 10 | 11 | import std.algorithm.comparison : min; 12 | import std; 13 | void main(){ 14 | int[] array1=[1,2,3,4,5]; 15 | int[] array2=[1]; 16 | int[] array3=[10,11,12,13,14]; 17 | foreach(array;[array1,array2,array3]){ 18 | array[0..min(3,$)].writeln; 19 | } 20 | } -------------------------------------------------------------------------------- /files/books: -------------------------------------------------------------------------------- 1 | The Great Gatsby 2 | To Kill a Mockingbird 3 | The Catcher in the Rye 4 | 1984 5 | Pride and Prejudice 6 | The Lord of the Rings 7 | The Hobbit 8 | Harry Potter and the Sorcerer's Stone 9 | Harry Potter and the Chamber of Secrets 10 | Harry Potter and the Prisoner of Azkaban 11 | Harry Potter and the Goblet of Fire 12 | Harry Potter and the Order of Phoenix 13 | Harry Potter and the Half-Blood Prince 14 | Harry Potter and the Deathly Hallows 15 | The Hunger Games 16 | The Giver 17 | The Fault in Our Stars 18 | The Diary of a Young Girl 19 | The Chronicles of Narnia 20 | The Adventures of Huckleberry Finn -------------------------------------------------------------------------------- /source/example7.d: -------------------------------------------------------------------------------- 1 | /* 2 | Writing structs 3 | 4 | please define nullable int; reminder this was vec2 from the last example: 5 | 6 | struct vec2{ 7 | int x; 8 | int y; 9 | } 10 | 11 | for now nullables are just a type and bool called isnull, 12 | we'll get to op overloading later 13 | 14 | output: 15 | generate 0..100 nullableints, ints that are %3==0 should be null 16 | */ 17 | 18 | 19 | import std; 20 | void main(){ 21 | foreach(i;0..100){ 22 | bool isnull=i%3==0; 23 | nullableint foo=nullableint(i,isnull); 24 | writeln( 25 | foo," : ", 26 | foo.isnull,",", 27 | foo.i 28 | ); 29 | } 30 | } -------------------------------------------------------------------------------- /.target/9: -------------------------------------------------------------------------------- 1 | The Great Gatsby 2 | To Kill a Mockingbird 3 | The Catcher in the Rye 4 | 1984 5 | Pride and Prejudice 6 | The Lord of the Rings 7 | The Hobbit 8 | Harry Potter and the Sorcerer's Stone 9 | Harry Potter and the Chamber of Secrets 10 | Harry Potter and the Prisoner of Azkaban 11 | Harry Potter and the Goblet of Fire 12 | Harry Potter and the Order of Phoenix 13 | Harry Potter and the Half-Blood Prince 14 | Harry Potter and the Deathly Hallows 15 | The Hunger Games 16 | The Giver 17 | The Fault in Our Stars 18 | The Diary of a Young Girl 19 | The Chronicles of Narnia 20 | The Adventures of Huckleberry Finn 21 | -------------------------------------------------------------------------------- /source/example33.d: -------------------------------------------------------------------------------- 1 | /* 2 | count duplicate dominos 3 | 4 | just some practice; [1,2] == [2,1] cause you can rotate it 5 | 6 | read those docs 7 | http://phobos.dpldocs.info/std.algorithm.html 8 | */ 9 | import std; 10 | 11 | alias domino=int[2]; 12 | domino rotate(domino d){ 13 | return [d[1],d[0]]; 14 | } 15 | int dupdominos(domino[] arr){ 16 | //??? 17 | return cast(int)(0); 18 | } 19 | unittest{ 20 | assert([].dupdominos==0); 21 | assert([[1,2],[2,1]].dupdominos==1); 22 | assert([[1,2],[2,1],[1,2],[2,1]].dupdominos==3); 23 | assert([[3,4],[6,6],[1,1],[3,3],[4,3],[1,1],[5,3],[5,3],[6,6]].dupdominos==4); 24 | } -------------------------------------------------------------------------------- /.target/6: -------------------------------------------------------------------------------- 1 | myint(0) : 0 2 | myint(1) : 1 3 | myint(2) : 2 4 | myint(3) : 3 5 | myint(4) : 4 6 | vec2(0, 0) : 0,0 7 | vec2(0, 1) : 0,1 8 | vec2(0, 2) : 0,2 9 | vec2(0, 3) : 0,3 10 | vec2(0, 4) : 0,4 11 | vec2(1, 0) : 1,0 12 | vec2(1, 1) : 1,1 13 | vec2(1, 2) : 1,2 14 | vec2(1, 3) : 1,3 15 | vec2(1, 4) : 1,4 16 | vec2(2, 0) : 2,0 17 | vec2(2, 1) : 2,1 18 | vec2(2, 2) : 2,2 19 | vec2(2, 3) : 2,3 20 | vec2(2, 4) : 2,4 21 | vec2(3, 0) : 3,0 22 | vec2(3, 1) : 3,1 23 | vec2(3, 2) : 3,2 24 | vec2(3, 3) : 3,3 25 | vec2(3, 4) : 3,4 26 | vec2(4, 0) : 4,0 27 | vec2(4, 1) : 4,1 28 | vec2(4, 2) : 4,2 29 | vec2(4, 3) : 4,3 30 | vec2(4, 4) : 4,4 31 | -------------------------------------------------------------------------------- /source/example27.d: -------------------------------------------------------------------------------- 1 | /* 2 | ranges 2 3 | 4 | Templates enable ranges, prove you understand that 5 | */ 6 | import std; 7 | 8 | struct counter{ 9 | int front;//yes this is legal 10 | int end; 11 | void popFront(){ 12 | front++; 13 | } 14 | bool empty(){ 15 | return front>=end; 16 | } 17 | } 18 | 19 | ??? getcounter ??? { 20 | return counter(0,cast(int)r.length); 21 | // standard termology is for an anonous range its type is R and its varible is r 22 | } 23 | 24 | unittest{ 25 | int[] foo; 26 | foo.length=10; 27 | int[5] bar; 28 | assert(foo.getcounter==counter(0,10)); 29 | assert(bar.getcounter==counter(0,5)); 30 | } -------------------------------------------------------------------------------- /source/example36.d: -------------------------------------------------------------------------------- 1 | /* 2 | the formal range interface 3 | 4 | I hate this thing and wish there was just a list of optional functions, but the 5 | std uses it and I expect you will need to care about it at some point 6 | 7 | with great sadness, please impliment something that qualifies as a 8 | `RandomAccessFinite range` 9 | 10 | thats comes out like sandpaper sliding off the tougue 11 | 12 | http://phobos.dpldocs.info/std.range.interfaces.html 13 | 14 | */ 15 | import std.range.interfaces; 16 | 17 | struct myrange{ 18 | ??? 19 | } 20 | 21 | unittest{ 22 | assert(is(MostDerivedInputRange!myrange==RandomAccessFinite!(int))); 23 | } -------------------------------------------------------------------------------- /.dev/intendedsolutions/example27.d: -------------------------------------------------------------------------------- 1 | /* 2 | ranges 2 3 | 4 | Templates enable ranges, prove you understand that 5 | */ 6 | import std; 7 | 8 | struct counter{ 9 | int front;//yes this is legal 10 | int end; 11 | void popFront(){ 12 | front++; 13 | } 14 | bool empty(){ 15 | return front>=end; 16 | } 17 | } 18 | 19 | auto getcounter(R)(R r){ 20 | return counter(0,cast(int)r.length); 21 | // standard termology is for an anonous range its type is R and its varible is r 22 | } 23 | 24 | unittest{ 25 | int[] foo; 26 | foo.length=10; 27 | int[5] bar; 28 | assert(foo.getcounter==counter(0,10)); 29 | assert(bar.getcounter==counter(0,5)); 30 | } -------------------------------------------------------------------------------- /.dev/intendedsolutions/example7.d: -------------------------------------------------------------------------------- 1 | /* 2 | Writing structs 3 | 4 | please define nullable int; reminder this was vec2 from the last example: 5 | 6 | struct vec2{ 7 | int x; 8 | int y; 9 | } 10 | 11 | for now nullables are just a type and bool called isnull, 12 | we'll get to op overloading later 13 | 14 | output: 15 | generate 0..100 nullableints, ints that are %3==0 should be null 16 | */ 17 | 18 | struct nullableint{ 19 | int i; 20 | bool isnull; 21 | } 22 | 23 | import std; 24 | void main(){ 25 | foreach(i;0..100){ 26 | bool isnull=i%3==0; 27 | nullableint foo=nullableint(i,isnull); 28 | writeln( 29 | foo," : ", 30 | foo.isnull,",", 31 | foo.i 32 | ); 33 | } 34 | } -------------------------------------------------------------------------------- /.dev/intendedsolutions/example33.d: -------------------------------------------------------------------------------- 1 | /* 2 | count duplicate dominos 3 | 4 | just some practice; [1,2] == [2,1] cause you can rotate it 5 | 6 | read those docs 7 | http://phobos.dpldocs.info/std.algorithm.html 8 | */ 9 | import std; 10 | 11 | alias domino=int[2]; 12 | domino rotate(domino d){ 13 | return [d[1],d[0]]; 14 | } 15 | int dupdominos(domino[] arr){ 16 | auto b=arr.map!(a=>a[1]>a[0] ? rotate(a):a) 17 | .array.sort 18 | .uniq; 19 | return cast(int)(arr.length-b.count); 20 | } 21 | unittest{ 22 | assert([].dupdominos==0); 23 | assert([[1,2],[2,1]].dupdominos==1); 24 | assert([[1,2],[2,1],[1,2],[2,1]].dupdominos==3); 25 | assert([[3,4],[6,6],[1,1],[3,3],[4,3],[1,1],[5,3],[5,3],[6,6]].dupdominos==4); 26 | } -------------------------------------------------------------------------------- /source/example6.d: -------------------------------------------------------------------------------- 1 | /* 2 | Structs, they group data together with names 3 | 4 | in d they can be consturucted by writing `mystructname("my structs args",1)` 5 | varibles are accessed with a `.` 6 | 7 | output: 8 | generate 0..5 myints and print them out with thier i 9 | 10 | geratate vec2s for a 5 by 5 area and print out thier x and y 11 | */ 12 | import std; 13 | 14 | struct myint{ 15 | int i; 16 | } 17 | struct vec2{ 18 | int x; 19 | int y; 20 | } 21 | 22 | void main(){ 23 | foreach(j;0..5){ 24 | myint foo=myint(j); 25 | writeln( 26 | , " : ", 27 | , 28 | ); 29 | } 30 | foreach(a;0..5){ 31 | foreach(b;0..5){ 32 | vec2 foo=???; 33 | writeln( 34 | , " : ", 35 | , ",", 36 | 37 | ); 38 | }} 39 | } -------------------------------------------------------------------------------- /source/example34.d: -------------------------------------------------------------------------------- 1 | /* 2 | Exact chunks 3 | 4 | return range of ranges that are of fixed size `n`, BUT if final chunk is less then `n`, 5 | add extra elements `fill` 6 | */ 7 | import std; 8 | 9 | auto exactchunks(R,E=typeof(R.init.front))(R r,int size,E fill=E.init){ 10 | //fancy header makes fill an element the range and optional 11 | //note that types have properities such as .init 12 | //yes the template rabbit hole is deep 13 | return ??? 14 | } 15 | 16 | unittest{ 17 | [1,2,3].exactchunks(2).writeln;//[[1, 2], [3, 0]] 18 | "abcdefg".exactchunks(5,'x').writeln;//[abcde, fgxxx] 19 | foreach(i;1..10){ 20 | int j=uniform(2,17); 21 | iota(uniform(50,999)).exactchunks(j) 22 | .each!(a=>assert(a.length==j)); 23 | } 24 | } -------------------------------------------------------------------------------- /.dev/intendedsolutions/example5.d: -------------------------------------------------------------------------------- 1 | /* 2 | fizzbuzz 3 | 4 | write fizzbuzz from sratch just to see if your paying attension 5 | I suggest you reread the previsous examples to get the syntax down 6 | 7 | output 8 | 1-100 fizzbuzz 9 | %3 fizz 10 | %5 buzz 11 | */ 12 | 13 | import std; 14 | 15 | string tostring(int i){ 16 | return i.to!string;//we will get to whats happening here soon 17 | } 18 | 19 | //--- 20 | 21 | string fizzbuzz(int i){ 22 | if(i%15==0){ 23 | return "fizzbuzz"; 24 | } 25 | if(i%5==0){ 26 | return "buzz"; 27 | } 28 | if(i%3==0){ 29 | return "fizz"; 30 | } 31 | return i.tostring;//treat "to!" as a magic function for now 32 | } 33 | 34 | void main(){ 35 | foreach(i;1..100+1){ 36 | i.fizzbuzz.writeln; 37 | }} -------------------------------------------------------------------------------- /source/example23.d: -------------------------------------------------------------------------------- 1 | /* 2 | Templates as generics 3 | 4 | Templates are a whole mess, and will be covered slowly, but you have to start somewhere 5 | 6 | `T` will be used as an anonous type everywhere(followed by S...) 7 | 8 | The following are generic functions, where the function arguments will be infered 9 | 10 | */ 11 | 12 | T lerp(T)(T a,T b,float p){// https://www.youtube.com/watch?v=YJB1QnEmlTs 13 | return a*p+b*(1-p); 14 | } 15 | unittest{ 16 | assert(lerp(0,100,.50)==); 17 | assert(lerp(0.25,.50,.3)==); 18 | assert(lerp('a','z',.5)==); 19 | } 20 | 21 | T clamp(???)(???){ 22 | if(amax){return max;} 24 | return a; 25 | } 26 | unittest{ 27 | assert(0.clamp(1,10)==1); 28 | assert('c'.clamp('a','z')=='c'); 29 | } -------------------------------------------------------------------------------- /.dev/intendedsolutions/example23.d: -------------------------------------------------------------------------------- 1 | /* 2 | Templates as generics 3 | 4 | Templates are a whole mess, and will be covered slowly, but you have to start somewhere 5 | 6 | `T` will be used as an anonous type everywhere(followed by S,U...) 7 | 8 | The following are generic functions, where the function arguments will be infered 9 | 10 | */ 11 | 12 | T lerp(T)(T a,T b,float p){// https://www.youtube.com/watch?v=YJB1QnEmlTs 13 | return a*p+b*(1-p); 14 | } 15 | unittest{ 16 | assert(lerp(0,100,.50)==); 17 | assert(lerp(0.25,.50,.3)==); 18 | assert(lerp('a','z',.5)==); 19 | } 20 | 21 | T clamp(???)(???){ 22 | if(amax){return max;} 24 | return a; 25 | } 26 | unittest{ 27 | assert(0.clamp(1,10)==1); 28 | assert('c'.clamp('a','z')=='c'); 29 | } -------------------------------------------------------------------------------- /.dev/intendedsolutions/example6.d: -------------------------------------------------------------------------------- 1 | /* 2 | Structs, they group data together with names 3 | 4 | in d they can be consturucted by writing `mystructname("my structs args",1)` 5 | varibles are accessed with a `.` 6 | 7 | output: 8 | generate 0..5 myints and print them out with thier i 9 | 10 | geratate vec2s for a 5 by 5 area and print out thier x and y 11 | */ 12 | import std; 13 | 14 | struct myint{ 15 | int i; 16 | } 17 | struct vec2{ 18 | int x; 19 | int y; 20 | } 21 | 22 | void main(){ 23 | foreach(j;0..5){ 24 | myint foo=myint(j); 25 | writeln( 26 | foo, " : ", 27 | foo.i, 28 | ); 29 | } 30 | foreach(a;0..5){ 31 | foreach(b;0..5){ 32 | vec2 foo=vec2(a,b); 33 | writeln( 34 | foo, " : ", 35 | foo.x, ",", 36 | foo.y 37 | ); 38 | }} 39 | } -------------------------------------------------------------------------------- /.dev/intendedsolutions/example34.d: -------------------------------------------------------------------------------- 1 | /* 2 | Exact chunks 3 | 4 | return range of ranges that are of fixed size `n`, BUT if final chunk is less then `n`, 5 | add extra elements `fill` 6 | */ 7 | import std; 8 | 9 | auto exactchunks(R,E=typeof(R.init.front))(R r,int size,E fill=E.init){ 10 | //fancy header makes fill an element the range and optional 11 | //note that types have properities such as .init 12 | //yes the template rabbit hole is deep 13 | return r.chunks(size).map!(a=>a.padRight(fill,size)); 14 | } 15 | 16 | unittest{ 17 | [1,2,3].exactchunks(2).writeln;//[[1, 2], [3, 0]] 18 | "abcdefg".exactchunks(5,'x').writeln;//[abcde, fgxxx] 19 | foreach(i;1..10){ 20 | int j=uniform(2,17); 21 | iota(uniform(50,999)).exactchunks(j) 22 | .each!(a=>assert(a.length==j)); 23 | } 24 | } -------------------------------------------------------------------------------- /source/example3.d: -------------------------------------------------------------------------------- 1 | /* 2 | control flow 3 | 4 | I'm assuming you know what switch and if statements are. 5 | goto teleports the program to the stated lable. 6 | 7 | note: d is picky about switch statements and gotos, 8 | switches must either be marked final or have a default case, 9 | gotos must be in same function and can not skip init-ing a var 10 | 11 | output: 12 | print even, then odd, repeat 5 times 13 | */ 14 | 15 | import std; 16 | void main(){ 17 | int i;//makes a var i, this will start at 0 18 | loop: 19 | switch(i%2){// % is the modulous/"reminder" operator 20 | case 0: 21 | "even".writeln; 22 | break; 23 | case 1: 24 | 25 | break; 26 | default: 27 | "2 ?!??!?!".writeln; 28 | } 29 | if(i<10){ 30 | i++;//adds 1 to i 31 | goto loop; 32 | } 33 | } -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | ## Dingbats (Alpha 2) 2 | 3 | A collection of simple and short exercises to help you learn D. 4 | 5 | ## Getting Started 6 | 7 | First, you should install the DMD compiler before you start solving the exercises. 8 | You can get it by visiting https://dlang.org. 9 | After you have successfully installed DMD, run the following commands: 10 | 11 | ``` 12 | git clone https://github.com/crazymonkyyy/dingbats.git 13 | cd dingbats 14 | rdmd dingbats.d 15 | ``` 16 | 17 | Now you are ready to start solving the exercises. 18 | You can begin by editing the example1.d file inside the examples folder. 19 | 20 | ## Status 21 | 22 | Currently alpha, but has 36 examples 23 | 24 | upto ranges but not yet into the meat of meta programming 25 | 26 | ## Contributing 27 | 28 | see .dev/CONTRIBUTING.md 29 | -------------------------------------------------------------------------------- /.dev/intendedsolutions/example3.d: -------------------------------------------------------------------------------- 1 | /* 2 | control flow 3 | 4 | I'm assuming you know what switch and if statements are. 5 | goto teleports the program to the stated lable. 6 | 7 | note: d is picky about switch statements and gotos, 8 | switches must either be marked final or have a default case, 9 | gotos must be in same function and can not skip init-ing a var 10 | 11 | output: 12 | print even, then odd, repeat 5 times 13 | */ 14 | 15 | import std; 16 | void main(){ 17 | int i;//makes a var i, this will start at 0 18 | loop: 19 | switch(i%2){// % is the modulous/"reminder" operator 20 | case 0: 21 | "even".writeln; 22 | break; 23 | case 1: 24 | "odd".writeln; 25 | break; 26 | default: 27 | "2 ?!??!?!".writeln; 28 | } 29 | if(i<10){ 30 | i++;//adds 1 to i 31 | goto loop; 32 | } 33 | } -------------------------------------------------------------------------------- /source/example16.d: -------------------------------------------------------------------------------- 1 | /* 2 | min and max 3 | 4 | http://phobos.dpldocs.info/std.algorithm.comparison.min.2.html 5 | 6 | 7 | output: 8 | given the two arrays compare each element 9 | then compare the whole arrays 10 | //todo wording 11 | */ 12 | 13 | import std.algorithm;//for reasons no one understands, its not in math *grumble grumble* 14 | import std.stdio; 15 | void main(){ 16 | int[] array1=[1,2,3,4,5]; 17 | int[] array2=[3,-5,7,10,0]; 18 | foreach(i;0..5){ 19 | "element ".writeln(i,": "); 20 | min(array1[i],array2[i]).writeln(" is min"); 21 | ???(array1[i],array2[i]).writeln(" is max"); 22 | } 23 | "---".writeln; 24 | array1.minElement.writeln(" is min of array1"); 25 | array1.??????????.writeln(" is max of array1"); 26 | ??????.minElement.writeln(" is min of array2"); 27 | array2.maxElement.writeln(" is max of array2"); 28 | } -------------------------------------------------------------------------------- /.dev/intendedsolutions/example16.d: -------------------------------------------------------------------------------- 1 | /* 2 | min and max 3 | 4 | http://phobos.dpldocs.info/std.algorithm.comparison.min.2.html 5 | 6 | 7 | output: 8 | given the two arrays compare each element 9 | then compare the whole arrays 10 | //todo wording 11 | */ 12 | 13 | import std.algorithm;//for reasons no one understands, its not in math *grumble grumble* 14 | import std.stdio; 15 | void main(){ 16 | int[] array1=[1,2,3,4,5]; 17 | int[] array2=[3,-5,7,10,0]; 18 | foreach(i;0..5){ 19 | "element ".writeln(i,": "); 20 | min(array1[i],array2[i]).writeln(" is min"); 21 | max(array1[i],array2[i]).writeln(" is max"); 22 | } 23 | "---".writeln; 24 | array1.minElement.writeln(" is min of array1"); 25 | array1.maxElement.writeln(" is max of array1"); 26 | array2.minElement.writeln(" is min of array2"); 27 | array2.maxElement.writeln(" is max of array2"); 28 | } -------------------------------------------------------------------------------- /source/example26.d: -------------------------------------------------------------------------------- 1 | /* 2 | Ranges 1 3 | 4 | Ranges are d's itorator concept, which is to say the list of functions you impliment 5 | to make a data structure that works with other poeples code 6 | 7 | Theres allot of complexity with the formal interface but ignore it, everyone else does :D 8 | ducktype and memorize these functions: 9 | 10 | front - return an element 11 | popFront - shorten the list by 1 12 | empty - is the list empty 13 | 14 | */ 15 | import std; 16 | struct counter{ 17 | int front;//yes this is legal 18 | int end; 19 | void popFront(){ 20 | front++; 21 | } 22 | bool empty(){ 23 | return front>=end; 24 | } 25 | } 26 | 27 | unittest{ 28 | int[10] array; 29 | foreach(int i,ref e;array){ 30 | e=i; 31 | } 32 | array.writeln; 33 | foreach(e;???){//by defining a range you can pass it to foreach 34 | assert(array[e]==e); 35 | } 36 | } -------------------------------------------------------------------------------- /source/example31.d: -------------------------------------------------------------------------------- 1 | /* 2 | map, reduce, filter 3 | 4 | The bread and butter of ranges 5 | 6 | map!F will intercept each call to front to apply F 7 | reduce!F, F is some function that take 2 elements and returns 1(such as addition), 8 | reduce continously applies the function until only one element remains 9 | filter!F, return elements where F is true 10 | 11 | F can be a fuction, a "lamda" (a=>a), or a string 12 | 13 | .array is a common hack to turn a range into a well behaving array; note its expensive 14 | */ 15 | import std; 16 | 17 | 18 | unittest{ 19 | int[] foo=[1,2,3,4,5]; 20 | int square(int i){ 21 | return i*i; 22 | } 23 | assert(???==[1,4,9,16,25]); 24 | enum str="a+b"; 25 | assert(???==15); 26 | assert(???==[1,3,5]); 27 | 28 | 29 | // filter out even numbers, square the results then return a sum 30 | assert(0/*foo.filter.map.reduce*/==35); 31 | } -------------------------------------------------------------------------------- /.dev/intendedsolutions/example26.d: -------------------------------------------------------------------------------- 1 | /* 2 | Ranges 1 3 | 4 | Ranges are d's itorator concept, which is to say the list of functions you impliment 5 | to make a data structure that works with other poeples code 6 | 7 | Theres allot of complexity with the formal interface but ignore it, everyone else does :D 8 | ducktype and memorize these functions: 9 | 10 | front - return an element 11 | popFront - shorten the list by 1 12 | empty - is the list empty 13 | 14 | */ 15 | import std; 16 | struct counter{ 17 | int front;//yes this is legal 18 | int end; 19 | void popFront(){ 20 | front++; 21 | } 22 | bool empty(){ 23 | return front>=end; 24 | } 25 | } 26 | 27 | unittest{ 28 | int[10] array; 29 | foreach(int i,ref e;array){ 30 | e=i; 31 | } 32 | array.writeln; 33 | foreach(e;counter(0,10)){//by defining a range you can pass it to foreach 34 | assert(array[e]==e); 35 | } 36 | } -------------------------------------------------------------------------------- /source/example4.d: -------------------------------------------------------------------------------- 1 | /* 2 | functions 3 | 4 | function syntax(to start with, theres allot of optional complexity) is 5 | returntype functionname(args){ body } 6 | 7 | theres ... at least a dozen different features related to functions, but 8 | to start with theres "utfs" where function calls can be rewritten from 9 | foo(bar) to bar.foo(sometimes, I complain allot about the edge cases); 10 | this will be used consitently 11 | 12 | please finish this fizzbuzz function and take note of how its used "chained" 13 | 14 | output: 15 | 1-20 fizzbuzz 16 | */ 17 | import std; 18 | string fizzbuzz(int i){ 19 | //15 case? 20 | if(i%5==0){ 21 | return "buzz"; 22 | } 23 | if(i%3==0){ 24 | return "fizz"; 25 | } 26 | return i.to!string;//treat "to!" as a magic function for now 27 | } 28 | void main(){//naturally main is just a function 29 | foreach(i;1..20+1){ 30 | i.fizzbuzz.writeln;//look at this syntax sugar it will be on the test 31 | } 32 | } -------------------------------------------------------------------------------- /.dev/intendedsolutions/example31.d: -------------------------------------------------------------------------------- 1 | /* 2 | map, reduce, filter 3 | 4 | The bread and butter of ranges 5 | 6 | map!F will intercept each call to front to apply F 7 | reduce!F, F is some function that take 2 elements and returns 1(such as addition), 8 | reduce continously applies the function until only one element remains 9 | filter!F, return elements where F is true 10 | 11 | F can be a fuction, a "lamda" (a=>a), or a string 12 | 13 | .array is a common hack to turn a range into a well behaving array; note its expensive 14 | */ 15 | import std; 16 | 17 | 18 | unittest{ 19 | int[] foo=[1,2,3,4,5]; 20 | int square(int i){ 21 | return i*i; 22 | } 23 | assert(foo.map!square.array==[1,4,9,16,25]); 24 | enum str="a+b"; 25 | assert(foo.reduce!str==15); 26 | assert(foo.filter!(a=>a%2).array==[1,3,5]); 27 | 28 | 29 | // filter out even numbers, square the results then return a sum 30 | assert(foo.filter!(a=>a%2).map!square.reduce!str==35); 31 | } -------------------------------------------------------------------------------- /source/example30.d: -------------------------------------------------------------------------------- 1 | /* 2 | start of functional-ish programming 3 | 4 | finish the "coin change" algorthim using slices and recursion 5 | given a ammount of money(in penneys) return a list of coins 6 | that sum to that amount perfering larger coins(just be greedy) 7 | */ 8 | 9 | int front(int[] a){ 10 | return a[0]; 11 | } 12 | int[] pop(int[] a){ 13 | return a[1..$]; 14 | } 15 | bool empty(int[] a){ 16 | return a.length==0; 17 | } 18 | 19 | int[] findchange(int i){ 20 | int[] americancoins=[100,25,10,5,1]; 21 | int[] calc(int left,int[] coins,int[] acc){ 22 | if(left==0){return acc;} 23 | if(lefta).array/*hacks cause strings are so misbehaved*/.verify); 59 | assert( ! [1,2,3,1,2,3,1,2,3].verify,"you should fail here"); 60 | assert(testspassed==101,"please run 100 tests"); 61 | } 62 | -------------------------------------------------------------------------------- /.dev/intendedsolutions/example35.d: -------------------------------------------------------------------------------- 1 | /* 2 | find spilt 3 | 4 | given an range that is nearly sorted/rotated(such as a concat of 2 sorted arrays) 5 | find the index where the sort isnt mantained, if sorted return -1 6 | 7 | help write the "fuzzing" unittests 8 | */ 9 | import std; 10 | 11 | void randomincrease(T)(ref T a,T b){ 12 | a=uniform!"(]"(a,b); 13 | } 14 | 15 | T[] randomsortedarray(T)(T min,T max){ 16 | struct myrange{ 17 | T front; 18 | T end; 19 | void popFront(){ 20 | randomincrease(front,end); 21 | } 22 | bool empty(){ 23 | return front==end; 24 | } 25 | } 26 | return myrange(min,max).array; 27 | } 28 | 29 | unittest{ 30 | randomsortedarray(0,10).writeln; 31 | foreach(i;0..10){ 32 | assert(randomsortedarray(0,10).isSorted); 33 | } 34 | randomsortedarray('a','z').writeln; 35 | } 36 | 37 | int findspilt(R)(R r){ 38 | foreach(i,e;r.slide(2).enumerate){ 39 | if(e[0]>e[1]){ 40 | return cast(int)i+1; 41 | } 42 | } 43 | return -1; 44 | } 45 | unittest{ 46 | assert(randomsortedarray(0,100).findspilt==-1); 47 | assert([1,2,3].findspilt==-1); 48 | assert([1,2,3,1,2,3].findspilt==3); 49 | assert(iota(0,10).findspilt==-1); 50 | assert(chain(iota(0,3),iota(0,3)).findspilt==3); 51 | } 52 | int testspassed=0; 53 | bool verify(R)(R r){ 54 | R copy=r; 55 | int spilt=r.findspilt; 56 | r=copy; 57 | bool pass=r.take(spilt).isSorted; 58 | r=copy; 59 | pass&=r.drop(spilt).isSorted; 60 | if(pass){ 61 | testspassed++; 62 | } 63 | return pass; 64 | } 65 | unittest{ 66 | foreach(i;0..100){ 67 | assert((randomsortedarray(0,100)~randomsortedarray(0,100)).verify); 68 | } 69 | assert("abcabc".map!(a=>a).array/*ugly hacks cause strings are so misbehaved*/.verify); 70 | assert( ! [1,2,3,1,2,3,1,2,3].verify,"you should fail here"); 71 | assert(testspassed==101,"please run 100 tests"); 72 | } 73 | -------------------------------------------------------------------------------- /.dev/unorginizedcode/dsyntaxcheatsheet.md: -------------------------------------------------------------------------------- 1 | ### hello world 2 | ```d 3 | import std; 4 | void main(string[] s){ // main that takes command line agruments s[1] will be the first arg 5 | string hello="hello ";// basic var initialisation 6 | hello~=s[1]; // same as hello = hello ~ s[1] 7 | hello.writeln; // same as writeln(hello) 8 | } 9 | ``` 10 | ### switch 11 | ```d 12 | switch(i){ 13 | case 1: 14 | break; 15 | default: assert(0); // there must be a default and asserts must be true 16 | } 17 | ``` 18 | ### ranges 19 | ``` 20 | E front() 21 | void popFront() 22 | bool empty 23 | //todo bidirectional and random access 24 | ``` 25 | ### types 26 | ``` 27 | bool, byte, ushort, int, ulong 28 | alias size_t=ulong; 29 | float, double 30 | char, dchar 31 | alias string=char[]; 32 | [] //slice,dynmatic array 33 | int[5][3]// 3x5 ints 34 | int[string] // ints indexed by strings, "aa arrays" 35 | std.meta.AliasSeq!(int,float) //list of types 36 | std.typecons.tuple(1,"foo") //anonous group of data 37 | alias T=int //type "assignment" 38 | ``` 39 | ### sugartastic syntax 40 | 41 | ```d 42 | auto foo(){//auto infers the type 43 | struct bar{int i;}//local struct, "voldemort type" 44 | return bar(1);//defualt type constuction 45 | } 46 | void main(){ 47 | auto foobar=foo;//auto infering the return; 48 | typeof(foobar)[5] fivebars;//typeof returns the type of an expression 49 | fivebars[3]=foo; 50 | } 51 | ``` 52 | ```d 53 | struct vec2{int x;int y} 54 | vec2 foo; 55 | with(foo){//in this block of code foo.$unknowsymbol will be attempted 56 | x=1; 57 | y=2; 58 | } 59 | ``` 60 | ### op overloads 61 | //todo 62 | 63 | ### function headers 64 | ``` 65 | foo(int i)(int j)//foo!1(2) will get an compile time i=1 and a runtime j=2 66 | foo(T)() //foo!int will get an alias T=int 67 | foo(int 68 | .... //todo 69 | ``` 70 | ### compiler flags 71 | -i -unittest -run -main -j 72 | ### compile time syntax 73 | 74 | ### other control flow 75 | ?: 76 | while do 77 | goto lables 78 | ### imports 79 | explaination of the file hierachy import uses 80 | 81 | ### is and __trait 82 | compiles, check a type, idk ask someone who claims to understand is -------------------------------------------------------------------------------- /.target/7: -------------------------------------------------------------------------------- 1 | nullableint(0, true) : true,0 2 | nullableint(1, false) : false,1 3 | nullableint(2, false) : false,2 4 | nullableint(3, true) : true,3 5 | nullableint(4, false) : false,4 6 | nullableint(5, false) : false,5 7 | nullableint(6, true) : true,6 8 | nullableint(7, false) : false,7 9 | nullableint(8, false) : false,8 10 | nullableint(9, true) : true,9 11 | nullableint(10, false) : false,10 12 | nullableint(11, false) : false,11 13 | nullableint(12, true) : true,12 14 | nullableint(13, false) : false,13 15 | nullableint(14, false) : false,14 16 | nullableint(15, true) : true,15 17 | nullableint(16, false) : false,16 18 | nullableint(17, false) : false,17 19 | nullableint(18, true) : true,18 20 | nullableint(19, false) : false,19 21 | nullableint(20, false) : false,20 22 | nullableint(21, true) : true,21 23 | nullableint(22, false) : false,22 24 | nullableint(23, false) : false,23 25 | nullableint(24, true) : true,24 26 | nullableint(25, false) : false,25 27 | nullableint(26, false) : false,26 28 | nullableint(27, true) : true,27 29 | nullableint(28, false) : false,28 30 | nullableint(29, false) : false,29 31 | nullableint(30, true) : true,30 32 | nullableint(31, false) : false,31 33 | nullableint(32, false) : false,32 34 | nullableint(33, true) : true,33 35 | nullableint(34, false) : false,34 36 | nullableint(35, false) : false,35 37 | nullableint(36, true) : true,36 38 | nullableint(37, false) : false,37 39 | nullableint(38, false) : false,38 40 | nullableint(39, true) : true,39 41 | nullableint(40, false) : false,40 42 | nullableint(41, false) : false,41 43 | nullableint(42, true) : true,42 44 | nullableint(43, false) : false,43 45 | nullableint(44, false) : false,44 46 | nullableint(45, true) : true,45 47 | nullableint(46, false) : false,46 48 | nullableint(47, false) : false,47 49 | nullableint(48, true) : true,48 50 | nullableint(49, false) : false,49 51 | nullableint(50, false) : false,50 52 | nullableint(51, true) : true,51 53 | nullableint(52, false) : false,52 54 | nullableint(53, false) : false,53 55 | nullableint(54, true) : true,54 56 | nullableint(55, false) : false,55 57 | nullableint(56, false) : false,56 58 | nullableint(57, true) : true,57 59 | nullableint(58, false) : false,58 60 | nullableint(59, false) : false,59 61 | nullableint(60, true) : true,60 62 | nullableint(61, false) : false,61 63 | nullableint(62, false) : false,62 64 | nullableint(63, true) : true,63 65 | nullableint(64, false) : false,64 66 | nullableint(65, false) : false,65 67 | nullableint(66, true) : true,66 68 | nullableint(67, false) : false,67 69 | nullableint(68, false) : false,68 70 | nullableint(69, true) : true,69 71 | nullableint(70, false) : false,70 72 | nullableint(71, false) : false,71 73 | nullableint(72, true) : true,72 74 | nullableint(73, false) : false,73 75 | nullableint(74, false) : false,74 76 | nullableint(75, true) : true,75 77 | nullableint(76, false) : false,76 78 | nullableint(77, false) : false,77 79 | nullableint(78, true) : true,78 80 | nullableint(79, false) : false,79 81 | nullableint(80, false) : false,80 82 | nullableint(81, true) : true,81 83 | nullableint(82, false) : false,82 84 | nullableint(83, false) : false,83 85 | nullableint(84, true) : true,84 86 | nullableint(85, false) : false,85 87 | nullableint(86, false) : false,86 88 | nullableint(87, true) : true,87 89 | nullableint(88, false) : false,88 90 | nullableint(89, false) : false,89 91 | nullableint(90, true) : true,90 92 | nullableint(91, false) : false,91 93 | nullableint(92, false) : false,92 94 | nullableint(93, true) : true,93 95 | nullableint(94, false) : false,94 96 | nullableint(95, false) : false,95 97 | nullableint(96, true) : true,96 98 | nullableint(97, false) : false,97 99 | nullableint(98, false) : false,98 100 | nullableint(99, true) : true,99 101 | --------------------------------------------------------------------------------