Journal #8265

Posted 11 years ago2013-10-10 21:45:05 UTC
Instant Mix Instant MixTitle commitment issues
haskell's a bitch

first time programming , and i'm given tutorial exercises to which I have no idea how to complete. eugh.
Using the function rotate from the previous question, write a function
makeKey :: Int -> [(Char, Char)]
that returns the cipher key with the given offset. See above for the description of how the cipher key is represented as a list of pairs. Example:
Main> makeKey 5 [(’A’,’F’),(’B’,’G’),(’C’,’H’),(’D’,’I’),(’E’,’J’),(’F’,’K’), (’G’,’L’),(’H’,’M’),(’I’,’N’),(’J’,’O’),(’K’,’P’),(’L’,’Q’), (’M’,’R’),(’N’,’S’),(’O’,’T’),(’P’,’U’),(’Q’,’V’),(’R’,’W’), (’S’,’X’),(’T’,’Y’),(’U’,’Z’),(’V’,’A’),(’W’,’B’),(’X’,’C’), (’Y’,’D’),(’Z’,’E’)]
The cipher key should show how to encrypt all of the uppercase English letters, and there should be no duplicates: each letter should appear just once amongst the pairs’ first compo- nents (and just once amongst the second components).
i mean seriously what the hell

8 Comments

Commented 11 years ago2013-10-10 23:45:18 UTC Comment #50941
Wow, you got Haskell as a first-time programming language? That's harsh. Ouch, seriously :P

On the other hand...if you don't give up, you should learn certain concepts much faster :)

I don't know Haskell, but here's a JavaScript solution in case that helps :P

Click for JSFiddle

Edit: Looks like you've already got a rotate function from a previous exercise, with that method the general process would be something like this:

1. Get list of characters from A-Z:
['A'..'Z']

2. You want to create pairs for each item in the list:
('A', rotate 'A' 5)

3. So, you have the list and the method that converts each item in the list into the result you want. This is called a map, or I think the Haskell term is `list comprehension`:
[(x, rotate x 5) | x <- ['A'..'Z']]

4. Put it in a function , change 5 to an input parameter:
makeKey n = [(x, rotate x n) | x <- ['A'..'Z']]

As I said I don't know Haskell so sorry if this is misleading or incorrect! Also I'm not passing your course for you so don't expect me to give you all your answers :P

I'm sure you've already come across this but I hear Learn You A Haskell is a great way to learn the language.
Commented 11 years ago2013-10-11 04:01:59 UTC Comment #50947
I've heard that Haskell is very good for coding AIs but that's about all I know about it.
Commented 11 years ago2013-10-11 05:47:18 UTC Comment #50948
Better start off with something like python.
Commented 11 years ago2013-10-11 08:19:08 UTC Comment #50943
Learn You A Haskell is exactly what i'm reading, and with some thought I actually got to that.

the real issue was I had no idea how to do rotate, to which after some thinking I got

rotate :: Int -> [Char] -> [Char]
rotate a xs | a >= 1 && a <= (length xs) = (drop a xs) ++ (take a xs)
| a < 0 = error "the number is negative JUST LIKE YOUR OUTPUT ON LIFE"
| a > (length xs) = error "your rotation is too large LIKE YOUR MOTHER"
| otherwise = xs
to which I could do

makeKey :: Int -> [(Char, Char)]
makeKey rotateChar = zip ['A'..'Z'] (rotate rotateChar ['A'..'Z'])

there's some other stuff I can't do but I guess that's what these tutorial sessions are for.
Commented 11 years ago2013-10-12 01:52:34 UTC Comment #50945
Never heard of this language! I wish we could upload knowledge like this to our brains, i have no patience/drive to learn coding, yet i would love to know how, good luck! =P
Commented 11 years ago2013-10-12 12:55:35 UTC Comment #50944
well the speel that our tutor was going on about is that Haskell is a functional language, that it's not object oriented. It's also lazy - ie intelligent, it can figure out a lot of things on its own - but an example of this is like zipping ( putting things from a list and another list together to make a list of pairs ) a small list with an infinite list. Any other language would have to compute the infinite list before zipping it to a small one, whereas haskell will only compute it to the point it needs to.

It's also apparently becoming more prelevant as haskell is very good with multi-core processors and parallel computing, so it's faster than other languages.

but it's also a bitch and nobody uses it
Commented 11 years ago2013-10-13 01:16:49 UTC Comment #50942
Eh, functional programming exists in many places where it is more useful than a pure functional language like Haskell or Lisp.

That concept of the 'infinite list' is called a generator and exists in many procedural and OO languages like Python (2.3), C# (2.0), JavaScript (1.7), PHP (5.5), and many more. It's certainly not exclusive to Haskell by any means.

Something like this is quite valid in C#:

IEnumerable<int> Numbers()
{
int i = 1;
while(true) yield return i++;
}

var five = Numbers().Take(5); // Contains [1, 2, 3, 4, 5]
Commented 11 years ago2013-10-13 11:56:42 UTC Comment #50946
You've perked my interest, I'm gonna check this language out IM!

You must log in to post a comment. You can login or register a new account.