• Hey, guest user. Hope you're enjoying NeoGAF! Have you considered registering for an account? Come join us and add your take to the daily discourse.

Programming |OT| C is better than C++! No, C++ is better than C

Koren

Member
I'm stuck learning fsharp so I can add a block to a file that nobody else at the company knows how to write or maintain.

This is hell.
I'd say it's hellish for a dozen hours, then it clicks and everything seems smooth (well, assuming it's as close as OCaml as I think it is, I can't install Xamarin T_T )
 

JeTmAn81

Member
How hard is it to learn a functional language once you've already learned at least one functional language previously? Is it like learning a new imperative language where you already grok the most important fundamentals and it's pretty easy to pick up a new one?
 

Makai

Member
How hard is it to learn a functional language once you've already learned at least one functional language previously? Is it like learning a new imperative language where you already grok the most important fundamentals and it's pretty easy to pick up a new one?
Nearly instant if you're in the same family

Lisp - Scheme - Clojure

Haskell - OCaml - F# - Rust - Swift
 

robin2

Member
i'm dabbling into 3d (voxels actually) and i don't understand indices (of vertices). I googled but everything i found is too technical/advanced for my level of incompetence:

i have a square face that is made of two triangular meshes; so a total of 6 vertices for the face. But two couples of these vertices share the same coordinates, since the two triangles are joined.. Do these vertices with the equal coordinates, have the same index (meaning that, in practice, there are 4 indices -or "index values"- per face)?
 

Koren

Member
i'm dabbling into 3d (voxels actually) and i don't understand indices (of vertices). I googled but everything i found is too technical/advanced for my level of incompetence:

i have a square face that is made of two triangular meshes; so a total of 6 vertices for the face. But two couples of these vertices share the same coordinates, since the two triangles are joined.. Do these vertices with the equal coordinates, have the same index (meaning that, in practice, there are 4 indices -or "index values"- per face)?
We'll need more information, I think, but I suppose there could be.

For example, take the square in 3D :

Code:
(0,1,0) _____ (1,1,0)
       |\    |
       | \   |
       |  \  |
       |   \ |
       |____\|
(0,0,0)       (1,0,0)

You have two triangles (0,0,0) - (0,1,0) - (1,0,0) and (0,1,0) - (1,1,0) - (1,0,0)

If you create a vertex table like
(0,0,0) | (0,1,0) | (1,0,0) | (1,1,0)

The first triangle is 0-1-2, the second 1-3-2, so 4 different indices.

You can usually represent a quad by 4 indices, like 0-1-3-2, since it's easy to reconstruct two triangles by suppressing the first and the third indices for example.


Also, where are the voxels? Or haven't I understood anything you're talking about??
 

robin2

Member
Also, where are the voxels? Or haven't I understood anything you're talking about??
It's more likely that I don't know what I'm talking about!

Anyway I think you answered my question:

here it computes the indices of the faces, 6 in total, but they get only 4 values because two are reused
Code:
		int numOfIndices = CHUNK_SIZE_X * CHUNK_SIZE_Y * CHUNK_SIZE_Z * 6 * 6 / 3;
		short[] indices = new short[numOfIndices];
		short j = 0;
		for (i = 0; i < numOfIndices; i += 6, j += 4) {
			indices[i + 0] = (short)(j + 0);
			indices[i + 1] = (short)(j + 1);
			indices[i + 2] = (short)(j + 2);
			indices[i + 3] = (short)(j + 2);  // notice this index value is reused
			indices[i + 4] = (short)(j + 3);
			indices[i + 5] = (short)(j + 0);  // notices this index values is reused
		}

here it creates the Meshes. i guess the last like sets up the "vertex tables" that you mention, with a total of 4 indices per face.
Code:
		this.meshes = new Mesh[chunksX * chunksY * chunksZ];
		for (i = 0; i < meshes.length; i++) {
			meshes[i] = new Mesh(
					true,
					CHUNK_SIZE_X * CHUNK_SIZE_Y * CHUNK_SIZE_Z * 6 * 4,
					CHUNK_SIZE_X * CHUNK_SIZE_Y * CHUNK_SIZE_Z * 36 / 3,
					VertexAttribute.Position(),
					VertexAttribute.Normal()
			);
			meshes[i].setIndices(indices);
		}

(this code is Java using libGDX, from here: https://github.com/libgdx/libgdx/tree/master/tests/gdx-tests/src/com/badlogic/gdx/tests/g3d/voxel)
 

Koren

Member
It's more likely that I don't know what I'm talking about!

Anyway I think you answered my question:

here it computes the indices of the faces, 6 in total, but they get only 4 values because two are reused
Yes, that's it...

It seems a part to convert the voxels into triangles for displaying purpose?
 

Skinpop

Member
i'm dabbling into 3d (voxels actually) and i don't understand indices (of vertices). I googled but everything i found is too technical/advanced for my level of incompetence:
voxels are just 3d bitmaps, they aren't very complicated at all. A bitmap is just an array storing some data(color if we are talking about images) and some information about its dimensions, so in 2d you have width and height and in 3d you have depth as well. Unlike triangles though since voxels is a data structure there's no notion of what they look like in terms of graphics. Most applications render them as cubes(but you could use whatever you want) and to do that you need to generate the geometry which I guess is what you are looking at.
 

Haly

One day I realized that sadness is just another word for not enough coffee.
I can't even do transitive.

I did counter in 50 then I saw some of the other scores...

Down to 16 with a little cheating thanks to spoilers.
 
Got counter down to 27 no spoilers

()=>{var a=0;return()=>++a}

No idea about the others. Anyway I think the test is bullshit because you should avoid all those situations.
 

Koren

Member
Yes. Note the lack of strict equality.
Saw it immediately, but I still don't have a clue. Again, I'm a JS newbie, I don't know all null / 0 / "" / undefined / etc. comparison results, and I suspect that's one of those cases...

I did counter in 50 then I saw some of the other scores...

Down to 16 with a little cheating thanks to spoilers.
Did 14, although I wasn't aware that
_ could replace ()
so that would make 13.

Can't really see how you can do less, but I have a lot to learn in JS. But the 1-character solution makes me wondering.
 

Koren

Member
()=>{var a=0;return()=>++a}

No idea about the others. Anyway I think the test is bullshit because you should avoid all those situations.
Was my first try, then I tried to reduce the variable declaration... Especially when getting rid of it means getting rid of return, too.

Little spoiler
think default arguments
 

Haly

One day I realized that sadness is just another word for not enough coffee.
Did 14, although I wasn't aware that
_ could replace ()
so that would make 13.
Yeah I could shave one off too with that but I have no idea why it works or where I can read up on it despite having gone over ES2015 multiple times.

This is my comprehensible solution for counter.

(x=1)=>()=>x++%4

How did you shave a point off of that? I think I can shorten the first argument but it's unclear how.
 

Somnid

Member
Did 14, although I wasn't aware that
_ could replace ()
so that would make 13.

() is needed if you have no arguments or it won't parse correctly, if you add a single character argument (in this case "_") it's actually one character shorter because parens can be omitted.

Can't really see how you can do less, but I have a lot to learn in JS. But the 1-character solution makes me wondering.

Any of the 1 character solutions are cheating. You can trivially hack the code on the page so if it seems too low it is.
 
Yeah I could shave one off too with that but I have no idea why it works or where I can read up on it despite having gone over ES2015 multiple times.

This is my comprehensible solution for counter.

(x=1)=>()=>x++%4

How did you shave a point off of that? I think I can shorten the first argument but it's unclear how.

You can delete 2 characters from this solution and it still works.

You can also replace 2 characters with 1 character and it still works.

That brings it down to 13.
 

Koren

Member
This one is more generic, supporting multiple languages for the same questions: https://www.codewars.com

I know this one... Codingame, too. And a bunch of problems collections like Euler Project to Advent of Code. (We should actually do a list)

But I was specifically talking about code golf, where length of solution matter. Codingame did this at a time, but I think they removed it...
 

Haly

One day I realized that sadness is just another word for not enough coffee.
Figured out counter@13 purely by accident as I was reentering the solution...

transitive:
'0',0,''

I know about this one from the spoilery comments:
[],0,[]
 

Haly

One day I realized that sadness is just another word for not enough coffee.
Lol I had to update to chrome 52 to do peano in 7:
2**53-1

Can someone tell me why that works but not:
2e53-1

Also how are people reaching 6 and 5?
 

Kansoku

Member
Quick question.

I defined two methods in Java, methodA(List<T> listA, List<T> listB) and methodB(T item, List<T> list). I then try to call the first method by passing two List<Integer>. However, when I try to compile, it complains about ambiguity.

What can I do to solve that?
 

Haly

One day I realized that sadness is just another word for not enough coffee.

Koren

Member
Experimental ES6 feature!

proto1 is the first question I answered almost instantly, but 19 isn't very good. I'm wondering where the 16 score people are saving chars.
I don't even know what I'm looking at ^_^

(finally found the transitive one, though... damn those comparisons are strange)
 

Makai

Member
Quick question.

I defined two methods in Java, methodA(List<T> listA, List<T> listB) and methodB(T item, List<T> list). I then try to call the first method by passing two List<Integer>. However, when I try to compile, it complains about ambiguity.

What can I do to solve that?
let's see the code
 

Kansoku

Member
let's see the code

There's not much more to that.

Code:
import java.util.*;

public class HelloWorld{

    public static <T> List<T> methodA(List<T> list1, List<T> list2){
        List<T> result = new ArrayList<T>();
        System.out.println("A");
        return result;
    }
    
    public static <T> List<T> methodA(T element, List<T> list){
        List<T> result = new ArrayList<T>();
        System.out.println("B");
        return result;
    }

     public static void main(String []args){
        List<Integer> a = methodA(Arrays.asList(1, 2), Arrays.asList(1, 2, 3));
     }
}
 
There's not much more to that.

Code:
import java.util.*;

public class HelloWorld{

    public static <T> List<T> methodA(List<T> list1, List<T> list2){
        List<T> result = new ArrayList<T>();
        System.out.println("A");
        return result;
    }
    
    public static <T> List<T> methodB(T element, List<T> list){
        List<T> result = new ArrayList<T>();
        System.out.println("B");
        return result;
    }

     public static void main(String []args){
        List<Integer> a = methodA(Arrays.asList(1, 2), Arrays.asList(1, 2, 3));
     }
}

That code works fine for me.

What I find odd is that you're not even invoking methodB at all. So it seems completely irrelevant to your question.
 

Kansoku

Member
That code works fine for me.

What I find odd is that you're not even invoking methodB at all. So it seems completely irrelevant to your question.

Ops sorry, checked here again, both method are called methodA. My bad. Will update the code.

The compiler error this:

Code:
HelloWorld.java:18: error: reference to methodA is ambiguous
        List<Integer> a = methodA(Arrays.asList(1, 2), Arrays.asList(1, 2, 3));
                          ^
  both method <T#1>methodA(List<T#1>,List<T#1>) in HelloWorld and method <T#2>methodA(T#2,List<T#2>) in HelloWorld match
  where T#1,T#2 are type-variables:
    T#1 extends Object declared in method <T#1>methodA(List<T#1>,List<T#1>)
    T#2 extends Object declared in method <T#2>methodA(T#2,List<T#2>)
1 error
 

Kylarean

Member
Ops sorry, checked here again, both method are called methodA. My bad. Will update the code.

The compiler error this:

Code:
HelloWorld.java:18: error: reference to methodA is ambiguous
        List<Integer> a = methodA(Arrays.asList(1, 2), Arrays.asList(1, 2, 3));
                          ^
  both method <T#1>methodA(List<T#1>,List<T#1>) in HelloWorld and method <T#2>methodA(T#2,List<T#2>) in HelloWorld match
  where T#1,T#2 are type-variables:
    T#1 extends Object declared in method <T#1>methodA(List<T#1>,List<T#1>)
    T#2 extends Object declared in method <T#2>methodA(T#2,List<T#2>)
1 error

Only way I can think to get rid of the ambiguity is to add a third parameter to each call of Class<T> clazz.

Then add Integer.class in the call from main.

Like:

Code:
	public static void main(String[] args) {
		List<Integer> a = methodA(Arrays.asList(1, 2, 3), Arrays.asList(1, 2, 3), Integer.class);
	}

	public static <T> List<T> methodA(List<T> list1, List<T> list2, Class<T> clazz) {
		List<T> result = new ArrayList<T>();
		System.out.println("A");
		return result;
	}

	public static <T> List<T> methodA(T element, List<T> list, Class<T> clazz) {
		List<T> result = new ArrayList<T>();
		System.out.println("B");
		return result;
	}

You're just running into a type erasure problem.
 

Kylarean

Member
Just specify it explicitly?

Code:
List<Integer> a = methodA<Integer>(Arrays.asList(1, 2, 3), Arrays.asList(1, 2, 3));

No. I don't believe that will work in this case.

<EDIT>

Actualy it might since the methods are static and he does it like this

Code:
List<Integer> a = HelloWorld.<Integer>methodA(Arrays.asList(1, 2, 3), Arrays.asList(1, 2, 3));

but I'm not in front of a compiler right now to test it.
 

TheeDanielJ

Neo Member
Hello everyone, I'm new here and am new to programming. I could really use some help. I'm working on validating string input. My loops repeats when its time for validating integer input, but just skips when its time to validate string input.

cout << "Player 1 enter your car number!" << endl;
cin >> carNumber[0];
while (cin.fail())
{
cout << "ERROR! Your car number must be an integer!" << endl;
cout << "Enter a number!" <<endl;
cin.clear();
cin.ignore(std::numeric_limits<int>::max(), '\n');
cin >> carNumber[0];
}
cout << "Player 1 enter a color for your car!" << endl;
cin >> carColor[0];
while (cin.fail())
{
cout << "ERROR! You must input a string aka a word!" << endl;
cout << "Enter a color!" << endl;
cin.clear();
cin.ignore((std::numeric_limits<std::streamsize>::max)(), '\n');
cin >> carColor[0];
}

Any help would be appreciated!
 

Pinewood

Member
Im slowly getting the grip on VBA, but I ran into an issue where if I convert the contents of a cell to a string, modify it and write it back, it omits the last nr if its a 0.

My code is here
Code:
s = "T" + Left(CStr(ws.Cells(1, i)), 4) + "." + Right(CStr(ws.Cells(1, i)), 2)
ws.Cells(1, i).Value = s

Ideally that should take a value like "2016.06" and convert it into "T2016.06"
But with October "2016.10" it gives me "T2016.,1"

Worst case I can go and change that one cell every time I convert but Id like to find a solution for this.
 
Top Bottom