From 8775dec9b972b5df9de24f9beb171656361e1bad Mon Sep 17 00:00:00 2001 From: Abigail Date: Thu, 6 Jan 2022 20:03:30 +0100 Subject: Week 003 & Week 123: Scheme solution for part 1 --- challenge-003/abigail/README.md | 1 + challenge-003/abigail/scheme/ch-1.scm | 43 +++++++++++++++++++++++++++++++++++ challenge-123/abigail/README.md | 1 + challenge-123/abigail/scheme/ch-1.scm | 43 +++++++++++++++++++++++++++++++++++ 4 files changed, 88 insertions(+) create mode 100644 challenge-003/abigail/scheme/ch-1.scm create mode 100644 challenge-123/abigail/scheme/ch-1.scm diff --git a/challenge-003/abigail/README.md b/challenge-003/abigail/README.md index 5a50b02ed5..59a58a6ead 100644 --- a/challenge-003/abigail/README.md +++ b/challenge-003/abigail/README.md @@ -14,6 +14,7 @@ * [Python](python/ch-1.py) * [R](r/ch-1.r) * [Ruby](ruby/ch-1.rb) +* [Scheme](scheme/ch-1.scm) * [Tcl](tcl/ch-1.tcl) diff --git a/challenge-003/abigail/scheme/ch-1.scm b/challenge-003/abigail/scheme/ch-1.scm new file mode 100644 index 0000000000..32a0facf6c --- /dev/null +++ b/challenge-003/abigail/scheme/ch-1.scm @@ -0,0 +1,43 @@ +#!/usr/local/bin/guile +!# + +;;; +;;; See https://theweeklychallenge.org/blog/perl-weekly-challenge-003 +;;; + +;;; +;;; Run as: guile --no-auto-compile ch-1.scm +;;; + + +(use-modules (ice-9 rdelim)) + + +(define (ugly uglylist mx next_2 next_3 next_5) + (define mymin) + (cond ((= mx (length uglylist)) (list-ref uglylist (- mx 1))) + (else + (set! mymin (min (* 2 (list-ref uglylist next_2)) + (* 3 (list-ref uglylist next_3)) + (* 5 (list-ref uglylist next_5)))) + + (ugly (append uglylist (list mymin) ) + mx + (if (<= (* 2 (list-ref uglylist next_2)) mymin) + (+ next_2 1) next_2) + (if (<= (* 3 (list-ref uglylist next_3)) mymin) + (+ next_3 1) next_3) + (if (<= (* 5 (list-ref uglylist next_5)) mymin) + (+ next_5 1) next_5))))) + +(define (main) + (define mx (read-line)) + (if (not (eof-object? mx)) + (begin + (display (ugly (list 1) (string->number mx) 0 0 0))(newline) + (main) + ) + ) +) + +(main) diff --git a/challenge-123/abigail/README.md b/challenge-123/abigail/README.md index a82d00c1a8..465ad169d4 100644 --- a/challenge-123/abigail/README.md +++ b/challenge-123/abigail/README.md @@ -32,6 +32,7 @@ Output: 12 * [Python](python/ch-1.py) * [R](r/ch-1.r) * [Ruby](ruby/ch-1.rb) +* [Scheme](scheme/ch-1.scm) * [Tcl](tcl/ch-1.tcl) ### Blog diff --git a/challenge-123/abigail/scheme/ch-1.scm b/challenge-123/abigail/scheme/ch-1.scm new file mode 100644 index 0000000000..2311efef91 --- /dev/null +++ b/challenge-123/abigail/scheme/ch-1.scm @@ -0,0 +1,43 @@ +#!/usr/local/bin/guile +!# + +;;; +;;; See https://theweeklychallenge.org/blog/perl-weekly-challenge-123 +;;; + +;;; +;;; Run as: guile --no-auto-compile ch-1.scm +;;; + + +(use-modules (ice-9 rdelim)) + + +(define (ugly uglylist mx next_2 next_3 next_5) + (define mymin) + (cond ((= mx (length uglylist)) (list-ref uglylist (- mx 1))) + (else + (set! mymin (min (* 2 (list-ref uglylist next_2)) + (* 3 (list-ref uglylist next_3)) + (* 5 (list-ref uglylist next_5)))) + + (ugly (append uglylist (list mymin) ) + mx + (if (<= (* 2 (list-ref uglylist next_2)) mymin) + (+ next_2 1) next_2) + (if (<= (* 3 (list-ref uglylist next_3)) mymin) + (+ next_3 1) next_3) + (if (<= (* 5 (list-ref uglylist next_5)) mymin) + (+ next_5 1) next_5))))) + +(define (main) + (define mx (read-line)) + (if (not (eof-object? mx)) + (begin + (display (ugly (list 1) (string->number mx) 0 0 0))(newline) + (main) + ) + ) +) + +(main) -- cgit