Ad

Going for style points

Code
Diff
  • int *fanis(char *r,int k) {
        char *w = malloc(0);
        for (int i = 0; r[i]; w[i++] = k + r[i]);
        return w;
    }
    • int*fanis(char*r,int k){char*w=malloc(0);for(int i=0;r[i];w[i++]=k+r[i]);return w;}
    • int *fanis(char *r,int k) {
    • char *w = malloc(0);
    • for (int i = 0; r[i]; w[i++] = k + r[i]);
    • return w;
    • }

Added exhaustive tests; refined solution to the original spec

Code
Diff
  • converter = lambda n: ["zero", "one", "two", "three", "four", "five", "six", "seven", "eight", "nine"][n]
    • exec(bytes('潣癮牥整㵲慬扭慤渠嬺稧牥❯✬湯❥✬睴❯✬桴敲❥✬潦牵Ⱗ昧癩❥✬楳❸✬敳敶❮✬楥桧❴✬楮敮Ⱗ琧湥崧湛⁝','u16')[2:])
    • converter = lambda n: ["zero", "one", "two", "three", "four", "five", "six", "seven", "eight", "nine"][n]

Added a test to break the solution one might call 'Divisible by x * y', with the example of 80 being divisible by 40 and 10 (not 400), and a code solution to reflect this distinction

Code
Diff
  • isDivisible = (n, x, y) => !(n % x || n % y)
    • const isDivisible = (n, x, y) => !(n % (x * y));
    • isDivisible = (n, x, y) => !(n % x || n % y)

Design an algorithm that accepts a positive integer and reverses the order of its digits.

Code
Diff
  • def reverse_int(int)
      int.to_s.reverse.to_i
    end
    • public class Algorithms {
    • public static int reverseInt(int n) {
    • int reversed = 0;
    • while(n != 0){
    • reversed = reversed * 10 + (n % 10);
    • n /= 10;
    • }
    • return reversed;
    • }
    • }
    • def reverse_int(int)
    • int.to_s.reverse.to_i
    • end
Fundamentals
Games
Code
Diff
  • def riddle(w) = /\?/ =~ w
    • def riddle(w)=/\?/=~w
    • def riddle(w) = /\?/ =~ w

As seraph776 pointed out a couple of days ago:

PEP 8

Always surround these binary operators with a single space on either side: assignment (=), augmented assignment (+=, -= etc.), comparisons (==, <, >, !=, <>, <=, >=, in, not in, is, is not), Booleans (and, or, not).

Code
Diff
  • find_max = max
    
    • find_max=max
    • find_max = max
Code
Diff
  • func gradeCalc(_ score: Int) -> String {
        (score < 0 || score > 100) ? "Not a grade" : ["F","F","F","F","F","F","D","C","B","A","A"][score / 10];
    }
    • func gradeCalc(_ score: Int) -> String {
    • do {
    • return try letterGrade(for: score)
    • } catch {
    • return "Not a grade"
    • }
    • }
    • func letterGrade(for score: Int) throws -> String {
    • switch score {
    • case 90...100:
    • return "A"
    • case 80..<90:
    • return "B"
    • case 70..<80:
    • return "C"
    • case 60..<70:
    • return "D"
    • case 0..<60:
    • return "F"
    • default:
    • throw ParameterError.outsideOfValidRange
    • }
    • }
    • enum ParameterError: Error {
    • case outsideOfValidRange
    • }
    • (score < 0 || score > 100) ? "Not a grade" : ["F","F","F","F","F","F","D","C","B","A","A"][score / 10];
    • }
Code
Diff
  • #define _GNU_SOURCE 1
    
    char *Hi() {
        return strdup("Hello World.");
    }
    • #define _GNU_SOURCE 1
    • char *Hi() {
    • char *hello = "Hello World.";
    • return hello;
    • return strdup("Hello World.");
    • }
Code
Diff
  • power = Math.pow
    • const power = (num, exp) => !exp ? 1 : new Array(exp).fill(num).reduce((a , b) => a * b)
    • power = Math.pow
Code
Diff
  • bool Or(bool a, bool b) {
        return a + b;
    }
    bool And(bool a, bool b) {
        return a * b;
    }
    bool Xor(bool a, bool b) {
        return a != b;
    }
    • bool Or(bool a, bool b) {
    • return a+b;
    • return a + b;
    • }
    • bool And(bool a, bool b) {
    • return a*b;
    • return a * b;
    • }
    • bool Xor(bool a, bool b) {
    • return a!=b;
    • return a != b;
    • }
Code
Diff
  • def verify_sum(a,b)
      a.sum == b.sum rescue false
    end
    • def verify_sum(a,b)
    • return false if a.nil? || b.nil?
    • a.sum == b.sum
    • a.sum == b.sum rescue false
    • end
Code
Diff
  • converter = lambda n: ["zero", "one", "two", "three", "four", "five", "six", "seven", "eight", "nine", "ten"][n]
    • converter = lambda n: 'zero one two three four five six seven eight nine ten'.split(' ')[n]
    • converter = lambda n: ["zero", "one", "two", "three", "four", "five", "six", "seven", "eight", "nine", "ten"][n]