diff options
| author | Dave Gauer <dave@ratfactor.com> | 2021-02-12 22:30:25 -0500 |
|---|---|---|
| committer | Dave Gauer <dave@ratfactor.com> | 2021-02-12 22:30:25 -0500 |
| commit | a43e7437c04179d96e647200c9e2404cde15a565 (patch) | |
| tree | a1c3fb90e224a5106a79bf9cade4ae02215a3d68 /ziglings | |
| parent | d9b8dfa535e1f8a2f00de8977d00ef09b556f0d9 (diff) | |
| parent | 37cb6a8b16ca90492c9e977460e98f710a129e9c (diff) | |
Merge branch 'SpexGuy-zig-build' into main
Diffstat (limited to 'ziglings')
| -rwxr-xr-x | ziglings | 164 |
1 files changed, 0 insertions, 164 deletions
diff --git a/ziglings b/ziglings deleted file mode 100755 index a5fa8d4..0000000 --- a/ziglings +++ /dev/null @@ -1,164 +0,0 @@ -#!/bin/bash - -# ziglings takes one parameter: the exercise number to jump to -jump_to=${1:-0} - -echo -echo " _ _ _ " -echo " ___(_) __ _| (_)_ __ __ _ ___ " -echo " |_ | |/ _' | | | '_ \ / _' / __| " -echo " / /| | (_| | | | | | | (_| \__ \ " -echo " /___|_|\__, |_|_|_| |_|\__, |___/ " -echo " |___/ |___/ " -echo - -# Capture terminal escape sequences (ANSI) for formatting -fmt_err=$( tput setaf 1 ) # red foreground -fmt_yay=$( tput setaf 2 ) # green foreground -fmt_off=$( tput sgr0 ) # reset colors/effects - -zig_cmd=zig -zig_minimum_version="0 8 0 1065" -zig_version=$($zig_cmd version 2>/dev/null) - -if [[ "$zig_version" =~ ([0-9]+)\.([0-9]+)\.([0-9]+)-dev\.([0-9]+) ]] -then - match_idx=1 # regex matches start at index 1 - - for v in $zig_minimum_version - do - if [[ ${BASH_REMATCH[$match_idx]} -lt $v ]] - then - echo "Your current Zig version is $zig_version." - echo "Please update your zig compiler to a version >=$(echo "${zig_minimum_version// /.}") "` - `"or change \$zig_cmd in ./ziglings to the appropriate path." - exit 1 - fi - match_idx=$((match_idx+1)) - done -elif [[ -z $zig_version ]] -then - echo "Ziglings failed to determine your Zig version." - echo "Please check if \$zig_cmd in ./ziglings matches the zig executable in your PATH." - exit 1 -else - echo "Sorry, Zig version number '${zig_version}' is not in the expected format for a current development build." - exit 1 -fi - -exercise_num=0 - -function check_it { - source_file="exercises/$1" - correct_output=$2 - hint=$3 - - # If the current exercise is less than the requested one, skip it - let exercise_num+=1 - if [[ $exercise_num -lt $jump_to ]] - then - return - fi - - # Compile/run the source and capture the result and exit value - cmd="$zig_cmd run $source_file" - echo "$ $cmd" - result=$($cmd 2>&1) - result_status=$? - - # Echo the result to the screen so user can see what their program does - echo "$result" - if [[ $result_status -ne 0 ]] - then - echo - printf "${fmt_err}Uh oh! Looks like there was an error.${fmt_off}\n" - if [[ ! -z "$hint" ]] - then - echo "$hint" - fi - echo - echo "Edit '$source_file' and run me again." - echo - exit 1 - fi - - # Wildcards to be lenient with anything AROUND the correct output - if [[ "$result" == *"$correct_output"* ]] - then - printf "${fmt_yay}** PASSED **${fmt_off}\n" - else - printf "${fmt_err}It seems to compile, but I wanted to see '$correct_output'.${fmt_off}\n" - if [[ ! -z "$hint" ]] - then - echo "$hint" - fi - echo - exit 1 - fi -} - -# I've chosen to explicitly number AND list each exercise rather than rely -# on sorting. Though it does mean manually renaming things to remove/insert, -# it's worked out well so far. - -check_it 01_hello.zig "Hello world" "Note the error: the source file has a hint for fixing 'main'." -check_it 02_std.zig "Standard Library" -check_it 03_assignment.zig "55 314159 -11" "There are three mistakes in this one!" -check_it 04_arrays.zig "Fourth: 7, Length: 8" "There are two things to complete here." -check_it 05_arrays2.zig "LEET: 1337, Bits: 100110011001" "Fill in the two arrays." -check_it 06_strings.zig "d=d ha ha ha Major Tom" "Each '???' needs something filled in." -check_it 07_strings2.zig "Ziggy" "Please fix the lyrics!" -check_it 08_quiz.zig "Program in Zig" "See if you can fix the program!" -check_it 09_if.zig "Foo is 1!" -check_it 10_if2.zig "price is \$17" -check_it 11_while.zig "n=1024" "You probably want a 'less than' condition." -check_it 12_while2.zig "n=1024" "It might help to look back at the previous exercise." -check_it 13_while3.zig "1 2 4 7 8 11 13 14 16 17 19" -check_it 14_while4.zig "n=4" -check_it 15_for.zig "A Dramatic Story: :-) :-) :-( :-| :-) The End." -check_it 16_for2.zig "13" -check_it 17_quiz2.zig "8, Fizz, Buzz, 11, Fizz, 13, 14, FizzBuzz, 16" "This is a famous game!" -check_it 18_functions.zig "Question: 42" "Can you help write the function?" -check_it 19_functions2.zig "2 4 8 16" -check_it 20_quiz3.zig "32 64 128 256" "Unexpected pop quiz! Help!" -check_it 21_errors.zig "2<4. 3<4. 4=4. 5>4. 6>4." "What's the deal with fours?" -check_it 22_errors2.zig "I compiled" "Get the error union type right to allow this to compile." -check_it 23_errors3.zig "a=64, b=22" -check_it 24_errors4.zig "a=20, b=14, c=10" -check_it 25_errors5.zig "a=0, b=19, c=0" -check_it 26_hello2.zig "Hello world" "Try using a try!" -check_it 27_defer.zig "One Two" -check_it 28_defer2.zig "(Goat) (Cat) (Dog) (Dog) (Goat) (Unknown) done." -check_it 29_errdefer.zig "Getting number...got 5. Getting number...failed!" -check_it 30_switch.zig "ZIG?" -check_it 31_switch2.zig "ZIG!" -check_it 32_unreachable.zig "1 2 3 9 8 7" -check_it 33_iferror.zig "2<4. 3<4. 4=4. 5>4. 6>4." "Seriously, what's the deal with fours?" -check_it 34_quiz4.zig "my_num=42" "Can you make this work?" -check_it 35_enums.zig "1 2 3 9 8 7" "This problem seems familiar..." -check_it 36_enums2.zig "#0000ff" "I'm feeling blue about this." -check_it 37_structs.zig "Your wizard has 90 health and 25 gold." -check_it 38_structs2.zig "Character 2 - G:10 H:100 XP:20" -check_it 39_pointers.zig "num1: 5, num2: 5" "Pointers aren't so bad." -check_it 40_pointers2.zig "a: 12, b: 12" -check_it 41_pointers3.zig "foo=6, bar=11" -check_it 42_pointers4.zig "num: 5, more_nums: 1 1 5 1" -check_it 43_pointers5.zig "Wizard (G:10 H:100 XP:20)" -check_it 44_quiz5.zig "Elephant A. Elephant B. Elephant C." "Oh no! We forgot Elephant B!" -# optional vals (simple scalar) -# optional fields (elephant tail - no longer need circular) -# super-simple struct method -# use struct method for elephant tails -# quiz: add elephant trunk (like tail)! - -echo -echo " __ __ _ " -echo " \ \ / __ _ _ _| | " -echo " \ V / _' | | | | | " -echo " | | (_| | |_| |_| " -echo " |_|\__,_|\__, (_) " -echo " |___/ " -echo -echo "You've completed all of the Ziglings exercises!" -echo " (That have been written so far.)" -echo |
