Daily Programming Challenge:

Programming (no configs, no support)
Forum rules
Only original work ;)
User avatar
GekkoP
Emacs Sancho Panza
Posts: 5878
Joined: Tue Sep 03, 2013 7:05 am

Re: Daily Programming Challenge:

Unread post by GekkoP » Tue Dec 09, 2014 4:50 pm

Code: Select all

(def conan (atom {:power 89 :health 100 :magic 12}))
(:power @conan)
(:health @conan)
(:magic @conan)

(defn flask-of-badassity [a]
  (let [p (:power @a)]
    (swap! a assoc :power (inc p))))
Result:

Code: Select all

user> (flask-of-badassity conan)
{:magic 12, :power 90, :health 100}

User avatar
rhowaldt
Dog
Posts: 4565
Joined: Wed Oct 17, 2012 9:01 am
Contact:

Re: Daily Programming Challenge:

Unread post by rhowaldt » Tue Dec 09, 2014 7:34 pm

okay, i was looking at this last one and thought "i can do that", so i did, in beautiful bash.

Code: Select all

#!/bin/bash

declare -A conan=( [strength]=11 [sexyness]=8 [unicorn]=0 )

function flask {
   echo "Conan has acquired the Flask of Badassity!"
   conan[unicorn]=1
   echo "Conan now has a unicorn!"
   echo
   echo "This is Conan now:"
   echo
   for c in "${!conan[@]}"; do
      echo "$c : ${conan[$c]}"
   done
}

if [ "$1" == "flask" ]; then
   flask
fi
result

Code: Select all

[19:32:07]$ conan flask
Conan has acquired the Flask of Badassity!
Conan now has a unicorn!

This is Conan now:

unicorn : 1
sexyness : 8
strength : 11
All statements are true in some sense, false in some sense, meaningless in some sense, true and false in some sense, true and meaningless in some sense, false and meaningless in some sense, and true and false and meaningless in some sense.

User avatar
wuxmedia
Grasshopper
Posts: 6454
Joined: Wed Oct 17, 2012 11:32 am
Location: Back in Blighty
Contact:

Re: Daily Programming Challenge:

Unread post by wuxmedia » Tue Dec 09, 2014 9:25 pm

^ now I feel really lazy/stupid... 8)
"Seek, and Ye shall find"
"Github | Chooons | Site"

User avatar
stark
MILF
Posts: 521
Joined: Sat Sep 27, 2014 6:38 pm
Location: Arpanet
Contact:

Re: Daily Programming Challenge:

Unread post by stark » Tue Dec 09, 2014 9:41 pm

^ me too the whole 'data-structure' got me all shaky.
If you can do it go ahead and do it, if you can't do it then don't even criticize it. - gingerdesu

User avatar
rhowaldt
Dog
Posts: 4565
Joined: Wed Oct 17, 2012 9:01 am
Contact:

Re: Daily Programming Challenge:

Unread post by rhowaldt » Tue Dec 09, 2014 11:21 pm

looking at DJ and Gekko's examples helped me a lot :)
and because the last time i programmed something was about a year ago, i had to Google each fucking bash-statement except for echo.
oh well... at least it's funny ;)
All statements are true in some sense, false in some sense, meaningless in some sense, true and false in some sense, true and meaningless in some sense, false and meaningless in some sense, and true and false and meaningless in some sense.

User avatar
franksinistra
Ivana Fukalot
Posts: 1093
Joined: Mon Jan 27, 2014 2:03 am
Location: 印尼国

Re: Daily Programming Challenge:

Unread post by franksinistra » Wed Dec 10, 2014 4:45 am

So.... i wanted to use clojure.core/atom, but since Gekko got there first
i'll have to make do using refs

Code: Select all

(defn new-char [id & {:as specific-stats}]
  ;; create new character 
  (ref (merge {:id id :hp (rand-int 1000) :dmg (rand-int 100)} specific-stats)))

(def conan-the-barbie (new-char "Conan The Barbarian" 
                       :manliness 20 
                       :testosterone 16 
                       :beard-length-in-meters 11))

@conan-the-barbie ;; recall stats

(fn flask-of-badassity []
  (dosync
    (alter conan-the-barbie update-in [:manliness] inc)
    (alter conan-the-barbie update-in [:beard-length-in-meters] inc))

rice no more.

User avatar
DebianJoe
Frame Buffer
Posts: 1915
Joined: Mon Jul 01, 2013 5:41 am
Location: emacs.d

Re: Daily Programming Challenge:

Unread post by DebianJoe » Wed Dec 10, 2014 7:12 am

These made me laugh. :)

Today's challenge...take some time to do something cool. I don't care if it's programming or brewing homemade whisky. Tomorrow, we resume full-force, with elevated challenges.
|>>BBQ Roaster, Alpha Branch<< | >> clinky << | >> X11 must die << |
Thanks BASIC

User avatar
rhowaldt
Dog
Posts: 4565
Joined: Wed Oct 17, 2012 9:01 am
Contact:

Re: Daily Programming Challenge:

Unread post by rhowaldt » Wed Dec 10, 2014 2:01 pm

^ does masturbating count?
All statements are true in some sense, false in some sense, meaningless in some sense, true and false in some sense, true and meaningless in some sense, false and meaningless in some sense, and true and false and meaningless in some sense.

User avatar
DebianJoe
Frame Buffer
Posts: 1915
Joined: Mon Jul 01, 2013 5:41 am
Location: emacs.d

Re: Daily Programming Challenge:

Unread post by DebianJoe » Wed Dec 10, 2014 2:45 pm

<.<
>.>
sure.
|>>BBQ Roaster, Alpha Branch<< | >> clinky << | >> X11 must die << |
Thanks BASIC

User avatar
rhowaldt
Dog
Posts: 4565
Joined: Wed Oct 17, 2012 9:01 am
Contact:

Re: Daily Programming Challenge:

Unread post by rhowaldt » Wed Dec 10, 2014 2:49 pm

thanks Joe, another challenge i can compete in! you make me feel so accomplished ;)
All statements are true in some sense, false in some sense, meaningless in some sense, true and false in some sense, true and meaningless in some sense, false and meaningless in some sense, and true and false and meaningless in some sense.

machinebacon
Baconator
Posts: 10253
Joined: Thu Sep 16, 2010 11:03 am
Location: Pfälzerwald
Contact:

Re: Daily Programming Challenge:

Unread post by machinebacon » Wed Dec 10, 2014 4:55 pm

Okay, I got one for you neckbeards:

Anna and Otto ask for an anagram creator. It does not need to create existing words, but write all possible versions of the entered string. (example: anna, nana, anan, aann, nnaa)

Extra beard point: only print those which are existing as expression in the filenames on your system.

Extra I-Love-Pidsley point: use 'time' to show how quick it is ;)
..gnutella..

User avatar
franksinistra
Ivana Fukalot
Posts: 1093
Joined: Mon Jan 27, 2014 2:03 am
Location: 印尼国

Re: Daily Programming Challenge:

Unread post by franksinistra » Thu Dec 11, 2014 3:55 am

first-challenge answer in Clojure:

Code: Select all

(defn juggle-string-from-y [x y]
  ;; juggle the string x from point y  
  (vector
    (get x y)
    (into [] (concat
               (take y x)
               (take-last (dec (- (count x) y)) x)))))

(defn combinate-string [a b]
  ;; put each letter as the first letter in the specified string
  ;; recur it for each letter 
  (cond
   (empty? b) a
   :else (for [[x y] (map (partial juggle-string-from-y b)
                          (range (count b)))]
           (combinate-string (conj a x) y))))

(defn word-combinations [word]
  ;; pass the result of combinate-string function 
  ;; to create plausible versions of the entered string
  (map (fn [w] (apply str w))
       (partition (count word)
                  (flatten (combinate-string [] (vec word))))))
I need an elaborate explanation as to what bacon meant in the extra-beard-point
(honestly i don't get it)


Third-Challenge I-Love-Pidsley:

Image
rice no more.

machinebacon
Baconator
Posts: 10253
Joined: Thu Sep 16, 2010 11:03 am
Location: Pfälzerwald
Contact:

Re: Daily Programming Challenge:

Unread post by machinebacon » Thu Dec 11, 2014 6:01 am

^ perfect.

What I meant is: the results of the anagram function should be checked against all filenames. If a filename with the same name (as one of the results) exists, only this string should be printed out.

Example:
anagram'ed word: act
results: act, cat, atc, tac
which of these are somewhere in the filesystem: cat (in /bin/cat), tac (in /usr/bin/tac)

Clear?
..gnutella..

User avatar
GekkoP
Emacs Sancho Panza
Posts: 5878
Joined: Tue Sep 03, 2013 7:05 am

Re: Daily Programming Challenge:

Unread post by GekkoP » Thu Dec 11, 2014 10:07 am

@frank that's a great solution. Honestly my Clojure needs to get better to come up with a solution like that one.

User avatar
DebianJoe
Frame Buffer
Posts: 1915
Joined: Mon Jul 01, 2013 5:41 am
Location: emacs.d

Re: Daily Programming Challenge:

Unread post by DebianJoe » Thu Dec 11, 2014 10:39 am

*applause Frank*

I refuse to answer this one due to a lack of anime in the challenge post. ^_^
(Actually, just really busy with something else...but really, Frank's answer is very nice.)
|>>BBQ Roaster, Alpha Branch<< | >> clinky << | >> X11 must die << |
Thanks BASIC

User avatar
franksinistra
Ivana Fukalot
Posts: 1093
Joined: Mon Jan 27, 2014 2:03 am
Location: 印尼国

Re: Daily Programming Challenge:

Unread post by franksinistra » Thu Dec 11, 2014 1:57 pm

^^^
clear as day sir bacon!
that's going to be really challenging.....

@Gekko and DJ:
thanks a lot both of you, but i honestly think my solution needs a better logical approach (or extra clojure library. Something like this)
a quick test of running the function with a string longer than 10 characters resulted in GC overflow, and a burning hot cpu temperature :(
rice no more.

User avatar
GekkoP
Emacs Sancho Panza
Posts: 5878
Joined: Tue Sep 03, 2013 7:05 am

Re: Daily Programming Challenge:

Unread post by GekkoP » Thu Dec 11, 2014 2:58 pm

^ maybe lazy-seq could be of any help about that? Or, IIRC, doing the recursion with recur.

User avatar
franksinistra
Ivana Fukalot
Posts: 1093
Joined: Mon Jan 27, 2014 2:03 am
Location: 印尼国

Re: Daily Programming Challenge:

Unread post by franksinistra » Fri Dec 12, 2014 4:35 am

^ lazy-seq will be helpful i think. I hope you'll accomplish what i can't using recur, Gekko!
rice no more.

User avatar
DebianJoe
Frame Buffer
Posts: 1915
Joined: Mon Jul 01, 2013 5:41 am
Location: emacs.d

Re: Daily Programming Challenge:

Unread post by DebianJoe » Sun Dec 14, 2014 9:04 am

I've been trying to wrap my head around the possibilities of an iterative sequence that cycles a list based on how long it is...not done yet, but I've not given up on it. It has to be possible, but it's probably going to be a little bit (read: 'significantly') more lines than anything we've put up here so far.

...the problem is, that I'm stupid, so it takes longer. :D
|>>BBQ Roaster, Alpha Branch<< | >> clinky << | >> X11 must die << |
Thanks BASIC

User avatar
DebianJoe
Frame Buffer
Posts: 1915
Joined: Mon Jul 01, 2013 5:41 am
Location: emacs.d

Re: Daily Programming Challenge:

Unread post by DebianJoe » Mon Dec 15, 2014 9:29 am

Okay, I've yet to make this work in Scheme form, but I've got an idea for a linear logarithmic time algorithm that might actually suit this use well. I will share, and you guys tell me if you see any obvious holes in my thinking. (This is a nasty one to get right and make run quickly, MB...curse you!)

Essentially, we'd need to map the entire alphabet to prime numbers. (a = 2, b = 3, c = 5, d = 7, e = 11)
per http://primes.utm.edu/lists/small/1000.txt.

Now, all words can be added together to create a 'anagram value'. "cab = 10", for instance. I'm pretty sure that only "anagram true" words will have the same value in this case. Now, Machine("I like watching you suffer")Bacon, has asked that we only print results that are somewhere in our system. Instead of having to run a hash on every single possibility of of every word (which will probably be an overflow in Clojure, and an insanely long run time in Chicken)...we can simply determine values of all of the filenames that we wish to check against. As soon as we have a value match, we can be sure that it's an anagram, print its value, and continue down through the file structure. This is not recursive, so while there's a lot of work on the front end, the back end should be very fast.

My (lack of) knowledge of Scheme is what's killing me here, but I'm still working on it.

We would also need to determine if the word to be checked has the same length as our hashed word, as (ab == c) by value alone. This should probably be step 1, and discard the word if it isn't the same length first. Quick check should go first, IMHO.
|>>BBQ Roaster, Alpha Branch<< | >> clinky << | >> X11 must die << |
Thanks BASIC

Post Reply