a thoughtful web.
Good ideas and conversation. No ads, no tracking.   Login or Take a Tour!
comment by wasoxygen
wasoxygen  ·  4032 days ago  ·  link  ·    ·  parent  ·  post: What language(s) are you currently learning?

Thank you very much for this suggestion. I have been wanting to try functional programming for a long time, after seeing so many inscrutable and concise solutions on Project Euler. I never managed to get far with Haskell, though.

In addition to the web version you linked to, Chris Krycho has created a nicely-formatted Kindle version. I am 4% through it and managed to write my first Scheme code for Exercise 1.3: "Define a procedure that takes three numbers as arguments and returns the sum of the squares of the two larger numbers."

  (define (square a) ( * a a))
  (define (sumofsquares a b) (+ (square a) (square b)))
  (define (<= a b) (or (< a b) (= a b)) )
  (define (sosbig2 a b c) 
    (cond 
      ( (and (<= a b) (<= a c)) (sumofsquares b c))
      ( (and (<= b a) (<= b c)) (sumofsquares a c))
      ( (and (<= c a) (<= c b)) (sumofsquares a b))))
I am using a handy online interpreter.

delta, how's your progress coming?





user-inactivated  ·  4032 days ago  ·  link  ·  

Well, I decided I didn't like Scheme's syntax + there aren't many frameworks & libraries that support it.

I'm learning C now, and I like it a lot more. The main reason I'm learning C is that I plan to use OpenWRT for a science fair. Your code above is pretty damn beautiful, though.

I wrote a program yesterday because my sister wanted a program related to flowers. (✿◠‿◠)

  #include <stdio.h>
  main()
  {
    int rose_amt = 12;
    int daisy_amt = 7;
    int tulip_amt = 23;
    int sunflower_amt = 42;
    int rose;
    int daisy;
    int tulip;
    int sunflower;
    int exit_value;

    printf("This program will calculate the grand total number of days\nit will take for four different kinds of flowers to grow.\n\n");
    printf("Roses take %d days to grow.\n", rose_amt);
    printf("Daisies take %d days to grow.\n", daisy_amt);
    printf("Tulips take %d days to grow.\n", tulip_amt);
    printf("Sunflowers take %d days to grow.\n", sunflower_amt);

    printf("\nHow many roses do you wish to plant?\n");
    scanf(" %d", &rose );

    printf("How many daisies do you wish to plant?\n");
    scanf(" %d", &daisy);

    printf("How many tulips do you wish to plant?\n");
    scanf(" %d", &tulip);

    printf("How many sunflowers do you wish to plant?\n");
    scanf(" %d", &sunflower);

    printf("\nIt will take a grand total of %d days for all the flowers to grow.\n", rose*rose_amt+daisy*daisy_amt+tulip*tulip_amt+sunflower*sunflower_amt);
    printf("\nWould you like to exit?\n");
    scanf("%d");
    return 0;
  }