Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

AY19/20 SS1 qn 7 #602

Open
muhdjabir opened this issue Apr 27, 2022 · 4 comments
Open

AY19/20 SS1 qn 7 #602

muhdjabir opened this issue Apr 27, 2022 · 4 comments

Comments

@muhdjabir
Copy link

Source

AY19/20 SS1
image

Description

Hi Everyone, I am abit weak in streams, how would you go about coding this out?

Screenshots (if any):

Insert Images here if necessary

@tzk00
Copy link

tzk00 commented Apr 27, 2022

Hi, what I did was I first created a stream of integers from 1 to n. I then map each integer to a point which I will then pass as an argument to a circle. The two points of the circle always add up to n + 1. So the rough idea to create a circle would be new Circle (new Point(x, n + 1 - x)) where x refers to each integer in the stream. I am not sure if this is the correct method but I could only think of this.

@MaxYongSK
Copy link

MaxYongSK commented Apr 27, 2022

I did this which is the same as what @tzk00 did I think

List< Circle > getCircles(int n) {
return Stream.iterate(1, x -> x <= n, x -> x + 1).map(x -> new Circle(new Point(x, n + 1 - x)))
.collect(Collectors.toList());
}

@calvinseptyanto
Copy link

List getCircles(int n) {
return Stream.iterate(1.0, x -> x + 1)
.limit(n)
.map(x -> new Circle(new Point(x, n + 1 - x)))
.collect(Collectors.toList());
}

@Lu-Yi-Fan
Copy link

List getCircles(int n) {
return Stream.iterate(1, i-> i < n +1, i -> i + 1).map(x -> new Circle( new Point((double) x,(double) (n+ 1 - x)))).collect(Collectors.toList());
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants