From 9ae08339c0e7a1bdd37d724fc4f909a5b69a7586 Mon Sep 17 00:00:00 2001 From: Daniel Siepmann Date: Tue, 26 Mar 2024 06:42:08 +0100 Subject: [PATCH] Switch to nix provided exercism Nixpkgs already provides exercism in latest version Add one on top level to get started with new languages. --- c/shell.nix | 2 +- exercism.nix | 25 ------------------------- go/shell.nix | 2 +- lua/shell.nix | 2 +- python/shell.nix | 2 +- python/triangle/triangle.py | 27 +++++++++++++++++++++++---- rust/shell.nix | 2 +- shell.nix | 10 ++++++++++ 8 files changed, 38 insertions(+), 34 deletions(-) delete mode 100644 exercism.nix create mode 100644 shell.nix diff --git a/c/shell.nix b/c/shell.nix index 5f4c717..6b31203 100644 --- a/c/shell.nix +++ b/c/shell.nix @@ -6,6 +6,6 @@ pkgs.mkShellNoCC { name = "exercism"; buildInputs = [ pkgs.coreutils - (pkgs.callPackage ../exercism.nix { }) + pkgs.exercism ]; } diff --git a/exercism.nix b/exercism.nix deleted file mode 100644 index 2308494..0000000 --- a/exercism.nix +++ /dev/null @@ -1,25 +0,0 @@ -{ - buildGoModule - , fetchFromGitHub - , lib -}: - -buildGoModule rec { - pname = "exercism"; - version = "3.3.0"; - src = fetchFromGitHub { - owner = "exercism"; - repo = "cli"; - rev = "v${version}"; - sha256 = "Mtb5c1/k8kp7bETOSE0X969BV176jpoprr1/mQ3E4Vg="; - }; - - vendorHash = "sha256-fnsSvbuVGRAndU88su2Ck7mV8QBDhxozdmwI3XGtxcA="; - - meta = with lib; { - homepage = "https://github.com/exercism/cli"; - description = "Command line interface for exercism website"; - license = licenses.mit; - platforms = platforms.linux; - }; -} diff --git a/go/shell.nix b/go/shell.nix index 277cbcf..6bdb0ef 100644 --- a/go/shell.nix +++ b/go/shell.nix @@ -6,6 +6,6 @@ pkgs.mkShellNoCC { name = "exercism"; buildInputs = [ pkgs.go - (pkgs.callPackage ../exercism.nix { }) + pkgs.exercism ]; } diff --git a/lua/shell.nix b/lua/shell.nix index 7359cb2..f2afe5c 100644 --- a/lua/shell.nix +++ b/lua/shell.nix @@ -6,6 +6,6 @@ pkgs.mkShellNoCC { name = "exercism"; buildInputs = [ (pkgs.lua.withPackages(ps: with ps; [ busted])) - (pkgs.callPackage ../exercism.nix { }) + pkgs.exercism ]; } diff --git a/python/shell.nix b/python/shell.nix index c2ab4ef..b01e3f5 100644 --- a/python/shell.nix +++ b/python/shell.nix @@ -6,6 +6,6 @@ pkgs.mkShellNoCC { name = "exercism"; buildInputs = [ (pkgs.python311.withPackages(ps: with ps; [ pytest ])) - (pkgs.callPackage ../exercism.nix { }) + pkgs.exercism ]; } diff --git a/python/triangle/triangle.py b/python/triangle/triangle.py index 3d088c7..b267d8b 100644 --- a/python/triangle/triangle.py +++ b/python/triangle/triangle.py @@ -1,10 +1,29 @@ -def equilateral(sides): - pass +def is_triangle(sides): + for side in sides: + if side <= 0: + return False + if sides[0] + sides[1] >= sides[2]: + return True + if sides[1] + sides[2] >= sides[0]: + return True + if sides[0] + sides[2] >= sides[1]: + return True + +def equilateral(sides): + if not is_triangle(sides): + return False + + return sides[0] == sides[1] == sides[2] def isosceles(sides): - pass + if not is_triangle(sides): + return false + return sides[0] == sides[1] or sides[0] == sides[2] or sides[1] == sides[2] def scalene(sides): - pass + if not is_triangle(sides): + return false + + return sides[0] != sides[1] and sides[0] != sides[2] and sides[1] != sides[2] diff --git a/rust/shell.nix b/rust/shell.nix index cda9e24..236c9b9 100644 --- a/rust/shell.nix +++ b/rust/shell.nix @@ -9,6 +9,6 @@ pkgs.mkShellNoCC { pkgs.rustc pkgs.cargo - (pkgs.callPackage ../exercism.nix { }) + pkgs.exercism ]; } diff --git a/shell.nix b/shell.nix new file mode 100644 index 0000000..b57531c --- /dev/null +++ b/shell.nix @@ -0,0 +1,10 @@ +{ + pkgs ? import { } +}: + +pkgs.mkShellNoCC { + name = "exercism"; + buildInputs = [ + pkgs.exercism + ]; +}