sepp2k's Profile User Rating: *****

Reputation: 2180 Grandmaster
Group:
Mentors
Active Posts:
3,380 (2.45 per day)
Joined:
21-June 11
Profile Views:
55,703
Last Active:
User is offline Private
Currently:
Offline

Previous Fields

Country:
DE
OS Preference:
Linux
Favorite Browser:
Who Cares
Favorite Processor:
Who Cares
Favorite Gaming Platform:
Who Cares
Your Car:
Who Cares
Dream Kudos:
0
Expert In:
C/C++, Functional Programming, Java, Python, Computer Science
Icon   sepp2k has not set their status

Posts I've Made

  1. In Topic: Haskell: Check if a number appears in a list 0 or 1 times

    Posted 26 Mar 2015

    It would help if you specified in what way your attempts did not do what you want (and what error message you're getting if any), but let's take a look at your first attempt:

    • If the list is empty, the result is True. That seems correct.
    • When it is not empty, the first element is equal to y and y appears at most once in the remaining elements, the result is False. That seems wrong. What if x appears zero times in the remaining elements? That'd mean that y appeared one time in total, meaning the function should be true, but it's not because the condition (x==y) && (atmostonce lx y) is met and you thus produce False as the result.
    • When the first element is not equal to y, the result is True. That also seems incorrect. That means you'd get True for the list [notY, y, y, y] even though y appears three times in it. You have to keep looking at the remaining items in the list until you find more than one or you've reached the end of the list.


    Your second attempt is clearly a type error. The first argument of elem should be the item you're looking for and the second argument should be the list. You supplied the list first, so that will not compile. Your usage of elem also doesn't seem helpful as finding out whether the list contains the number 1 or the number 0 does not seem relevant to the problem at hand. Unless I completely misunderstood your problem description, you want to whether x appears 1 or 0 times - not whether 1 or 0 appear in the list. Lastly you only provided a pattern for when the second argument is 1, so you'd get an exception when you call the function with any argument other than 1.
  2. In Topic: Working with 2d arrays and trying to change 'touching' indexes

    Posted 23 Mar 2015

    Ah, I see. You can either access the items by index like this: arr[ pos[0], pos[1] ] (where pos is an element of @pos, which really should be called @positions or at least @poss to make clear that it contains multiple position - also does it really need to be an instance variable? Where else do you need to access it?). Or you can unpack the array directly when iterating like this:

    @positions.each do |row_num, col_num|
      # ...
    end
    
    
  3. In Topic: Working with 2d arrays and trying to change 'touching' indexes

    Posted 23 Mar 2015

    The easiest approach would be to not modify the array in-place, but rather create a new with the new values. I can think of two relatively straight-forward ways to accomplish this:

    1. Use nested calls to map.with_index and then inside the block produce 1 iff the corresponding element in the old array or any of its neighbors are 1.
    2. Create a nested array of zeros (new_array = Array.new(num_rows) { Array.new(num_cols, 0) }), then iterate over the original array using each_with_index (just like you are doing now) and whenever you encounter a 1, set the corresponding element in the new array as well as its neighbors to 1.

    Your approach should work too though. What problem are you encountering with it?
  4. In Topic: Can someone show me how to get this code to stop asking for my name?

    Posted 18 Mar 2015

    Also if you only want one name, there's no reason to have a vector of them.
  5. In Topic: Formal Verification of Programs

    Posted 17 Mar 2015

    View PostSkydiver, on 17 March 2015 - 06:20 PM, said:

    Because the claim is that it is a "program correctness verification tool" therefore it should also verify the correctness for things that a compiler would spot.


    Either you misread my post or I'm totally misreading yours. I didn't say "the compiler warns about these cases, so the verification tool doesn't need to". I said "the compiler warns about these cases, so obviously the verification tool can detect them as well".

    Of course the general case of detecting all cases of UB in C or C++ is undecidable, but that doesn't make it harder for the verifier to detect than other cases of contract violations, which are equally undecidable.

My Information

Member Title:
D.I.C Lover
Age:
Age Unknown
Birthday:
Birthday Unknown
Gender:
Years Programming:
15
Programming Languages:
Haskell, Ruby, OCaml, SML, F#, Scala, Racket/Scheme, Vala, C#, C++, Java

Contact Information

E-mail:
Private
ICQ:
ICQ  205544826
Jabber:
Jabber  sexykane86@jabber.ccc.de