<?xml version="1.0" encoding="utf-8"?>
<feed xmlns="http://w3.org/2005/Atom" xml:lang="en">
<title type="text">Luís Ramalho</title>
<generator uri="https://github.com/jekyll/jekyll">Jekyll</generator>
<link rel="self" type="application/atom+xml" href="https://luisramalho.com/feed.xml" />
<link rel="alternate" type="text/html" href="https://luisramalho.com" />
<updated>2020-03-18T03:00:30+00:00</updated>
<id>https://luisramalho.com/</id>
<author>
  <name>Luís Ramalho</name>
  <uri>https://luisramalho.com/</uri>
  
</author>


<entry>
  <title type="html"><![CDATA[How Augmented Reality Can Help Develop the Sense of Belonging in Software Engineers Working Remotely]]></title>
  <link rel="alternate" type="text/html" href="https://luisramalho.com/how-augmented-reality-can-help-develop-the-sense-of-belonging-in-software-engineers-working-remotely" />
  <id>https://luisramalho.com/how-augmented-reality-can-help-develop-the-sense-of-belonging-in-software-engineers-working-remotely</id>
  <published>2020-03-18T00:00:00+00:00</published>
  <updated>2020-03-18T00:00:00+00:00</updated>
  <author>
    <name>Luís Ramalho</name>
    <uri>https://luisramalho.com</uri>
    
  </author>
  <content type="html">
    &lt;p&gt;As more and more people are switching to work remotely due to the current world pandemic, I’d like to share my dissertation submitted for my master’s degree in 2018 which explored how augmented reality can help develop the sense of belonging in software engineers working remotely. Here’s the abstract:&lt;/p&gt;

&lt;blockquote&gt;
  &lt;p&gt;The rise of remote working is creating not only opportunities but also challenges to organisations. One important challenge is how to to develop belongingness when employees are working at distance from their colleagues and the organisation premises.&lt;/p&gt;

  &lt;p&gt;This study presents a qualitative synthesis review of the literature on the effects of remote working on the sense of belonging of software engineers and explores how augmented reality could help develop it. It examined the topics of sense of belonging, software engineers working remotely and augmented reality with the intention of finding correlations between them as well as providing a comprehensive background and current knowledge in these areas. This review has found that augmented reality could potentially be used to develop the sense of belonging of software engineers working remotely by creating a feeling of presence, allowing for the development of an identity and generating opportunities for informal communication to take place.&lt;/p&gt;

  &lt;p&gt;However, the research has also shown that the current state-of-the-art augmented reality technology has not yet reached a stage where it would be feasible to use it to develop the sense of belonging of remote employees. Therefore, further research could use the insights from this summary of the literature to direct the development of augmented reality technologies towards practical implementations that could be used in the real world in order to develop the sense of belonging of employees working remotely.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;You can read the full dissertation &lt;a href=&quot;/assets/articles/ramalho_luis_2018.pdf&quot;&gt;here&lt;/a&gt;.&lt;/p&gt;

    &lt;p&gt;&lt;a href=&quot;https://luisramalho.com/how-augmented-reality-can-help-develop-the-sense-of-belonging-in-software-engineers-working-remotely&quot;&gt;How Augmented Reality Can Help Develop the Sense of Belonging in Software Engineers Working Remotely&lt;/a&gt; was originally published by Luís Ramalho at &lt;a href=&quot;https://luisramalho.com&quot;&gt;Luís Ramalho&lt;/a&gt; on March 18, 2020.&lt;/p&gt;
  </content>
</entry>


<entry>
  <title type="html"><![CDATA[Ways to improve estimates for project times and costs]]></title>
  <link rel="alternate" type="text/html" href="https://luisramalho.com/ways-to-improve-estimates-for-project-times-and-costs" />
  <id>https://luisramalho.com/ways-to-improve-estimates-for-project-times-and-costs</id>
  <published>2018-09-06T00:00:00+00:00</published>
  <updated>2018-09-06T00:00:00+00:00</updated>
  <author>
    <name>Luís Ramalho</name>
    <uri>https://luisramalho.com</uri>
    
  </author>
  <content type="html">
    &lt;p&gt;In order to discuss the possible ways to improve the accuracy of estimates, it is important to understand that there
is not a direct and effortless solution to this problem. There are multiple ways to assess an estimate.&lt;/p&gt;

&lt;iframe width=&quot;560&quot; height=&quot;315&quot; src=&quot;https://youtube.com/embed/eBt9dbsRLUI&quot; frameborder=&quot;0&quot; allow=&quot;autoplay; encrypted-media&quot; allowfullscreen=&quot;&quot;&gt;&lt;/iframe&gt;

&lt;p&gt;&lt;br /&gt;&lt;/p&gt;

&lt;p&gt;According to
Heinze (2017) these can be summarised in how credible, accurate, exact, precise, reliable, tolerant and valid an
estimate is. Although, it could be argued that the most important measure of project success is how close it sticks
to the project budget (i.e. cost) and schedule (i.e. duration or time). As described in the previous video, there are a wide
range of reasons why estimates are often wrong. In fact, it would not have been possible to cover all the reasons or
ways to improve each and every cause of inaccurate estimates. Therefore, this video will focus on a subset of
causes and ways to increase the probability of better estimates.&lt;/p&gt;

&lt;p&gt;A large and growing body of literature (Clark and Lorenzoni 1996; Kemp 2004; Steyn et al. 2016; Amos 2004; Seeletse
and Ladzani 2012) has investigated what would be necessary for a more accurate estimate. They suggest that first
and foremost it is essential to have a well-defined scope of the project that it is to be estimated. In fact, it would
certainly lead to an inaccurate estimate to try and assess a project without fully understanding its scope. Secondly,
there needs to be a dependable cost element structure in which the information is well organised. Thirdly, it
would be beneficial to use historical cost data, in other words, analysing similar projects and trying to understand
how much time and money was spent in those projects could help more accurately estimate how much time and
money will be needed for the new project. This information can be provided from the cost accounting records or
by people with detailed knowledge or experience in similar projects. Furthermore, Novakova (2013) argues that
this historical data should be combined with actual calculated costs in order to improve the likelihood that the
estimate is closer to the final cost and time.&lt;/p&gt;

&lt;p&gt;As was pointed out in the previous video, risk plays a critical and important role in a project. Risk, if not
accounted for, can cause a project to fail, be delayed or over budget. Therefore, it is absolutely necessary to have a
contingency plan to cover the potential risks and uncertainties that are inherent to a complex project. Cheung,
Wong and Skitmore (2008) identified that a person that is risk-averse and tolerates underestimates more than
overestimates is more likely to produce a more accurate estimate. This is not surprising, thus a way to improve
estimates for project times and costs is to simply take the risk and uncertainties into consideration and plan for
them in advance. Thus, one could make sure that the person doing the estimate is of the type described previously.
Moreover, one should not be reluctant to overestimate if the consequences of doing so are not exceedingly serious.&lt;/p&gt;

&lt;p&gt;As far as the psychological factors are concerned, there are a few threats that need to be taken into account. Firstly,
opportunism or a hidden agenda can cause projects to be poorly estimated. These private interests can sometimes
not be perfectly aligned with the goals of the project (Flyvbjerg, Bruzelius and Rothengatter 2003). It is difficult to
give a solution for this problem, as the causes for that happening are extensive. However, one possible solution
would be to not have a single person or small group of individuals doing the estimate. In fact, the more team
members involved in creating the estimate the more likely it will be that it will be closer to the true cost and schedule. Secondly, bounded rationality, where the people involved might have cognitive limitations regarding
the risk estimation (Bazerman andMoore 2008). In this case, it would be better to seek further opinions from
experts or people that have dealt with similar projects in the past. Finally, there is the issue of subjectivity, where
project players might base their estimates in previous experiences, values or personal opinions that are not linked
to any data or calculations (Parkin 1996). As with the bounded rationality, in this situation, it would be beneficial
to consult other people to try and achieve a better estimate.&lt;/p&gt;

&lt;p&gt;Thus far, several studies (MacDonell and Shepperd 2003; Trendowicz and Jeffery 2014; McLain 2009; Devaux
1999) have suggested that a possible way to improve estimates for a project’s time and cost is to use multiple
estimates rather than just one. In this manner, the subjectivity and unreliability of a single estimate is reduced;
thus, increasing the accuracy of the final estimate. As noted byMcLain (2009), a way to combine these multiple
estimates is to simply take an average. The other solution to deal with multiple estimates is to choose the one
with the more thorough analysis or the one that the majority of the stakeholders in the project believe to be the
closest to the actual cost and time.&lt;/p&gt;

&lt;p&gt;Furthermore, it is necessary to constantly measure and monitor a project so that the chances of it going wrong
are reduced. Thus, leading to our final suggestion to improve estimates. That is to continuously re-estimate the
project and with that being aware of the possible errors done in the previous estimates and adjusting the plan
accordingly. Moreover, estimates should allow for flexibility, and therefore should not be too strict in terms of cost
and time. So, a final thought would be to try and keep estimates as adaptable or responsive as possible in order to
accommodate for the uncertainties that will most likely occur.&lt;/p&gt;

&lt;p&gt;In conclusion, estimates are not an exact science and it will always be impossible to have it absolutely accurate.
Therefore, one should on one hand have the reasons for wrong estimates described in the previous video in mind when
estimating, and on the other hand, try and apply the suggestions given in this video to eliminate some of these
reasons when estimating the time and cost of a project.&lt;/p&gt;

&lt;h2 id=&quot;references&quot;&gt;References&lt;/h2&gt;

&lt;p&gt;&lt;small&gt;Amos, Scott J (2004). Skills &amp;amp; knowledge of cost engineering. AACE International.&lt;/small&gt;&lt;/p&gt;

&lt;p&gt;&lt;small&gt;Bazerman,Max H and Don AMoore (2008). ‘Judgment in managerial decision making’.&lt;/small&gt;&lt;/p&gt;

&lt;p&gt;&lt;small&gt;Cheung, Franco KT,Margie WLWong andMartin Skitmore (2008). ‘A study of clients’ and estimators’ tolerance
towards estimating errors’. In: Construction management and economics 26.4, pp. 349–362.&lt;/small&gt;&lt;/p&gt;

&lt;p&gt;&lt;small&gt;Clark, Forrest and Albert B Lorenzoni (1996). Applied cost engineering. CRC Press.&lt;/small&gt;&lt;/p&gt;

&lt;p&gt;&lt;small&gt;Devaux, Stephen A (1999). Total project control: A manager’s guide to integrated project planning, measuring, and
tracking.Wiley New York, NY.&lt;/small&gt;&lt;/p&gt;

&lt;p&gt;&lt;small&gt;Flyvbjerg, Bent, Nils Bruzelius andWerner Rothengatter (2003).Megaprojects and risk: An anatomy of ambition.
Cambridge University Press.&lt;/small&gt;&lt;/p&gt;

&lt;p&gt;&lt;small&gt;Heinze, Kurt (2017). Cost management of capital projects. Routledge.&lt;/small&gt;&lt;/p&gt;

&lt;p&gt;&lt;small&gt;Kemp, Sid (2004). Project management demystified.McGraw Hill Professional.&lt;/small&gt;&lt;/p&gt;

&lt;p&gt;&lt;small&gt;MacDonell, Stephen G andMartin J Shepperd (2003). ‘Combining techniques to optimize effort predictions in
software project management’. In: Journal of Systems and Software 66.2, pp. 91–98.
McLain, David (2009). ‘Quantifying project characteristics related to uncertainty’. In: ProjectManagement Journal
40.4, pp. 60–73.&lt;/small&gt;&lt;/p&gt;

&lt;p&gt;&lt;small&gt;Novakova, Helena (2013). ‘Methodology of transportation project management’. In: Journal of Systems Integration
4.3, p. 30.&lt;/small&gt;&lt;/p&gt;

&lt;p&gt;&lt;small&gt;Parkin, James (1996). ‘Organizational decision making and the project manager’. In: International Journal of
ProjectManagement 14.5, pp. 257–263.&lt;/small&gt;&lt;/p&gt;

&lt;p&gt;&lt;small&gt;Seeletse, Solly andWatson Ladzani (2012). ‘Project cost estimation techniques used by most emerging building
contractors of South Africa’. In: Acta Structilia 19.1, pp. 106–125.&lt;/small&gt;&lt;/p&gt;

&lt;p&gt;&lt;small&gt;Steyn, Herman et al. (2016). Project management: A multi-disciplinary approach. FPM Publishing.&lt;/small&gt;&lt;/p&gt;

&lt;p&gt;&lt;small&gt;Trendowicz, Adam and Ross Jeffery (2014). ‘Software project effort estimation’. In: Foundations and Best Practice
Guidelines for Success, Constructive CostModel–COCOMO pags, pp. 277–293.&lt;/small&gt;&lt;/p&gt;

    &lt;p&gt;&lt;a href=&quot;https://luisramalho.com/ways-to-improve-estimates-for-project-times-and-costs&quot;&gt;Ways to improve estimates for project times and costs&lt;/a&gt; was originally published by Luís Ramalho at &lt;a href=&quot;https://luisramalho.com&quot;&gt;Luís Ramalho&lt;/a&gt; on September 06, 2018.&lt;/p&gt;
  </content>
</entry>


<entry>
  <title type="html"><![CDATA[Why estimates go wrong?]]></title>
  <link rel="alternate" type="text/html" href="https://luisramalho.com/why-estimates-go-wrong" />
  <id>https://luisramalho.com/why-estimates-go-wrong</id>
  <published>2018-09-04T00:00:00+00:00</published>
  <updated>2018-09-04T00:00:00+00:00</updated>
  <author>
    <name>Luís Ramalho</name>
    <uri>https://luisramalho.com</uri>
    
  </author>
  <content type="html">
    &lt;p&gt;Accurate estimates are notorious difficult to make. Parkinson’s law states that “work expands so as to fill the
time available for its completion” (Parkinson 1968). In fact, this law might explain the reason why projects rarely
underrun. However, the major problem in many projects is that the time available for its completion is often
underestimated, thus, causing the potential cancellation or overrun of the project both in terms of time and cost.
In the sections that follow, there will be a discussion of reasons why estimates are often wrong and in another post give &lt;a href=&quot;/ways-to-improve-estimates-for-project-times-and-costs&quot;&gt;suggestions of ways to improve them&lt;/a&gt;.&lt;/p&gt;

&lt;iframe width=&quot;560&quot; height=&quot;315&quot; src=&quot;https://youtube.com/embed/kmGZQI5mrMY&quot; frameborder=&quot;0&quot; allow=&quot;autoplay; encrypted-media&quot; allowfullscreen=&quot;&quot;&gt;&lt;/iframe&gt;

&lt;h2 id=&quot;reasons-why-estimates-are-often-wrong&quot;&gt;Reasons why estimates are often wrong&lt;/h2&gt;

&lt;p&gt;A notorious industry where project estimates are extremely often wrong is the construction industry (Chan and
Park 2005). The Olympic Games is a great example, where more often than not the budget is surpassed. Although
one of the reasons for this is that the time constraints forces the project to invariably be concluded on time.
There are nonetheless other examples, such as the software industry. Here, Laird and Brennan (2006) state that
approximately one quarter of all projects are cancelled ahead of their completion. In fact, of the percentage of
projects that actually finish, only 28% deliver on the initial estimated cost and time. These inaccurate estimates,
one could argue, are spread over all industries and a substantial amount of research has been done in order to
identify the root cause and possible explanations for this recurring issue of imprecise estimates.&lt;/p&gt;

&lt;p&gt;However, it is important to note, before listing a few possible reasons that may cause estimates to be often wrong,
that the project schedule is usually negotiated at the beginning of a project (Daughtrey and Carroll 2007). Aside
from that, in most cases projects start with a date that is decided in advance and with a poor definition of the
requirements needed.&lt;/p&gt;

&lt;p&gt;A reasonable way to list these reasons would be to categorise them into different groups. Siemiatycki (2008) divided
the reasons an estimate might be inaccurate into four main categories, which are: (1) technical; (2) economic; (3)
psychological; and (4) political. These sub-groups are logical and will be pointed to during the discussion.&lt;/p&gt;

&lt;p&gt;In the literature, multiple authors (Cantarelli et al. 2013; Ramgopal 2003; Siemiatycki 2008) suggest that uncertainties
are possibly the major cause of wrong estimates. These are the technical reasons an estimate might not
be accurate. Ramgopal (2003) argues that the resources and methods choices are often based on assumptions
that might not include any contingency for unpredictable events. Furthermore, this assumptions are not due to
rational decision-making but rather a result of opportunism, bounded rationality and subjectivity (Firmenich
2017). Thus, the individuals in charge of the estimates might be limited by the scope of the project they are aware
of or the time left to make a decision.&lt;/p&gt;

&lt;p&gt;Another technical issue that might cause estimates to be wrong is that they are usually taken from historical data.&lt;/p&gt;

&lt;p&gt;Novakova (2013) pointed out that since costs in the past are smaller than in the present, these early estimations
are often undervalued. In addition, there are also estimates that go over the actual cost (Moyo and Huisman 2014),
although less frequent, these are also the result of similar factors that cause estimates to go under the actual cost.
For example, these factors could be uncertainties or bounded rationality. Furthermore, considering Parkinson’s
law (Parkinson 1968) it could be argued that estimates are created based on the time available to complete the
tasks, instead of the actual time that would take to finish them. This would cause projects to either finish on the
time stipulated or simply to overrun. Also, Daughtrey and Carroll (2007) state that the task interdependencies are
not recognised in the early stages which might cause further deviations from an accurate estimate. In fact, this is
one very important point because if task interdependencies are not planned properly and a contingency solution
is not in place then most likely the estimate will fail to be correct.&lt;/p&gt;

&lt;p&gt;Humans are not perfectly rational; they are emotional and therefore prone to misjudgement and biases. Flyvbjerg,
Holm and Buhl (2002) state that in the beginning of a project, cost reports consistently underestimate the budget
because they anticipate a best-case scenario instead of a sensible and more realistic expectation. This, also called
“optimism bias” (Siemiatycki 2008), occurs when on one hand organisations underestimate time and cost but on
the other hand overestimate the benefits of a project. It is a case of a psychological reason for inaccurate estimates.
Cantarelli et al. (2013) add that these initial cost estimates besides the fact that they include prior uncertainties,
they are also influenced by possible political pressures, extra modifications and with limited direction during the
process.&lt;/p&gt;

&lt;p&gt;However, one of the limitations of the factors described in the previous paragraphs is the assumption that the
people making the estimates are honest and integrous. Unfortunately, the real world is very complex and often
the person doing the estimate will try and disregard on purpose the actual cost of the project so that they increase
their chances in successfully promoting a project due to its cheapness (Flyvbjerg, Bruzelius and Rothengatter
2003). That is an example of both an economic and political argument sub-grouped by Siemiatycki (2008) as a
cause for possible imprecise estimates. Furthermore, even though they might be honest and integrous, they might
lack risk management competence in order to effectively estimate a complex project. In fact, if they simply do not
have the necessary competence they will in effect produce a poor risk analysis and as a consequence produce a
flawed estimate. In addition, it is not uncommon for companies to over-commit and later under-deliver. This can
occur as a result of multiple factors, such as competitive pressure from other companies, having an excessively
eager sales team, a misunderstanding of the consequences of the commitment or merely for failing to include the
team in the estimation process (Daughtrey and Carroll 2007).&lt;/p&gt;

&lt;p&gt;In summary, there are endless reasons why estimates are often wrong. They are extremely hard to make precisely
and there are simply too many variables to be counted that might cause the estimates to be inaccurate. The goal
would be, therefore, to try and quantify as much as possible the risks and have a contingency plan in case the
project almost without exception does not occur as predicted. As an old adage from Benjamin Franklin states: “If
you fail to plan, you are planning to fail”&lt;/p&gt;

&lt;h2 id=&quot;references&quot;&gt;References&lt;/h2&gt;

&lt;p&gt;&lt;small&gt;Cantarelli, Chantal C et al. (2013). ‘Cost overruns in large-scale transportation infrastructure projects: Explanations
and their theoretical embeddedness’. In: arXiv preprint arXiv:1307.2176.&lt;/small&gt;&lt;/p&gt;

&lt;p&gt;&lt;small&gt;Chan, Swee Lean and Moonseo Park (2005). ‘Project cost estimation using principal component regression’. In:
ConstructionManagement and Economics 23.3, pp. 295–304.&lt;/small&gt;&lt;/p&gt;

&lt;p&gt;Daughtrey, Taz and Sue Carroll (2007). Fundamental concepts for the software quality engineer. Vol. 2. ASQ Quality
Press.&amp;lt;/small&amp;gt;&lt;/p&gt;

&lt;p&gt;&lt;small&gt;Firmenich, Jennifer (2017). ‘Customisable framework for project risk management’. In: Construction Innovation
17.1, pp. 68–89.&lt;/small&gt;&lt;/p&gt;

&lt;p&gt;&lt;small&gt;Flyvbjerg, Bent, Nils Bruzelius and Werner Rothengatter (2003). Megaprojects and risk: An anatomy of ambition.
Cambridge University Press.&lt;/small&gt;&lt;/p&gt;

&lt;p&gt;&lt;small&gt;Flyvbjerg, Bent, Mette Skamris Holm and Soren Buhl (2002). ‘Underestimating costs in public works projects:
Error or lie?’ In: Journal of the American planning association 68.3, pp. 279–295.&lt;/small&gt;&lt;/p&gt;

&lt;p&gt;&lt;small&gt;Laird, Linda M and M Carol Brennan (2006). Software measurement and estimation: a practical approach. Vol. 2.
JohnWiley &amp;amp; Sons.&lt;/small&gt;&lt;/p&gt;

&lt;p&gt;&lt;small&gt;Moyo, Benson andMagda Huisman (2014). ‘Empirical investigation of Systems Cost EstimationModels in the
Limpopo province of South Africa: A requirements modelling problem’. In: Proceedings of the International
Conference on Software Engineering Research and Practice (SERP).WorldComp, p. 1.&lt;/small&gt;&lt;/p&gt;

&lt;p&gt;&lt;small&gt;Novakova, Helena (2013). ‘Methodology of transportation project management’. In: Journal of Systems Integration
4.3, p. 30.&lt;/small&gt;&lt;/p&gt;

&lt;p&gt;&lt;small&gt;Parkinson, C Northcote (1968). Parkinson’s Law on the Pursuit of Progress. Penguin Books.&lt;/small&gt;&lt;/p&gt;

&lt;p&gt;&lt;small&gt;Ramgopal, Maruboyina (2003). ‘Project uncertainty management’. In: Cost Engineering 45.12, pp. 21–24.&lt;/small&gt;&lt;/p&gt;

&lt;p&gt;&lt;small&gt;Siemiatycki, Matti (2008). ‘Managing optimism biases in the delivery of large-infrastructure projects: A corporate
performance benchmarking approach’. In: Infrastructure Systems and Services: Building Networks for a Brighter&lt;/small&gt;&lt;/p&gt;

&lt;p&gt;&lt;small&gt;Future (INFRA), 2008 First International Conference on. IEEE, pp. 1–6.&lt;/small&gt;&lt;/p&gt;

    &lt;p&gt;&lt;a href=&quot;https://luisramalho.com/why-estimates-go-wrong&quot;&gt;Why estimates go wrong?&lt;/a&gt; was originally published by Luís Ramalho at &lt;a href=&quot;https://luisramalho.com&quot;&gt;Luís Ramalho&lt;/a&gt; on September 04, 2018.&lt;/p&gt;
  </content>
</entry>


<entry>
  <title type="html"><![CDATA[Lean Thinking versus Project Management]]></title>
  <link rel="alternate" type="text/html" href="https://luisramalho.com/lean-thinking-vs-project-management" />
  <id>https://luisramalho.com/lean-thinking-vs-project-management</id>
  <published>2018-09-02T00:00:00+00:00</published>
  <updated>2018-09-02T00:00:00+00:00</updated>
  <author>
    <name>Luís Ramalho</name>
    <uri>https://luisramalho.com</uri>
    
  </author>
  <content type="html">
    &lt;p&gt;In order to compare and contrast Lean Thinking with Project Management it is essential do define an assessment criteria. These are the decisive aspects and objectives of a project that may deem it a success.&lt;/p&gt;

&lt;iframe width=&quot;560&quot; height=&quot;315&quot; src=&quot;https://youtube.com/embed/0t8PNvjjIrI&quot; frameborder=&quot;0&quot; allow=&quot;autoplay; encrypted-media&quot; allowfullscreen=&quot;&quot;&gt;&lt;/iframe&gt;

&lt;p&gt;&lt;br /&gt;&lt;/p&gt;

&lt;p&gt;Considering that there are broadly two stages in a project: the delivery and post delivery. Where the former is concerned with doing the project right and the latter with getting the project right. For this post the focus is on the former, thus the assessment criteria described will be regarding the process of handling a project; the delivery.&lt;/p&gt;

&lt;h2 id=&quot;project-success-criteria&quot;&gt;Project Success Criteria&lt;/h2&gt;

&lt;p&gt;One of the most common criteria to measure the success of a project is the triple constraint, also known as the Iron Triangle (This term was coined by Dr. Martin Barnes in 1969 for a course entitled ‘Time andMoney in Contract Control’), that consists of time, cost and quality (Olsen 1971). It is of sound judgement to believe that a project that completes on time, within the stipulate budget and adequate quality is a successful one. However, it could be questioned if these aspects suggested by Olsen (1971) almost 50 years ago are still good measurements of a project success. It can be argued that time and cost are often just estimates and quality is not an objective aspect but rather it has different meanings for different people. An example of this is the Sydney Opera House which, in spite of failing all three Iron Triangle elements, can arguably be considered a successful project as it is a world-famous landmark and an icon of architecture (Lim andMohamed 1999). Notwithstanding this reasoning, often these three attributes do lead to a project that is seen as successful. In the next section the contributions of Lean and Project Management to achieve success in the triple constraint will be discussed.&lt;/p&gt;

&lt;h2 id=&quot;iron-triangle-time-cost-and-quality&quot;&gt;Iron Triangle: Time, Cost and Quality&lt;/h2&gt;

&lt;h3 id=&quot;time&quot;&gt;Time&lt;/h3&gt;

&lt;p&gt;On the question of time, Lean as described in our previous post &lt;a href=&quot;/lean-thinking-for-new-product-introduction&quot;&gt;Lean Thinking for New Product Introduction&lt;/a&gt; is a philosophy that seeks to eliminate waste. In this case, waste would be Non-Value Adding (NVA) activities, delays, transportation and unnecessary movement. However, it is beyond the bounds of possibility to eliminate waste completely. So, this is an endless pursue rather than a objective. In Project Management, which is based more on tools and techniques, the time constraint is more immutable and therefore the tasks are ordered, often in terms of priority, and then executed as competently as possible in order to meet the deadline. PM uses Gantt charts (Wilson 2003) and Scrum boards (Schwaber 2004) for a visual representation of the phases and progress of a project. Finally, on one hand it can be argued that Lean, as a continuing process, would be better suitable for projects that last longer and have similar tasks and on the other hand PM would be better for isolated or ‘one-off’ type of projects where the variables are unique.&lt;/p&gt;

&lt;h3 id=&quot;cost&quot;&gt;Cost&lt;/h3&gt;

&lt;p&gt;In terms of cost, Project Management (PM) has mainly three areas where it seeks to control the costs, these are:&lt;/p&gt;
&lt;ol&gt;
  &lt;li&gt;Cost estimation; where there is an attempt to roughly calculate the total cost of the project. For example, analogous estimating (Rad 2002) which estimates the cost by of one project based on the cost of a previous project.&lt;/li&gt;
  &lt;li&gt;Cost budgeting; where the project manager attempts to aggregate the total cost of the project in order to form a basic level for the costs; and&lt;/li&gt;
  &lt;li&gt;Cost control; where all the elements that might impact the cost of the project are limited as much as possible employing cost management tools. Lean tries to control the costs of a project by making sure everyone in the organisation sticks to standardised work and continuous improvement by reporting and correcting issues as soon as possible. Furthermore, if there are wastes that are causing extra costs, e.g. an overhead cost or expense, Lean can eliminate these and by doing so will reduce costs.&lt;/li&gt;
&lt;/ol&gt;

&lt;h2 id=&quot;quality&quot;&gt;Quality&lt;/h2&gt;

&lt;p&gt;As far as quality is concerned, Project Management is a more linear process than Lean. Starting with PM, the Project Management Institute (2013) in their PMBOK Guide divided project quality management into three processes:
quality planning, quality assurance, and quality control. Firstly, a quality management plan is elaborated during quality planning. Secondly, project audits take place in the quality assurance stage in order to determine if a project is following the procedures and policies of the project and organisation. Finally, on the quality control step, inspections are made in order to determine if the project was done in line with the standards. In the case
of Lean the goal is to eliminate muda, rather than inspecting the project at the last stage, Lean tries to inspect
early in the process. Using value stream mapping it is possible to identify and prevent defects from the beginning.
Furthermore, with the standardised work and the constant implementation and enforcement of the best practices,
Lean ensures that quality is continuously improved.&lt;/p&gt;

&lt;h2 id=&quot;impact-on-stakeholders&quot;&gt;Impact on Stakeholders&lt;/h2&gt;

&lt;p&gt;The impact on stakeholders is one of the factors to have in consideration for a project. In fact, meeting or
even exceeding these expectations can deem a project successful; if it also achieves the objectives. In Project
Management one of the goals is to monitor the expectations of the stakeholders. This can be done with a Key
Performance Indicator (KPI) that addresses the stakeholder’s concern, this KPI should be made aware to the
stakeholder and updated frequently (Ogunlana et al. 2010). Furthermore, just the fact that the project is complying
with the Iron Triangle  will make the stakeholders feel that the project is going according to plan.
Nonetheless, these will have to be communicated to the stakeholders and therefore interpersonal skills will play
an important role. Lean will try and satisfy the stakeholders by delivering an impeccable product with no time
wasted and lowest cost without jeopardising quality (Oppenheim,Murman and Secor 2011). Oppenheim (2004)
argues that Lean helps the employees involved in the design stage of product development by allowing them to
have an uninterrupted flow. By doing that, it increases the chances that the work will be done with focus and the
final design should be representative of the extra attention given to the project’s tasks.&lt;/p&gt;

&lt;h2 id=&quot;internal-success&quot;&gt;Internal Success&lt;/h2&gt;

&lt;p&gt;Internal success, in spite of the double entendre the “company comes first” (Field 2014), is naturally extremely
important for any business. As an example, this success can mean a satisfied workforce, meeting the intended
business benefit or simply a positive learning outcome for the company. The main goal of a business is “to make
money in the present as well as in the future” (Goldratt, Fox and Grasman 1986). Thus, it could be argued that a
project success is closely connected with the company’s success. Particularly, it is crucial that the project is aligned
with the strategy of the organisation. That is one of the tasks of the project manager: to make sure that the project
is leading to an improvement for the company in one way or another. ProjectManagement could, for example,
keep track of data regarding projects that were successful and use that to improve the next project. In fact, that is
what Lean proposes as well with their continuous improvement philosophy. Proper documentation should be
kept by project managers (Todorovic et al. 2015) in order to keep records and make it possible to analyse the data
at a later stage. Regarding the satisfied workforce, Lean is considered to improve the process flow along with the
employee morale (Mor, Singh and Bhardwaj 2016) by promoting transparency over the project (Eskerod and Riis
2009), standardisation of the tools and methods (H.McManus andMillard 2004), and training employees (Garza
2005). Likewise, in ProjectManagement one of the crucial tasks is to keep the team members in consideration.
This includes assigning new tasks to people that have been doing the same task repeatedly, making the work more
enjoyable and generally being creative in dealing with the complexity of the human nature.&lt;/p&gt;

&lt;h2 id=&quot;safety&quot;&gt;Safety&lt;/h2&gt;

&lt;p&gt;In terms of meeting the safety standards,Mor, Singh and Bhardwaj (2016) state that these are not usually taken
into account by Lean. This interpretation contrasts with that of (Aziz and Hafez 2013) who argue that if Lean
is implemented correctly it will lead to “dramatic improvements in safety”. The reason being that Lean is a
continuous improvement philosophy, in the pursue of perfection, and therefore will advocate that a non-safe
environment is not perfect and should be eliminated. In other words, danger should be considered a waste
because it does not add any value whereas safety does.
Regarding ProjectManagement, it attempts to deal with safety issues by creating a health and safety policy that
seeks to prevent accidents from happening (Robson et al. 2007). In spite of the fact that these concerns arise
further down the product life cycle than the design stage, it is important to have them in mind during the whole
product development process. Furthermore, PM uses tools and methods to measure and confirm that the health
and safety policy is being effective. These can involve inspections, an evaluation of the performance of the health
and safety policy and frequent audits (Helmreich, Klinect andWilhelm 2017; Zhou, Bai and Sun 2014).&lt;/p&gt;

&lt;h2 id=&quot;sustainability&quot;&gt;Sustainability&lt;/h2&gt;

&lt;p&gt;Sustainability is increasingly becoming one of the most important topics of discussion for businesses worldwide
(Silvius et al. 2012). Therefore, it is crucial for a business to be aware of social and environmental issues
when developing a product. As far as Lean is concerned, the organisation should include environmental waste as
part of other Lean wastes and leverage it in order to take aim at “environmental ‘blind spots’ ” that occur with
fixed expenses or indirect costs of running a business (Mor, Singh and Bhardwaj 2016). With respect to Project
Management, it is necessary to seek a product development that guarantees that the outputs, outcomes and
benefits of the project are sustainable during the product life cycle and also during product development.&lt;/p&gt;

&lt;h2 id=&quot;references&quot;&gt;References&lt;/h2&gt;

&lt;p&gt;&lt;small&gt;Aziz, Remon Fayek and Sherif Mohamed Hafez (2013). ‘Applying lean thinking in construction and performance
improvement’. In: Alexandria Engineering Journal 52.4. issn: 1110-0168.&lt;/small&gt;&lt;/p&gt;

&lt;p&gt;&lt;small&gt;Eskerod, Pernille and Eva Riis (2009). ‘Project management models as value creators’. In: Project Management
Journal 40.1, pp. 4–18.&lt;/small&gt;&lt;/p&gt;

&lt;p&gt;&lt;small&gt;Field, Tim (2014). ‘ToxicWork Environment’. In: Mental Illness in the Workplace: Psychological Disability Management
207.&lt;/small&gt;&lt;/p&gt;

&lt;p&gt;&lt;small&gt;Garza, Laura A (2005). ‘Integrating lean principles in automotive product development: breaking down barriers in
culture and process’. PhD thesis. Massachusetts Institute of Technology.&lt;/small&gt;&lt;/p&gt;

&lt;p&gt;&lt;small&gt;Goldratt, Eliyahu M, Robert E Fox and Gerard Grasman (1986). The race. Vol. 179. North river press Croton-on-Hudson, NY.&lt;/small&gt;&lt;/p&gt;

&lt;p&gt;&lt;small&gt;Helmreich, Robert L, James R Klinect and John AWilhelm (2017). ‘System safety and threat and error management:
The line operational safety audit (losa)’. In: Proceedings of the Eleventh International Symposium on Aviation
Psychology.&lt;/small&gt;&lt;/p&gt;

&lt;p&gt;&lt;small&gt;Lim, CS and M Zain Mohamed (1999). ‘Criteria of project success: an exploratory re-examination’. In: International
journal of project management 17.4, pp. 243–248.&lt;/small&gt;&lt;/p&gt;

&lt;p&gt;&lt;small&gt;McManus, Hugh and Richard Millard (2004). ‘Value stream analysis and mapping for product development’.&lt;/small&gt;&lt;/p&gt;

&lt;p&gt;&lt;small&gt;Mor, Rahul S, Sarbjit Singh and Arvind Bhardwaj (2016). ‘Learning on Lean Production: A Review of Opinion and
Research within Environmental Constraints’. In: Operations and Supply ChainManagement: An International
Journal 9.1, pp. 61–72.&lt;/small&gt;&lt;/p&gt;

&lt;p&gt;&lt;small&gt;Ogunlana, Stephen O et al. (2010). ‘Beyond the ‘iron triangle’: Stakeholder perception of key performance indicators
(KPIs) for large-scale public sector development projects’. In: International journal of project management
28.3, pp. 228–236.&lt;/small&gt;&lt;/p&gt;

&lt;p&gt;&lt;small&gt;Olsen, Richard Paul (1971). ‘Can project management be defined?’ In: ProjectManagement Institute.&lt;/small&gt;&lt;/p&gt;

&lt;p&gt;&lt;small&gt;Oppenheim, Bohdan W (2004). ‘Lean product development flow’. In: Systems engineering 7.4.&lt;/small&gt;&lt;/p&gt;

&lt;p&gt;&lt;small&gt;Oppenheim, Bohdan W, Earll M Murman and Deborah A Secor (2011). ‘Lean enablers for systems engineering’.
In: Systems Engineering 14.1, pp. 29–55.&lt;/small&gt;&lt;/p&gt;

&lt;p&gt;&lt;small&gt;Project Management Institute (2013). A guide to the project management body of knowledge (PMBOK® Guide).
Fifth Edition. Newtown Square, Pennsylvania: Project Management Institute.&lt;/small&gt;&lt;/p&gt;

&lt;p&gt;&lt;small&gt;Rad, Parviz F (2002). Project estimating and cost management. Management Concepts Incorporated.&lt;/small&gt;&lt;/p&gt;

&lt;p&gt;&lt;small&gt;Robson, Lynda S et al. (2007). ‘The effectiveness of occupational health and safety management system interventions: a systematic review’. In: Safety Science 45.3, pp. 329–353.&lt;/small&gt;&lt;/p&gt;

&lt;p&gt;&lt;small&gt;Schwaber, Ken (2004). Agile project management with Scrum. Microsoft press.&lt;/small&gt;&lt;/p&gt;

&lt;p&gt;&lt;small&gt;Silvius, Gilbert et al. (2012). Sustainability in project management. Gower Publishing, Ltd.&lt;/small&gt;&lt;/p&gt;

&lt;p&gt;&lt;small&gt;Todorovic, Marija Lj et al. (2015). ‘Project success analysis framework: A knowledge-based approach in project
management’. In: International Journal of ProjectManagement 33.4, pp. 772–783.&lt;/small&gt;&lt;/p&gt;

&lt;p&gt;&lt;small&gt;Wilson, James M (2003). ‘Gantt charts: A centenary appreciation’. In: European Journal of Operational Research
149.2, pp. 430–437.&lt;/small&gt;&lt;/p&gt;

&lt;p&gt;&lt;small&gt;Zhou, Jian-Lan, Ze-HuaBai and Zhi-Yu Sun (2014). ‘A hybrid approach for safety assessment in high-risk hydro power construction-
project work systems’. In: Safety Science 64, pp. 163–172.&lt;/small&gt;&lt;/p&gt;

    &lt;p&gt;&lt;a href=&quot;https://luisramalho.com/lean-thinking-vs-project-management&quot;&gt;Lean Thinking versus Project Management&lt;/a&gt; was originally published by Luís Ramalho at &lt;a href=&quot;https://luisramalho.com&quot;&gt;Luís Ramalho&lt;/a&gt; on September 02, 2018.&lt;/p&gt;
  </content>
</entry>


<entry>
  <title type="html"><![CDATA[Lean Thinking for New Product Introduction]]></title>
  <link rel="alternate" type="text/html" href="https://luisramalho.com/lean-thinking-for-new-product-introduction" />
  <id>https://luisramalho.com/lean-thinking-for-new-product-introduction</id>
  <published>2018-08-31T00:00:00+00:00</published>
  <updated>2018-08-31T00:00:00+00:00</updated>
  <author>
    <name>Luís Ramalho</name>
    <uri>https://luisramalho.com</uri>
    
  </author>
  <content type="html">
    &lt;p&gt;In this post I will give an overview of the Lean Philosophy and cover a few essential topics:&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;Value vs Waste ( Ohno’s seven wastes; Non-Value Adding (NVA) and Essential Non-Value Adding (ENVA); and Muda, Mura and Muri)&lt;/li&gt;
  &lt;li&gt;5Cs&lt;/li&gt;
  &lt;li&gt;Visual Control&lt;/li&gt;
  &lt;li&gt;Value-stream mapping and analysis&lt;/li&gt;
&lt;/ul&gt;

&lt;iframe width=&quot;560&quot; height=&quot;315&quot; src=&quot;https://youtube.com/embed/LMxN7Z0aDNg&quot; frameborder=&quot;0&quot; allow=&quot;autoplay; encrypted-media&quot; allowfullscreen=&quot;&quot;&gt;&lt;/iframe&gt;
&lt;p&gt;&lt;br /&gt;&lt;/p&gt;

&lt;p&gt;Lean was initially defined by Womack, Jones and Roos (1990) as an integrated way of eliminating waste in order
for every step in every process to add value for the customer. It has five principles that were described by Womack
and Jones (1996) as:&lt;/p&gt;
&lt;ol&gt;
  &lt;li&gt;specify value;&lt;/li&gt;
  &lt;li&gt;identify the value stream and eliminate waste;&lt;/li&gt;
  &lt;li&gt;make the value flow;&lt;/li&gt;
  &lt;li&gt;let the customer pull the (value) process; and&lt;/li&gt;
  &lt;li&gt;pursue perfection.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;The advantage of these five principles
is that they give the organisation a road map to more plainly apply the Lean Thinking philosophy to a business
process (Haque and James-Moore 2004). Furthermore, these principles also meet the improvement cycle defined
by Deming; &lt;em&gt;plan–do–check–adjust&lt;/em&gt; (Deming 2000). These Deming’s four steps are used for the control and
continuous improvement of business processes, which is identical to what Lean proposes.&lt;/p&gt;

&lt;p&gt;Generally, there are two main terms to clarify in order to understand the lean philosophy: value and waste.&lt;/p&gt;

&lt;h2 id=&quot;value&quot;&gt;Value&lt;/h2&gt;
&lt;p&gt;Value can be described as something that meets the customer’s needs at a particular time and price, in other words, it
is what matters to the customer.&lt;/p&gt;

&lt;h2 id=&quot;waste&quot;&gt;Waste&lt;/h2&gt;

&lt;p&gt;Waste was defined by Fujio Cho, the former President of Toyota, as “anything
other than the minimum amount of equipment, materials, parts, space, and worker’s time, which are absolutely
essential to add value to the product” (Suzaki 1987).&lt;/p&gt;

&lt;p&gt;The types of waste may further be divided into six main types that have been identified in the literature, these
types may then be grouped into three broad waste types, which are: (1) Ohno’s seven wastes; (2) Non-Value
Adding (NVA) and Essential Non-Value Adding (ENVA); and (3) Muda, Mura and Muri.&lt;/p&gt;

&lt;h3 id=&quot;1-ohnos-seven-wastes&quot;&gt;1. Ohno’s seven wastes&lt;/h3&gt;

&lt;p&gt;Firstly, Ohno’s seven types of waste were suggested by Toyota Chief Engineer Taiichi Ohno as part of the Toyota Production System (TPS). These types of waste of an organisation were the following: over-production, delays or waiting, transportation, unsuitable processing, inventory, unnecessary movement, and defects (Ohno et al. 1987).&lt;/p&gt;

&lt;h3 id=&quot;2-non-value-adding-nva-and-essential-non-value-adding-enva&quot;&gt;2. Non-Value Adding (NVA) and Essential Non-Value Adding (ENVA)&lt;/h3&gt;

&lt;p&gt;Secondly, there are the Non-Value Adding (NVA) and Essential Non-Value Adding (ENVA) types of waste. On one hand, the activities that are Non-Value Adding can and should be eliminated because they do not add value to the customer and are not
essential. One the other hand, the Essential Non-Value Adding activities are those that in spite of the fact that do
not add any value to the customer cannot be eliminated. An example of the latter could be quality inspection,
therefore the organisation should try and standardise, or if possible automate, these activities.&lt;/p&gt;

&lt;h3 id=&quot;3-muda-mura-and-muri&quot;&gt;3. Muda, Mura and Muri&lt;/h3&gt;

&lt;p&gt;Finally, the last group consists of Muda, Mura and Muri. These are often called the 3Ms of Lean (Watanabe 2000) and have the
following meanings: Muda (waste or non-value adding actions), Mura (workload fluctuations or unevenness) and
Muri (overburden). An interesting fact about these types of waste is that if Mura and Muri are eliminated, then
Muda will not be created in the first place. Thus, a business should not directly focus on eliminating Muda but on
its prevention by solving Mura and Muri.&lt;/p&gt;

&lt;p&gt;In spite of the fact that Haque and James-Moore (2004) considered the use of Lean principles in New Product
Introduction (NPI) an unusual endeavour back in 2004, a literature review shows that manufacturing is still the
most dominant stage for the use of these principles. However, there are a variety of Lean tools and techniques
that can be used to help an organisation identify and eliminate waste as well as reduce the non-value-adding activities in the design stage of an NPI.&lt;/p&gt;

&lt;h2 id=&quot;5cs&quot;&gt;5Cs&lt;/h2&gt;

&lt;p&gt;Firstly, the 5C which is a five step technique to organise the workplace and is important in the design stage and subsequent delivery of the new product to customers. The reason being that it enforces a continuous improvement of the working environment by not only establishing a standard (Wheat, Mills and Carnell 2003, p. 44) but also by eliminating noise. The 5Cs are: (1) clear-out; (2) configure; (3) clean and check; (4) conformity; and (5) custom and practice. These were derived from the Japanese 5Ss which consist of: Seiri (sort), Seiton (straighten), Seiso (scrub), Seiketsu (systematize), Shitsuke (standardise).&lt;/p&gt;

&lt;h2 id=&quot;visual-control&quot;&gt;Visual Control&lt;/h2&gt;

&lt;p&gt;Secondly, visual control could be used in order to check that everything is going according to plan. These should be quick checks that ensure that everything is proceeding as well as it should. Haque and James-Moore (2004) add that these types of visual checks are very productive in recognising areas where complications might occur.&lt;/p&gt;

&lt;h2 id=&quot;value-stream-mapping-and-analysis&quot;&gt;Value-stream mapping and analysis&lt;/h2&gt;

&lt;p&gt;Thirdly, the value-stream mapping and analysis. It is also known as “material- and information-flow mapping” (Rother and
Shook 1998) and is a Lean tool that helps analyse and design the steps necessary for a product to go from the
current state to a successful deliver to the customer.&lt;/p&gt;

&lt;p&gt;One important point identified by Karlsson and Ahlström (1996) is that it is not enough for an organisation to simply implement the Lean techniques to reach the goal of Lean product development. In order to accomplish that the organisation needs to unite these seemingly isolated techniques as a whole process.&lt;/p&gt;

&lt;h1 id=&quot;references&quot;&gt;References&lt;/h1&gt;
&lt;p&gt;&lt;small&gt;Deming,William Edwards (2000). The new economics: for industry, government, education. MIT press.&lt;/small&gt;&lt;/p&gt;

&lt;p&gt;&lt;small&gt;Haque, Badr and Mike James-Moore (2004). ‘Applying lean thinking to new product introduction’. In: Journal of
Engineering design 15.1, pp. 1–31.&lt;/small&gt;&lt;/p&gt;

&lt;p&gt;&lt;small&gt;Karlsson, Christer and Pär Ahlström (1996). ‘The difficult path to lean product development’. In: Journal of product
innovation management 13.4, pp. 283–295.&lt;/small&gt;&lt;/p&gt;

&lt;p&gt;&lt;small&gt;Ohno, Taiichi et al. (1987). ‘The Toyota Production System’. PhD thesis.Monterey Institute of International Studies.&lt;/small&gt;&lt;/p&gt;

&lt;p&gt;&lt;small&gt;Rother,Mike and John Shook (1998). ‘Learning to See: Value StreamMapping to Create Value and EliminateMuda.
v. 1.1’. In: Oct., The Lean Enterprise Inst., Brookline,Mass.&lt;/small&gt;&lt;/p&gt;

&lt;p&gt;&lt;small&gt;Suzaki, Kiyoshi (1987). New manufacturing challenge: Techniques for continuous improvement. Simon and
Schuster.&lt;/small&gt;&lt;/p&gt;

&lt;p&gt;&lt;small&gt;Watanabe, Susumu (2000). ‘The Japan model and the future of employment and wage systems’. In: International
Labour Review 139.3, pp. 307–333.&lt;/small&gt;&lt;/p&gt;

&lt;p&gt;&lt;small&gt;Wheat, Barbara, ChuckMills andMike Carnell (2003). Leaning into Six Sigma: a parable of the journey to Six Sigma
and a lean enterprise.McGraw-Hill New York, NY.&lt;/small&gt;&lt;/p&gt;

&lt;p&gt;&lt;small&gt;Womack, James P and Daniel T Jones (1996). ‘Lean thinking: Banish waste and create wealth in your organisation’.
In: Simon and Shuster, New York, NY 397.&lt;/small&gt;&lt;/p&gt;

&lt;p&gt;&lt;small&gt;Womack, James P, Daniel T Jones and Daniel Roos (1990). Machine that changed the world. Simon and Schuster.
Zhou, Jian-Lan, Ze-HuaBai and Zhi-Yu Sun(2014). ‘A hybrid approach for safety assessment in high-risk hydropower construction-project work systems’. In: Safety Science 64, pp. 163–172.&lt;/small&gt;&lt;/p&gt;

    &lt;p&gt;&lt;a href=&quot;https://luisramalho.com/lean-thinking-for-new-product-introduction&quot;&gt;Lean Thinking for New Product Introduction&lt;/a&gt; was originally published by Luís Ramalho at &lt;a href=&quot;https://luisramalho.com&quot;&gt;Luís Ramalho&lt;/a&gt; on August 31, 2018.&lt;/p&gt;
  </content>
</entry>


<entry>
  <title type="html"><![CDATA[Project Euler — Problem 58]]></title>
  <link rel="alternate" type="text/html" href="https://luisramalho.com/project-euler-problem-58" />
  <id>https://luisramalho.com/project-euler-problem-58</id>
  <published>2016-08-21T00:00:00+00:00</published>
  <updated>2016-08-21T00:00:00+00:00</updated>
  <author>
    <name>Luís Ramalho</name>
    <uri>https://luisramalho.com</uri>
    
  </author>
  <content type="html">
    &lt;p&gt;&lt;a href=&quot;https://projecteuler.net/problem=58&quot;&gt;Spiral primes&lt;/a&gt; is a problem in which one must find the side length of the square spiral for which the ratio of primes along both diagonals first falls below 10%. More information on this spiral can be found on &lt;a href=&quot;http://en.wikipedia.org/wiki/Ulam_spiral&quot;&gt;Ulam spiral&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;In order to solve this problem I started by creating an &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;ArrayList&lt;/code&gt; of all the diagonal numbers and check for their primality. However, creating an &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;ArrayList&lt;/code&gt; from scratch for every loop was inefficient and soon I have implemented a method to return just the diagonal numbers for the current loop:&lt;/p&gt;

&lt;figure class=&quot;highlight&quot;&gt;&lt;pre&gt;&lt;code class=&quot;language-java&quot; data-lang=&quot;java&quot;&gt;&lt;span class=&quot;kd&quot;&gt;private&lt;/span&gt; &lt;span class=&quot;nc&quot;&gt;ArrayList&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;nc&quot;&gt;Integer&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;&amp;gt;&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;getDiagonalNumbersForLoop&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;kt&quot;&gt;int&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;n&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;{&lt;/span&gt;
    &lt;span class=&quot;nc&quot;&gt;ArrayList&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;nc&quot;&gt;Integer&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;&amp;gt;&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;diagonalNumbers&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;new&lt;/span&gt; &lt;span class=&quot;nc&quot;&gt;ArrayList&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;&amp;lt;&amp;gt;();&lt;/span&gt;
    &lt;span class=&quot;k&quot;&gt;if&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;n&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;&amp;lt;&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;return&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;diagonalNumbers&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;;&lt;/span&gt;

    &lt;span class=&quot;kt&quot;&gt;int&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;offset&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;n&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;*&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;2&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;-&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;2&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;;&lt;/span&gt;
    &lt;span class=&quot;kt&quot;&gt;int&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;currentDiagonalNumber&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;getFirstDiagonal&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;n&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;);&lt;/span&gt;
    &lt;span class=&quot;kt&quot;&gt;int&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;lastDiagonalNumber&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;getLastDiagonal&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;n&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;);&lt;/span&gt;

    &lt;span class=&quot;n&quot;&gt;diagonalNumbers&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;add&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;currentDiagonalNumber&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;);&lt;/span&gt;
    &lt;span class=&quot;k&quot;&gt;while&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;currentDiagonalNumber&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;!=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;lastDiagonalNumber&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;{&lt;/span&gt;
        &lt;span class=&quot;n&quot;&gt;currentDiagonalNumber&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;+=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;offset&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;;&lt;/span&gt;
        &lt;span class=&quot;n&quot;&gt;diagonalNumbers&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;add&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;currentDiagonalNumber&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;);&lt;/span&gt;
    &lt;span class=&quot;o&quot;&gt;}&lt;/span&gt;

    &lt;span class=&quot;k&quot;&gt;return&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;diagonalNumbers&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;o&quot;&gt;}&lt;/span&gt;

&lt;span class=&quot;kd&quot;&gt;private&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;int&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;getFirstDiagonal&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;kt&quot;&gt;int&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;n&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;{&lt;/span&gt;
    &lt;span class=&quot;k&quot;&gt;return&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;getLastDiagonal&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;n&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;-&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;n&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;-&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;*&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;6&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;o&quot;&gt;}&lt;/span&gt;

&lt;span class=&quot;kd&quot;&gt;private&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;int&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;getLastDiagonal&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;kt&quot;&gt;int&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;n&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;{&lt;/span&gt;
    &lt;span class=&quot;kt&quot;&gt;int&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;sideLength&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;n&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;*&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;2&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;-&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;;&lt;/span&gt;
    &lt;span class=&quot;k&quot;&gt;return&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;sideLength&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;*&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;sideLength&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;o&quot;&gt;}&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/figure&gt;

&lt;p&gt;The &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;getLastDiagonal()&lt;/code&gt; returns the bottom right diagonal number in the square spiral, so for &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;n = 2&lt;/code&gt; it returns 9. Afterwards it is straight forward to obtain the first diagonal number with the method &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;getFirstDiagonal()&lt;/code&gt;, so we get 3 as the first diagonal number in the second spiral square.&lt;/p&gt;

&lt;p&gt;Having the first and last diagonal numbers, and the offset between each diagonal number in a certain size &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;n&lt;/code&gt; square spiral makes it easy to return all the diagonal numbers.&lt;/p&gt;

&lt;p&gt;Thus, one just needs to accumulate the number of primes as we keep adding square spirals and divide by the total number of diagonal numbers.&lt;/p&gt;

&lt;figure class=&quot;highlight&quot;&gt;&lt;pre&gt;&lt;code class=&quot;language-java&quot; data-lang=&quot;java&quot;&gt;&lt;span class=&quot;kd&quot;&gt;public&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;int&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;solution&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;()&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;{&lt;/span&gt;
    &lt;span class=&quot;kt&quot;&gt;int&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;primes&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;;&lt;/span&gt;
    &lt;span class=&quot;kt&quot;&gt;double&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;diagonalNumbers&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;;&lt;/span&gt;
    &lt;span class=&quot;kt&quot;&gt;double&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;percentageOfPrimes&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;100&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;;&lt;/span&gt;
    &lt;span class=&quot;nc&quot;&gt;ArrayList&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;nc&quot;&gt;Integer&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;&amp;gt;&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;numbers&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;;&lt;/span&gt;

    &lt;span class=&quot;kt&quot;&gt;int&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;count&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;2&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;;&lt;/span&gt;
    &lt;span class=&quot;k&quot;&gt;while&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;percentageOfPrimes&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;&amp;gt;&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;10&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;{&lt;/span&gt;
        &lt;span class=&quot;n&quot;&gt;numbers&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;getDiagonalNumbersForLoop&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;count&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;);&lt;/span&gt;
        &lt;span class=&quot;n&quot;&gt;diagonalNumbers&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;kt&quot;&gt;double&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;count&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;*&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;4&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;-&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;3&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;);&lt;/span&gt;
        &lt;span class=&quot;n&quot;&gt;primes&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;+=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;getNumberOfPrimes&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;numbers&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;);&lt;/span&gt;
        &lt;span class=&quot;n&quot;&gt;percentageOfPrimes&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;primes&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;/&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;diagonalNumbers&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;*&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;100&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;;&lt;/span&gt;
        &lt;span class=&quot;n&quot;&gt;count&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;++;&lt;/span&gt;
    &lt;span class=&quot;o&quot;&gt;}&lt;/span&gt;
    &lt;span class=&quot;k&quot;&gt;return&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;count&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;-&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;*&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;2&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;-&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;o&quot;&gt;}&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/figure&gt;

&lt;p&gt;Took: 136ms.&lt;/p&gt;

&lt;p&gt;The full solution can be found &lt;a href=&quot;https://github.com/luisramalho/euler/blob/master/Problem058.java&quot;&gt;here&lt;/a&gt;.&lt;/p&gt;

    &lt;p&gt;&lt;a href=&quot;https://luisramalho.com/project-euler-problem-58&quot;&gt;Project Euler — Problem 58&lt;/a&gt; was originally published by Luís Ramalho at &lt;a href=&quot;https://luisramalho.com&quot;&gt;Luís Ramalho&lt;/a&gt; on August 21, 2016.&lt;/p&gt;
  </content>
</entry>


<entry>
  <title type="html"><![CDATA[Project Euler — Problem 57]]></title>
  <link rel="alternate" type="text/html" href="https://luisramalho.com/project-euler-problem-57" />
  <id>https://luisramalho.com/project-euler-problem-57</id>
  <published>2014-11-19T00:00:00+00:00</published>
  <updated>2014-11-19T00:00:00+00:00</updated>
  <author>
    <name>Luís Ramalho</name>
    <uri>https://luisramalho.com</uri>
    
  </author>
  <content type="html">
    &lt;p&gt;&lt;a href=&quot;https://projecteuler.net/problem=57&quot;&gt;Square root convergents&lt;/a&gt; is a problem in which one must find how many fractions of the square root of 2 contain a numerator with more digits than denominator.&lt;/p&gt;

&lt;p&gt;Since we are dealing with big numbers, we should use &lt;a href=&quot;https://docs.oracle.com/javase/7/docs/api/java/math/BigInteger.html&quot;&gt;BigIntegers&lt;/a&gt;. Then, I looked for a pattern since we are given the first 8 iterations.&lt;/p&gt;

&lt;p&gt;Respectively: \(\frac{3}{2}\),
\(\frac{7}{5}\),
\(\frac{17}{12}\),
\(\frac{41}{29}\),
\(\frac{99}{70}\),
\(\frac{239}{169}\),
\(\frac{577}{408}\),
\(\frac{1393}{985}\)&lt;/p&gt;

&lt;p&gt;I found one that applied for both the numerator and denominator:&lt;/p&gt;

&lt;script type=&quot;math/tex; mode=display&quot;&gt;n_{k+1} = 2\cdot n_k + n_{k-1}&lt;/script&gt;

&lt;script type=&quot;math/tex; mode=display&quot;&gt;d_{k+1} = 2\cdot d_k + d_{k-1}&lt;/script&gt;

&lt;p&gt;Afterwards, it was trivial to code the solution:&lt;/p&gt;

&lt;figure class=&quot;highlight&quot;&gt;&lt;pre&gt;&lt;code class=&quot;language-java&quot; data-lang=&quot;java&quot;&gt;&lt;span class=&quot;nc&quot;&gt;ArrayList&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;nc&quot;&gt;BigInteger&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;&amp;gt;&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;n&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;new&lt;/span&gt; &lt;span class=&quot;nc&quot;&gt;ArrayList&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;&amp;lt;&amp;gt;();&lt;/span&gt;
&lt;span class=&quot;n&quot;&gt;n&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;add&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nc&quot;&gt;BigInteger&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;valueOf&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;3&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;));&lt;/span&gt; &lt;span class=&quot;c1&quot;&gt;// first numerator&lt;/span&gt;
&lt;span class=&quot;n&quot;&gt;n&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;add&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nc&quot;&gt;BigInteger&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;valueOf&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;7&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;));&lt;/span&gt; &lt;span class=&quot;c1&quot;&gt;// second numerator&lt;/span&gt;

&lt;span class=&quot;nc&quot;&gt;ArrayList&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;nc&quot;&gt;BigInteger&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;&amp;gt;&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;d&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;new&lt;/span&gt; &lt;span class=&quot;nc&quot;&gt;ArrayList&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;&amp;lt;&amp;gt;();&lt;/span&gt;
&lt;span class=&quot;n&quot;&gt;d&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;add&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nc&quot;&gt;BigInteger&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;valueOf&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;2&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;));&lt;/span&gt; &lt;span class=&quot;c1&quot;&gt;// first denominator&lt;/span&gt;
&lt;span class=&quot;n&quot;&gt;d&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;add&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nc&quot;&gt;BigInteger&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;valueOf&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;5&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;));&lt;/span&gt; &lt;span class=&quot;c1&quot;&gt;// second denominator&lt;/span&gt;

&lt;span class=&quot;nc&quot;&gt;BigInteger&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;two&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;nc&quot;&gt;BigInteger&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;valueOf&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;2&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;);&lt;/span&gt;
&lt;span class=&quot;k&quot;&gt;for&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;kt&quot;&gt;int&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;i&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;;&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;i&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;&amp;lt;&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;1000&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;;&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;i&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;++)&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;{&lt;/span&gt;
    &lt;span class=&quot;n&quot;&gt;n&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;add&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;n&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;get&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;i&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;).&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;multiply&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;two&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;).&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;add&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;n&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;get&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;i&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;-&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;)));&lt;/span&gt;
    &lt;span class=&quot;n&quot;&gt;d&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;add&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;d&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;get&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;i&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;).&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;multiply&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;two&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;).&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;add&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;d&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;get&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;i&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;-&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;)));&lt;/span&gt;
&lt;span class=&quot;o&quot;&gt;}&lt;/span&gt;

&lt;span class=&quot;kt&quot;&gt;int&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;count&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;k&quot;&gt;for&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;kt&quot;&gt;int&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;i&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;;&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;i&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;&amp;lt;&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;n&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;size&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;();&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;i&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;++)&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;{&lt;/span&gt;
    &lt;span class=&quot;k&quot;&gt;if&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;n&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;get&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;i&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;).&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;toString&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;().&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;length&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;()&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;&amp;gt;&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;d&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;get&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;i&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;).&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;toString&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;().&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;length&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;())&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;{&lt;/span&gt;
        &lt;span class=&quot;n&quot;&gt;count&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;++;&lt;/span&gt;
    &lt;span class=&quot;o&quot;&gt;}&lt;/span&gt;
&lt;span class=&quot;o&quot;&gt;}&lt;/span&gt;

&lt;span class=&quot;k&quot;&gt;return&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;count&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/figure&gt;

&lt;p&gt;The full solution can be found &lt;a href=&quot;https://github.com/luisramalho/euler/blob/master/Problem057.java&quot;&gt;here&lt;/a&gt;.&lt;/p&gt;

    &lt;p&gt;&lt;a href=&quot;https://luisramalho.com/project-euler-problem-57&quot;&gt;Project Euler — Problem 57&lt;/a&gt; was originally published by Luís Ramalho at &lt;a href=&quot;https://luisramalho.com&quot;&gt;Luís Ramalho&lt;/a&gt; on November 19, 2014.&lt;/p&gt;
  </content>
</entry>


<entry>
  <title type="html"><![CDATA[Project Euler — Problem 56]]></title>
  <link rel="alternate" type="text/html" href="https://luisramalho.com/project-euler-problem-56" />
  <id>https://luisramalho.com/project-euler-problem-56</id>
  <published>2014-11-18T00:00:00+00:00</published>
  <updated>2014-11-18T00:00:00+00:00</updated>
  <author>
    <name>Luís Ramalho</name>
    <uri>https://luisramalho.com</uri>
    
  </author>
  <content type="html">
    &lt;p&gt;&lt;a href=&quot;https://projecteuler.net/problem=56&quot;&gt;Powerful digit sum&lt;/a&gt; is a problem in which one must find the maximum digital sum considering natural numbers of the form, a^b, where a, b &amp;lt; 100.&lt;/p&gt;

&lt;p&gt;Since we are dealing with big numbers, we should use &lt;a href=&quot;https://docs.oracle.com/javase/7/docs/api/java/math/BigInteger.html&quot;&gt;BigIntegers&lt;/a&gt;. This library has the method &lt;a href=&quot;https://docs.oracle.com/javase/7/docs/api/java/math/BigInteger.html#pow(int)&quot;&gt;pow()&lt;/a&gt; which makes our life easier when calculating powers of BigIntegers.&lt;/p&gt;

&lt;figure class=&quot;highlight&quot;&gt;&lt;pre&gt;&lt;code class=&quot;language-java&quot; data-lang=&quot;java&quot;&gt;&lt;span class=&quot;kt&quot;&gt;int&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;max&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;nc&quot;&gt;BigInteger&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;n&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;k&quot;&gt;for&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;kt&quot;&gt;int&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;a&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;;&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;a&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;&amp;lt;&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;100&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;;&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;a&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;++)&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;{&lt;/span&gt;
    &lt;span class=&quot;k&quot;&gt;for&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;kt&quot;&gt;int&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;b&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;;&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;b&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;&amp;lt;&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;100&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;;&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;b&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;++)&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;{&lt;/span&gt;
        &lt;span class=&quot;n&quot;&gt;n&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;nc&quot;&gt;BigInteger&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;valueOf&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;a&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;).&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;pow&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;b&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;);&lt;/span&gt;
        &lt;span class=&quot;n&quot;&gt;max&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;nc&quot;&gt;Math&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;max&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;digitalSum&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;n&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;),&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;max&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;);&lt;/span&gt;
    &lt;span class=&quot;o&quot;&gt;}&lt;/span&gt;
&lt;span class=&quot;o&quot;&gt;}&lt;/span&gt;
&lt;span class=&quot;k&quot;&gt;return&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;max&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/figure&gt;

&lt;p&gt;Then, it is just a matter of calculating the sum of all the digits in the BigInteger, and returning the maximum.&lt;/p&gt;

&lt;figure class=&quot;highlight&quot;&gt;&lt;pre&gt;&lt;code class=&quot;language-java&quot; data-lang=&quot;java&quot;&gt;&lt;span class=&quot;kt&quot;&gt;int&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;sum&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;nc&quot;&gt;String&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;digits&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;n&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;toString&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;();&lt;/span&gt;
&lt;span class=&quot;k&quot;&gt;for&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;kt&quot;&gt;int&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;i&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;;&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;i&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;&amp;lt;&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;digits&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;length&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;();&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;i&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;++)&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;{&lt;/span&gt;
    &lt;span class=&quot;n&quot;&gt;sum&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;+=&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;kt&quot;&gt;int&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;digits&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;charAt&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;i&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;-&lt;/span&gt; &lt;span class=&quot;sc&quot;&gt;'0'&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;o&quot;&gt;}&lt;/span&gt;
&lt;span class=&quot;k&quot;&gt;return&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;sum&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/figure&gt;

&lt;p&gt;The full solution can be found &lt;a href=&quot;https://github.com/luisramalho/euler/blob/master/Problem056.java&quot;&gt;here&lt;/a&gt;.&lt;/p&gt;

    &lt;p&gt;&lt;a href=&quot;https://luisramalho.com/project-euler-problem-56&quot;&gt;Project Euler — Problem 56&lt;/a&gt; was originally published by Luís Ramalho at &lt;a href=&quot;https://luisramalho.com&quot;&gt;Luís Ramalho&lt;/a&gt; on November 18, 2014.&lt;/p&gt;
  </content>
</entry>


<entry>
  <title type="html"><![CDATA[Project Euler — Problem 55]]></title>
  <link rel="alternate" type="text/html" href="https://luisramalho.com/project-euler-problem-55" />
  <id>https://luisramalho.com/project-euler-problem-55</id>
  <published>2014-11-17T00:00:00+00:00</published>
  <updated>2014-11-17T00:00:00+00:00</updated>
  <author>
    <name>Luís Ramalho</name>
    <uri>https://luisramalho.com</uri>
    
  </author>
  <content type="html">
    &lt;p&gt;&lt;a href=&quot;https://projecteuler.net/problem=55&quot;&gt;Lychrel numbers&lt;/a&gt; is a problem in which one must find how many Lychrel numbers are there below ten-thousand. You can read &lt;a href=&quot;http://en.wikipedia.org/wiki/Lychrel_number&quot;&gt;here&lt;/a&gt; more about Lychrel numbers.&lt;/p&gt;

&lt;p&gt;It was clear since the beginning that we would be dealing with large numbers, so my approach was to use &lt;a href=&quot;https://docs.oracle.com/javase/7/docs/api/java/math/BigInteger.html&quot;&gt;BigIntegers&lt;/a&gt;.&lt;/p&gt;

&lt;figure class=&quot;highlight&quot;&gt;&lt;pre&gt;&lt;code class=&quot;language-java&quot; data-lang=&quot;java&quot;&gt;&lt;span class=&quot;kt&quot;&gt;int&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;lychrelNumbers&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;kt&quot;&gt;int&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;i&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;nc&quot;&gt;BigInteger&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;temp&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;nc&quot;&gt;BigInteger&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;one&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;nc&quot;&gt;BigInteger&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;ONE&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;nc&quot;&gt;BigInteger&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;b&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;new&lt;/span&gt; &lt;span class=&quot;nc&quot;&gt;BigInteger&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;10&quot;&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;);&lt;/span&gt;
&lt;span class=&quot;nc&quot;&gt;BigInteger&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;limit&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;new&lt;/span&gt; &lt;span class=&quot;nc&quot;&gt;BigInteger&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;10000&quot;&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;);&lt;/span&gt;
&lt;span class=&quot;k&quot;&gt;for&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;(;&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;b&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;compareTo&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;limit&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;&amp;lt;&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;;&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;b&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;b&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;add&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;one&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;),&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;i&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;{&lt;/span&gt;
    &lt;span class=&quot;n&quot;&gt;temp&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;b&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;;&lt;/span&gt;
    &lt;span class=&quot;k&quot;&gt;do&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;{&lt;/span&gt;
        &lt;span class=&quot;n&quot;&gt;temp&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;temp&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;add&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;reverse&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;temp&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;));&lt;/span&gt;
        &lt;span class=&quot;n&quot;&gt;i&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;++;&lt;/span&gt;
    &lt;span class=&quot;o&quot;&gt;}&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;while&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;(!&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;isPalindrome&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;temp&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;toString&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;())&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;&amp;amp;&amp;amp;&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;i&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;&amp;lt;&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;50&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;);&lt;/span&gt;

    &lt;span class=&quot;c1&quot;&gt;// Lychrel number&lt;/span&gt;
    &lt;span class=&quot;k&quot;&gt;if&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;i&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;==&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;50&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;{&lt;/span&gt;
        &lt;span class=&quot;n&quot;&gt;lychrelNumbers&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;++;&lt;/span&gt;
    &lt;span class=&quot;o&quot;&gt;}&lt;/span&gt;
&lt;span class=&quot;o&quot;&gt;}&lt;/span&gt;
&lt;span class=&quot;k&quot;&gt;return&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;lychrelNumbers&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/figure&gt;

&lt;p&gt;I started with 10 because 0 to 9 are palindromes. Inside the for loop we check if the addition of a number with it’s reverse is a palindrome for a maximum of 49 times. If not, then we got a Lychrel numbers.&lt;/p&gt;

&lt;p&gt;The full solution can be found &lt;a href=&quot;https://github.com/luisramalho/euler/blob/master/Problem055.java&quot;&gt;here&lt;/a&gt;.&lt;/p&gt;

    &lt;p&gt;&lt;a href=&quot;https://luisramalho.com/project-euler-problem-55&quot;&gt;Project Euler — Problem 55&lt;/a&gt; was originally published by Luís Ramalho at &lt;a href=&quot;https://luisramalho.com&quot;&gt;Luís Ramalho&lt;/a&gt; on November 17, 2014.&lt;/p&gt;
  </content>
</entry>


<entry>
  <title type="html"><![CDATA[An internal error occurred during&#58; "IvyDE resolve".]]></title>
  <link rel="alternate" type="text/html" href="https://luisramalho.com/vaadin-ivyde-resolve" />
  <id>https://luisramalho.com/vaadin-ivyde-resolve</id>
  <published>2014-11-13T00:00:00+00:00</published>
  <updated>2014-11-13T00:00:00+00:00</updated>
  <author>
    <name>Luís Ramalho</name>
    <uri>https://luisramalho.com</uri>
    
  </author>
  <content type="html">
    &lt;p&gt;If you’re trying to run Vaadin by following &lt;a href=&quot;https://github.com/vaadin/vaadin#setting-up-eclipse-to-develop-vaadin-7&quot;&gt;this&lt;/a&gt; and using Eclipse 4.4.1 it is likely that you will get the following error message:&lt;/p&gt;

&lt;!-- ![Vaadin IvyDE Error](https://luisramalho.com/assets/vaadin-error-1.png &quot;Vaadin IvyDE Error&quot;) --&gt;

&lt;blockquote&gt;
  &lt;p&gt;An internal error occurred during: “IvyDE resolve”.
org.eclipse.osgi.internal.framework.EquinoxConfiguration$1 cannot be cast to java.lang.String&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;The problem is totally on IvyDE’s side and has already been &lt;a href=&quot;https://issues.apache.org/jira/browse/IVY-1487&quot;&gt;documented&lt;/a&gt; and a fix has been &lt;a href=&quot;https://github.com/apache/ant-ivy/commit/81fec3193ad12a0f78eb021c4a1548484595860b&quot;&gt;merged&lt;/a&gt;. Nonetheless, it is still not available in the official update site &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;http://apache.org/dist/ant/ivyde/updatesite&lt;/code&gt;. Thus, if you want to fix this issue you can use the &lt;a href=&quot;http://ant.apache.org/ivy/ivyde/download.cgi#jenkins&quot;&gt;trunk version&lt;/a&gt; of IvyDE.&lt;/p&gt;

&lt;p&gt;Go to &lt;em&gt;Help &amp;gt; Install New Software…&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;https://luisramalho.com/assets/vaadin-error-2.png&quot; alt=&quot;Install New Software&quot; title=&quot;Install New Software&quot; /&gt;&lt;/p&gt;

&lt;p&gt;Then enter &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;https://builds.apache.org/job/IvyDE-updatesite/lastSuccessfulBuild/artifact/trunk/build/&lt;/code&gt; in the &lt;em&gt;Work with:&lt;/em&gt; field.&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;https://luisramalho.com/assets/vaadin-error-3.png&quot; alt=&quot;Install New Software&quot; title=&quot;Install New Software&quot; /&gt;&lt;/p&gt;

&lt;p&gt;Finally, select &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;Apache Ivy Library&lt;/code&gt; and click Finnish.&lt;/p&gt;

&lt;p&gt;Now you can import the Vaadin project, or if that was already done you can resolve the issues by using the options on vaadin project and choosing &lt;em&gt;Ivy &amp;gt; Resolve&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;https://luisramalho.com/assets/vaadin-error-4.png&quot; alt=&quot;Ivy Resolve&quot; title=&quot;Ivy Resolve&quot; /&gt;&lt;/p&gt;

&lt;p&gt;Have fun with Vaadin!&lt;/p&gt;

    &lt;p&gt;&lt;a href=&quot;https://luisramalho.com/vaadin-ivyde-resolve&quot;&gt;An internal error occurred during&amp;#58; &quot;IvyDE resolve&quot;.&lt;/a&gt; was originally published by Luís Ramalho at &lt;a href=&quot;https://luisramalho.com&quot;&gt;Luís Ramalho&lt;/a&gt; on November 13, 2014.&lt;/p&gt;
  </content>
</entry>


<entry>
  <title type="html"><![CDATA[Project Euler — Problem 52]]></title>
  <link rel="alternate" type="text/html" href="https://luisramalho.com/project-euler-problem-52" />
  <id>https://luisramalho.com/project-euler-problem-52</id>
  <published>2014-11-13T00:00:00+00:00</published>
  <updated>2014-11-13T00:00:00+00:00</updated>
  <author>
    <name>Luís Ramalho</name>
    <uri>https://luisramalho.com</uri>
    
  </author>
  <content type="html">
    &lt;p&gt;&lt;a href=&quot;https://projecteuler.net/problem=52&quot;&gt;Permuted multiples&lt;/a&gt; is a problem in which one must find the smallest positive integer, x, such that 2x, 3x, 4x, 5x, and 6x, contain the same digits.&lt;/p&gt;

&lt;p&gt;A brute-force solution is to just loop through integers until 2x, 3x, 4x, 5x, and 6x are permuations of one another, when that happens we have found our integer.&lt;/p&gt;

&lt;figure class=&quot;highlight&quot;&gt;&lt;pre&gt;&lt;code class=&quot;language-java&quot; data-lang=&quot;java&quot;&gt;&lt;span class=&quot;kt&quot;&gt;int&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;count&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;k&quot;&gt;for&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;kt&quot;&gt;int&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;i&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;;&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;;&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;i&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;++)&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;{&lt;/span&gt;
    &lt;span class=&quot;n&quot;&gt;count&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;;&lt;/span&gt;
    &lt;span class=&quot;k&quot;&gt;for&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;kt&quot;&gt;int&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;j&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;2&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;;&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;j&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;&amp;lt;&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;7&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;;&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;j&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;++)&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;{&lt;/span&gt;
        &lt;span class=&quot;k&quot;&gt;if&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;isPermutation&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;i&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;i&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;*&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;j&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;))&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;{&lt;/span&gt;
            &lt;span class=&quot;k&quot;&gt;if&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;(++&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;count&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;==&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;5&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;{&lt;/span&gt;
                &lt;span class=&quot;k&quot;&gt;return&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;i&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;;&lt;/span&gt;
            &lt;span class=&quot;o&quot;&gt;}&lt;/span&gt;
        &lt;span class=&quot;o&quot;&gt;}&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;else&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;{&lt;/span&gt;
            &lt;span class=&quot;k&quot;&gt;break&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;;&lt;/span&gt;
        &lt;span class=&quot;o&quot;&gt;}&lt;/span&gt;
    &lt;span class=&quot;o&quot;&gt;}&lt;/span&gt;
&lt;span class=&quot;o&quot;&gt;}&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/figure&gt;

&lt;p&gt;I have used the method below to find is two integers are permutations of one another. Basically, we create an array of numbers which will have indices 0 to 9, and then count how many occurrences are in the first integer. Then, we just do the inverse to the second integer and if they are permuations then the array should be all zeros.&lt;/p&gt;

&lt;figure class=&quot;highlight&quot;&gt;&lt;pre&gt;&lt;code class=&quot;language-java&quot; data-lang=&quot;java&quot;&gt;&lt;span class=&quot;kd&quot;&gt;private&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;boolean&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;isPermutation&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;kt&quot;&gt;int&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;x&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;int&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;y&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;{&lt;/span&gt;
    &lt;span class=&quot;kt&quot;&gt;int&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;[]&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;numbers&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;new&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;int&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;10&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;];&lt;/span&gt;

    &lt;span class=&quot;kt&quot;&gt;int&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;t&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;x&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;;&lt;/span&gt;
    &lt;span class=&quot;k&quot;&gt;while&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;t&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;&amp;gt;&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;{&lt;/span&gt;
        &lt;span class=&quot;n&quot;&gt;numbers&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;t&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;%&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;10&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;]++;&lt;/span&gt;
        &lt;span class=&quot;n&quot;&gt;t&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;/=&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;10&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;;&lt;/span&gt;
    &lt;span class=&quot;o&quot;&gt;}&lt;/span&gt;

    &lt;span class=&quot;n&quot;&gt;t&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;y&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;;&lt;/span&gt;
    &lt;span class=&quot;k&quot;&gt;while&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;t&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;&amp;gt;&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;{&lt;/span&gt;
        &lt;span class=&quot;n&quot;&gt;numbers&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;t&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;%&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;10&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;]--;&lt;/span&gt;
        &lt;span class=&quot;n&quot;&gt;t&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;/=&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;10&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;;&lt;/span&gt;
    &lt;span class=&quot;o&quot;&gt;}&lt;/span&gt;

    &lt;span class=&quot;k&quot;&gt;for&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;kt&quot;&gt;int&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;i&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;;&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;i&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;&amp;lt;&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;10&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;;&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;i&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;++)&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;{&lt;/span&gt;
        &lt;span class=&quot;k&quot;&gt;if&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;numbers&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;i&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;]&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;!=&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;{&lt;/span&gt;
            &lt;span class=&quot;k&quot;&gt;return&lt;/span&gt; &lt;span class=&quot;kc&quot;&gt;false&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;;&lt;/span&gt;
        &lt;span class=&quot;o&quot;&gt;}&lt;/span&gt;
    &lt;span class=&quot;o&quot;&gt;}&lt;/span&gt;

    &lt;span class=&quot;k&quot;&gt;return&lt;/span&gt; &lt;span class=&quot;kc&quot;&gt;true&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;o&quot;&gt;}&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/figure&gt;

&lt;p&gt;The full solution can be found &lt;a href=&quot;https://github.com/luisramalho/euler/blob/master/Problem052.java&quot;&gt;here&lt;/a&gt;.&lt;/p&gt;

    &lt;p&gt;&lt;a href=&quot;https://luisramalho.com/project-euler-problem-52&quot;&gt;Project Euler — Problem 52&lt;/a&gt; was originally published by Luís Ramalho at &lt;a href=&quot;https://luisramalho.com&quot;&gt;Luís Ramalho&lt;/a&gt; on November 13, 2014.&lt;/p&gt;
  </content>
</entry>


<entry>
  <title type="html"><![CDATA[LeetCode's Single Number]]></title>
  <link rel="alternate" type="text/html" href="https://luisramalho.com/leetcode-single-number" />
  <id>https://luisramalho.com/leetcode-single-number</id>
  <published>2014-11-13T00:00:00+00:00</published>
  <updated>2014-11-13T00:00:00+00:00</updated>
  <author>
    <name>Luís Ramalho</name>
    <uri>https://luisramalho.com</uri>
    
  </author>
  <content type="html">
    &lt;p&gt;LeetCode’s &lt;a href=&quot;https://oj.leetcode.com/problems/single-number/&quot;&gt;Single Number&lt;/a&gt; is a problem where an array of integers is given and every element appears twice except for one. The goal is to find that single one.&lt;/p&gt;

&lt;p&gt;&lt;a href=&quot;http://en.wikipedia.org/wiki/Exclusive_or&quot;&gt;XOR&lt;/a&gt; makes this exercise extremely straight forward. The reason being that when you XOR 3 elements, and two of them are repeated then you get the other element. Say &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;4 ^ 4 ^ 3&lt;/code&gt; then you get &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;3&lt;/code&gt;. Thus, the code below will give us the single element in the array that is not repeated.&lt;/p&gt;

&lt;figure class=&quot;highlight&quot;&gt;&lt;pre&gt;&lt;code class=&quot;language-java&quot; data-lang=&quot;java&quot;&gt;&lt;span class=&quot;kd&quot;&gt;public&lt;/span&gt; &lt;span class=&quot;kd&quot;&gt;class&lt;/span&gt; &lt;span class=&quot;nc&quot;&gt;Solution&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;{&lt;/span&gt;
    &lt;span class=&quot;kd&quot;&gt;public&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;int&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;singleNumber&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;kt&quot;&gt;int&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;[]&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;a&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;{&lt;/span&gt;
        &lt;span class=&quot;kt&quot;&gt;int&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;x&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;;&lt;/span&gt;
        &lt;span class=&quot;kt&quot;&gt;int&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;n&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;a&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;length&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;;&lt;/span&gt;
        &lt;span class=&quot;k&quot;&gt;for&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;kt&quot;&gt;int&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;i&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;;&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;i&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;&amp;lt;&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;n&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;;&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;i&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;++)&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;{&lt;/span&gt;
            &lt;span class=&quot;n&quot;&gt;x&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;^=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;a&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;i&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;];&lt;/span&gt;
        &lt;span class=&quot;o&quot;&gt;}&lt;/span&gt;
        &lt;span class=&quot;k&quot;&gt;return&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;x&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;;&lt;/span&gt;
    &lt;span class=&quot;o&quot;&gt;}&lt;/span&gt;
&lt;span class=&quot;o&quot;&gt;}&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/figure&gt;


    &lt;p&gt;&lt;a href=&quot;https://luisramalho.com/leetcode-single-number&quot;&gt;LeetCode's Single Number&lt;/a&gt; was originally published by Luís Ramalho at &lt;a href=&quot;https://luisramalho.com&quot;&gt;Luís Ramalho&lt;/a&gt; on November 13, 2014.&lt;/p&gt;
  </content>
</entry>


<entry>
  <title type="html"><![CDATA[Project Euler — Problem 50]]></title>
  <link rel="alternate" type="text/html" href="https://luisramalho.com/project-euler-problem-50" />
  <id>https://luisramalho.com/project-euler-problem-50</id>
  <published>2014-11-12T00:00:00+00:00</published>
  <updated>2014-11-12T00:00:00+00:00</updated>
  <author>
    <name>Luís Ramalho</name>
    <uri>https://luisramalho.com</uri>
    
  </author>
  <content type="html">
    &lt;p&gt;Today is a good day! I’m among the 7% that solved 50 Euler problems. Woohoo! Ok, ok! Enough bragging, so the problem 50 is called &lt;a href=&quot;https://projecteuler.net/problem=50&quot;&gt;consecutive prime sum&lt;/a&gt; in which one must find the prime, below one-million, that can be written as the sum of the most consecutive primes.&lt;/p&gt;

&lt;p&gt;My first reaction was to compute the sum of all consecutive prime numbers until I got 1 million, then if that number was not a prime itself I would start removing the lowest primes and seeing if there’s space to add the next largest prime.&lt;/p&gt;

&lt;figure class=&quot;highlight&quot;&gt;&lt;pre&gt;&lt;code class=&quot;language-java&quot; data-lang=&quot;java&quot;&gt;&lt;span class=&quot;kt&quot;&gt;int&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;limit&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;1_000_000&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;nc&quot;&gt;ArrayList&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;nc&quot;&gt;Integer&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;&amp;gt;&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;primes&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;getPrimes&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;limit&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;);&lt;/span&gt;

&lt;span class=&quot;kt&quot;&gt;int&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;sum&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;kt&quot;&gt;int&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;i&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;k&quot;&gt;while&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;sum&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;+&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;primes&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;get&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;i&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;&amp;lt;&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;limit&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;{&lt;/span&gt;
    &lt;span class=&quot;n&quot;&gt;sum&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;+=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;primes&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;get&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;i&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;);&lt;/span&gt;
    &lt;span class=&quot;n&quot;&gt;i&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;++;&lt;/span&gt;
&lt;span class=&quot;o&quot;&gt;}&lt;/span&gt;

&lt;span class=&quot;kt&quot;&gt;int&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;start&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;kt&quot;&gt;int&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;end&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;i&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;k&quot;&gt;while&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;(!&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;isPrime&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;sum&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;))&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;{&lt;/span&gt;
    &lt;span class=&quot;n&quot;&gt;sum&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;-=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;primes&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;get&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;start&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;);&lt;/span&gt;
    &lt;span class=&quot;k&quot;&gt;while&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;sum&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;+&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;primes&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;get&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;end&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;&amp;lt;&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;limit&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;{&lt;/span&gt;
        &lt;span class=&quot;n&quot;&gt;sum&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;+=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;primes&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;get&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;end&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;);&lt;/span&gt;
        &lt;span class=&quot;n&quot;&gt;end&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;++;&lt;/span&gt;
    &lt;span class=&quot;o&quot;&gt;}&lt;/span&gt;
    &lt;span class=&quot;n&quot;&gt;end&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;i&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;;&lt;/span&gt;
    &lt;span class=&quot;n&quot;&gt;start&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;++;&lt;/span&gt;
&lt;span class=&quot;o&quot;&gt;}&lt;/span&gt;

&lt;span class=&quot;k&quot;&gt;return&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;sum&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/figure&gt;

&lt;p&gt;The full solution can be found &lt;a href=&quot;https://github.com/luisramalho/euler/blob/master/Problem050.java&quot;&gt;here&lt;/a&gt;.&lt;/p&gt;

    &lt;p&gt;&lt;a href=&quot;https://luisramalho.com/project-euler-problem-50&quot;&gt;Project Euler — Problem 50&lt;/a&gt; was originally published by Luís Ramalho at &lt;a href=&quot;https://luisramalho.com&quot;&gt;Luís Ramalho&lt;/a&gt; on November 12, 2014.&lt;/p&gt;
  </content>
</entry>


<entry>
  <title type="html"><![CDATA[Project Euler — Problem 31]]></title>
  <link rel="alternate" type="text/html" href="https://luisramalho.com/project-euler-problem-31" />
  <id>https://luisramalho.com/project-euler-problem-31</id>
  <published>2014-10-15T00:00:00+00:00</published>
  <updated>2014-10-15T00:00:00+00:00</updated>
  <author>
    <name>Luís Ramalho</name>
    <uri>https://luisramalho.com</uri>
    
  </author>
  <content type="html">
    &lt;p&gt;&lt;a href=&quot;https://projecteuler.net/problem=31&quot;&gt;Coin sums&lt;/a&gt; is a problem where one must count how many different ways a £2 coin can be made using any number of coins. Firstly, I tried to tackle this problem using brute-force, as I usually go about it. However, in this particular case and because there were so many coins (aka 8), creating a &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;for loop&lt;/code&gt; for each and every coin was not a solution that I’d be happy with.&lt;/p&gt;

&lt;p&gt;Thus, and because none of the algorithms that came to mind applied here I turned my eyes to other possible solutions in the  In this research I found a very clever solution by &lt;a href=&quot;http://bradleymize.com/project-euler-problem-31-coin-sums/&quot;&gt;Bradley&lt;/a&gt;, which introduced me to &lt;a href=&quot;http://en.wikipedia.org/wiki/Partition_(number_theory)&quot;&gt;Integer Partition&lt;/a&gt;. If you are not familiar, basically:&lt;/p&gt;

&lt;blockquote&gt;
  &lt;p&gt;In number theory and combinatorics, a partition of a positive integer n, also called an integer partition, is a way of writing n as a sum of positive integers. Two sums that differ only in the order of their summands are considered the same partition.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Armed with this new knowledge, I was able to easily implement the &lt;a href=&quot;http://algorithmist.com/index.php/Coin_Change&quot;&gt;pseudo-code&lt;/a&gt; and obtain the right answer for the problem.&lt;/p&gt;

&lt;figure class=&quot;highlight&quot;&gt;&lt;pre&gt;&lt;code class=&quot;language-java&quot; data-lang=&quot;java&quot;&gt;&lt;span class=&quot;kt&quot;&gt;int&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;[]&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;coins&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;{&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;2&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;5&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;10&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;20&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;50&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;100&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;200&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;};&lt;/span&gt;
&lt;span class=&quot;k&quot;&gt;return&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;count&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;200&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;coins&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;length&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;-&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;coins&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;);&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/figure&gt;

&lt;figure class=&quot;highlight&quot;&gt;&lt;pre&gt;&lt;code class=&quot;language-java&quot; data-lang=&quot;java&quot;&gt;&lt;span class=&quot;kt&quot;&gt;int&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;count&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;kt&quot;&gt;int&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;n&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;int&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;m&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;int&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;[]&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;coins&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;{&lt;/span&gt;
    &lt;span class=&quot;k&quot;&gt;if&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;n&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;==&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;{&lt;/span&gt;
        &lt;span class=&quot;k&quot;&gt;return&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;;&lt;/span&gt;
    &lt;span class=&quot;o&quot;&gt;}&lt;/span&gt;
    &lt;span class=&quot;k&quot;&gt;if&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;n&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;&amp;lt;&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;{&lt;/span&gt;
        &lt;span class=&quot;k&quot;&gt;return&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;;&lt;/span&gt;
    &lt;span class=&quot;o&quot;&gt;}&lt;/span&gt;
    &lt;span class=&quot;k&quot;&gt;if&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;m&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;&amp;lt;&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;0&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;&amp;amp;&amp;amp;&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;n&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;&amp;gt;=&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;{&lt;/span&gt;
        &lt;span class=&quot;k&quot;&gt;return&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;;&lt;/span&gt;
    &lt;span class=&quot;o&quot;&gt;}&lt;/span&gt;
    &lt;span class=&quot;k&quot;&gt;return&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;count&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;n&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;m&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;-&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;coins&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;+&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;count&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;n&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;-&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;coins&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;m&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;],&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;m&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;coins&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;);&lt;/span&gt;
&lt;span class=&quot;o&quot;&gt;}&lt;/span&gt;
&lt;span class=&quot;k&quot;&gt;return&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;result&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/figure&gt;

&lt;p&gt;The full solution can be found &lt;a href=&quot;https://github.com/luisramalho/euler/blob/master/Problem031.java&quot;&gt;here&lt;/a&gt;.&lt;/p&gt;

    &lt;p&gt;&lt;a href=&quot;https://luisramalho.com/project-euler-problem-31&quot;&gt;Project Euler — Problem 31&lt;/a&gt; was originally published by Luís Ramalho at &lt;a href=&quot;https://luisramalho.com&quot;&gt;Luís Ramalho&lt;/a&gt; on October 15, 2014.&lt;/p&gt;
  </content>
</entry>


<entry>
  <title type="html"><![CDATA[Codility's CountFactors]]></title>
  <link rel="alternate" type="text/html" href="https://luisramalho.com/count-factors" />
  <id>https://luisramalho.com/count-factors</id>
  <published>2014-10-10T00:00:00+00:00</published>
  <updated>2014-10-10T00:00:00+00:00</updated>
  <author>
    <name>Luís Ramalho</name>
    <uri>https://luisramalho.com</uri>
    
  </author>
  <content type="html">
    &lt;p&gt;&lt;a href=&quot;https://codility.com/demo/take-sample-test/count_factors&quot;&gt;CountFactors&lt;/a&gt; is a problem where one must compute the factors of a given number. Note that before attempting this problem, you should read the material on &lt;a href=&quot;https://codility.com/media/train/8-PrimeNumbers.pdf&quot;&gt;prime and composite numbers
&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;We incremente the count by two because based on one divisor, we can find the symmetric divisor. In other words, if &lt;em&gt;a&lt;/em&gt; is a divisor of &lt;em&gt;n&lt;/em&gt; then &lt;em&gt;n/a&lt;/em&gt; is also one. The only case when that does not happen is when is if the number is in the form &lt;em&gt;k^2&lt;/em&gt;, meaning that the symmetric divisor of &lt;em&gt;k&lt;/em&gt; is also &lt;em&gt;k&lt;/em&gt;.&lt;/p&gt;

&lt;figure class=&quot;highlight&quot;&gt;&lt;pre&gt;&lt;code class=&quot;language-java&quot; data-lang=&quot;java&quot;&gt;&lt;span class=&quot;kt&quot;&gt;int&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;i&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;kt&quot;&gt;int&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;result&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;k&quot;&gt;while&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;i&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;&amp;lt;&lt;/span&gt; &lt;span class=&quot;nc&quot;&gt;Math&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;sqrt&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;n&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;))&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;{&lt;/span&gt;
    &lt;span class=&quot;k&quot;&gt;if&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;n&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;%&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;i&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;==&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;{&lt;/span&gt;
        &lt;span class=&quot;n&quot;&gt;result&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;+=&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;2&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;;&lt;/span&gt;
    &lt;span class=&quot;o&quot;&gt;}&lt;/span&gt;
    &lt;span class=&quot;n&quot;&gt;i&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;++;&lt;/span&gt;
&lt;span class=&quot;o&quot;&gt;}&lt;/span&gt;
&lt;span class=&quot;k&quot;&gt;if&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nc&quot;&gt;Math&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;pow&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;i&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;2&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;==&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;n&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;{&lt;/span&gt;
    &lt;span class=&quot;n&quot;&gt;result&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;+=&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;o&quot;&gt;}&lt;/span&gt;
&lt;span class=&quot;k&quot;&gt;return&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;result&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/figure&gt;

&lt;p&gt;The full solution can be found &lt;a href=&quot;https://github.com/luisramalho/codility/blob/master/L08E2CountFactors.java&quot;&gt;here&lt;/a&gt;.&lt;/p&gt;

    &lt;p&gt;&lt;a href=&quot;https://luisramalho.com/count-factors&quot;&gt;Codility's CountFactors&lt;/a&gt; was originally published by Luís Ramalho at &lt;a href=&quot;https://luisramalho.com&quot;&gt;Luís Ramalho&lt;/a&gt; on October 10, 2014.&lt;/p&gt;
  </content>
</entry>


<entry>
  <title type="html"><![CDATA[Codility's MaxProfit]]></title>
  <link rel="alternate" type="text/html" href="https://luisramalho.com/max-slice" />
  <id>https://luisramalho.com/max-slice</id>
  <published>2014-10-06T00:00:00+00:00</published>
  <updated>2014-10-06T00:00:00+00:00</updated>
  <author>
    <name>Luís Ramalho</name>
    <uri>https://luisramalho.com</uri>
    
  </author>
  <content type="html">
    &lt;p&gt;&lt;a href=&quot;https://codility.com/demo/take-sample-test/max_profit&quot;&gt;MaxProfit&lt;/a&gt; is a problem where one must compute the maximum possible earnings given a log of stock prices. Note that before attempting this problem, you should read the material on &lt;a href=&quot;https://codility.com/media/train/7-MaxSlice.pdf&quot;&gt;maximum slice&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;Our goal is to basically compute the maximum profit that ends in a given position. Thus, if we assume that the maximum profit that ends in a position &lt;em&gt;i&lt;/em&gt; equals &lt;em&gt;maxProfit&lt;/em&gt; then the maximum slice ending in position &lt;em&gt;i + 1&lt;/em&gt; is going to be &lt;em&gt;max(0, maxProfit + (a&lt;sub&gt;i&lt;/sub&gt; - a&lt;sub&gt;i - 1&lt;/sub&gt;))&lt;/em&gt;.&lt;/p&gt;

&lt;figure class=&quot;highlight&quot;&gt;&lt;pre&gt;&lt;code class=&quot;language-java&quot; data-lang=&quot;java&quot;&gt;&lt;span class=&quot;kt&quot;&gt;int&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;maxProfit&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;kt&quot;&gt;int&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;maxSlice&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;;&lt;/span&gt;

&lt;span class=&quot;k&quot;&gt;for&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;kt&quot;&gt;int&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;i&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;;&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;i&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;&amp;lt;&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;a&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;length&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;;&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;i&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;++)&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;{&lt;/span&gt;
    &lt;span class=&quot;n&quot;&gt;maxProfit&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;nc&quot;&gt;Math&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;max&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;maxProfit&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;+&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;a&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;i&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;]&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;-&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;a&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;i&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;-&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;]));&lt;/span&gt;
    &lt;span class=&quot;n&quot;&gt;maxSlice&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;nc&quot;&gt;Math&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;max&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;maxSlice&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;maxProfit&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;);&lt;/span&gt;
&lt;span class=&quot;o&quot;&gt;}&lt;/span&gt;

&lt;span class=&quot;k&quot;&gt;if&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;maxSlice&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;&amp;lt;&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;{&lt;/span&gt;
    &lt;span class=&quot;n&quot;&gt;maxSlice&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;o&quot;&gt;}&lt;/span&gt;

&lt;span class=&quot;k&quot;&gt;return&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;maxSlice&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/figure&gt;

&lt;p&gt;The full solution can be found &lt;a href=&quot;https://github.com/luisramalho/codility/blob/master/L07E1MaxProfit.java&quot;&gt;here&lt;/a&gt;.&lt;/p&gt;

    &lt;p&gt;&lt;a href=&quot;https://luisramalho.com/max-slice&quot;&gt;Codility's MaxProfit&lt;/a&gt; was originally published by Luís Ramalho at &lt;a href=&quot;https://luisramalho.com&quot;&gt;Luís Ramalho&lt;/a&gt; on October 06, 2014.&lt;/p&gt;
  </content>
</entry>


<entry>
  <title type="html"><![CDATA[Codility's Genomic Range Query]]></title>
  <link rel="alternate" type="text/html" href="https://luisramalho.com/genomic-range-query" />
  <id>https://luisramalho.com/genomic-range-query</id>
  <published>2014-09-22T00:00:00+00:00</published>
  <updated>2014-09-22T00:00:00+00:00</updated>
  <author>
    <name>Luís Ramalho</name>
    <uri>https://luisramalho.com</uri>
    
  </author>
  <content type="html">
    &lt;p&gt;&lt;a href=&quot;https://codility.com/demo/take-sample-test/genomic_range_query&quot;&gt;Genomic Range Query&lt;/a&gt; is a problem from codility with the goal of finding the minimal nucleotide from a range of sequence DNA. Note that before attempting this problem, you should read the material on &lt;a href=&quot;https://codility.com/media/train/3-PrefixSums.pdf&quot;&gt;prefix sums&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;In order to solve the problem I started by marking the position of each nucleotide in a 2D array. There are 4 nucleotides (A, C, G and T), so &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;a[0][i]&lt;/code&gt; will mark the position &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;i&lt;/code&gt; of nucleotide A as &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;1&lt;/code&gt; if it appears in the string, otherwise &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;a[0][i]&lt;/code&gt; will have the value of &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;0&lt;/code&gt;. The same for &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;a[1][i]&lt;/code&gt; for nucleotide C, and so on.&lt;/p&gt;

&lt;figure class=&quot;highlight&quot;&gt;&lt;pre&gt;&lt;code class=&quot;language-java&quot; data-lang=&quot;java&quot;&gt;&lt;span class=&quot;kt&quot;&gt;int&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;[][]&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;a&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;new&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;int&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;4&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;][&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;s&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;length&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;()];&lt;/span&gt; &lt;span class=&quot;c1&quot;&gt;// A, C, G and T
&lt;/span&gt;
&lt;span class=&quot;k&quot;&gt;for&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;kt&quot;&gt;int&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;i&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;;&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;i&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;&amp;lt;&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;s&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;length&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;();&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;i&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;++)&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;{&lt;/span&gt;
    &lt;span class=&quot;kt&quot;&gt;char&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;ch&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;s&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;charAt&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;i&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;);&lt;/span&gt;
    &lt;span class=&quot;k&quot;&gt;switch&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;ch&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;{&lt;/span&gt;
    &lt;span class=&quot;k&quot;&gt;case&lt;/span&gt; &lt;span class=&quot;sc&quot;&gt;'A'&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;:&lt;/span&gt;
        &lt;span class=&quot;n&quot;&gt;a&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;][&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;i&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;]++;&lt;/span&gt;
        &lt;span class=&quot;k&quot;&gt;break&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;;&lt;/span&gt;
    &lt;span class=&quot;k&quot;&gt;case&lt;/span&gt; &lt;span class=&quot;sc&quot;&gt;'C'&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;:&lt;/span&gt;
        &lt;span class=&quot;n&quot;&gt;a&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;][&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;i&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;]++;&lt;/span&gt;
        &lt;span class=&quot;k&quot;&gt;break&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;;&lt;/span&gt;
    &lt;span class=&quot;k&quot;&gt;case&lt;/span&gt; &lt;span class=&quot;sc&quot;&gt;'G'&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;:&lt;/span&gt;
        &lt;span class=&quot;n&quot;&gt;a&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;2&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;][&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;i&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;]++;&lt;/span&gt;
        &lt;span class=&quot;k&quot;&gt;break&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;;&lt;/span&gt;
    &lt;span class=&quot;k&quot;&gt;case&lt;/span&gt; &lt;span class=&quot;sc&quot;&gt;'T'&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;:&lt;/span&gt;
        &lt;span class=&quot;n&quot;&gt;a&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;3&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;][&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;i&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;]++;&lt;/span&gt;
        &lt;span class=&quot;k&quot;&gt;break&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;;&lt;/span&gt;
    &lt;span class=&quot;k&quot;&gt;default&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;:&lt;/span&gt;
        &lt;span class=&quot;k&quot;&gt;break&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;;&lt;/span&gt;
    &lt;span class=&quot;o&quot;&gt;}&lt;/span&gt;
&lt;span class=&quot;o&quot;&gt;}&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/figure&gt;

&lt;p&gt;Once we have the position of each nucleotide in the 2D array &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;a&lt;/code&gt;, we can proceed to compute the prefix sum of each of the nucleotides:&lt;/p&gt;

&lt;figure class=&quot;highlight&quot;&gt;&lt;pre&gt;&lt;code class=&quot;language-java&quot; data-lang=&quot;java&quot;&gt;&lt;span class=&quot;kt&quot;&gt;int&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;[][]&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;prefixSum&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;new&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;int&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;4&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;][&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;s&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;length&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;()&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;+&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;];&lt;/span&gt;
&lt;span class=&quot;k&quot;&gt;for&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;kt&quot;&gt;int&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;k&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;;&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;k&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;&amp;lt;&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;s&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;length&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;()&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;+&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;;&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;k&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;++)&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;{&lt;/span&gt;
    &lt;span class=&quot;k&quot;&gt;for&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;kt&quot;&gt;int&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;j&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;;&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;j&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;&amp;lt;&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;4&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;;&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;j&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;++)&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;{&lt;/span&gt;
        &lt;span class=&quot;n&quot;&gt;prefixSum&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;j&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;][&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;k&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;]&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;prefixSum&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;j&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;][&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;k&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;-&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;]&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;+&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;a&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;j&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;][&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;k&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;-&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;];&lt;/span&gt;
    &lt;span class=&quot;o&quot;&gt;}&lt;/span&gt;
&lt;span class=&quot;o&quot;&gt;}&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/figure&gt;

&lt;p&gt;The final step is to return the value of the minimal impact factor of nucleotides contained in the given range. I did that by checking if the difference between the highest range prefix sum and the lowest returns a value above 0, if yes, then it means that a nucleotide of that impact factor must have occured, hence it’s our answer and we can break out of the loop.&lt;/p&gt;

&lt;figure class=&quot;highlight&quot;&gt;&lt;pre&gt;&lt;code class=&quot;language-java&quot; data-lang=&quot;java&quot;&gt;&lt;span class=&quot;kt&quot;&gt;int&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;[]&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;m&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;new&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;int&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;p&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;length&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;];&lt;/span&gt;
&lt;span class=&quot;k&quot;&gt;for&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;kt&quot;&gt;int&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;i&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;;&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;i&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;&amp;lt;&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;p&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;length&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;;&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;i&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;++)&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;{&lt;/span&gt;
    &lt;span class=&quot;kt&quot;&gt;int&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;x&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;p&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;i&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;];&lt;/span&gt;
    &lt;span class=&quot;kt&quot;&gt;int&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;y&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;q&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;i&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;];&lt;/span&gt;
    &lt;span class=&quot;k&quot;&gt;for&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;kt&quot;&gt;int&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;j&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;;&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;j&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;&amp;lt;&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;4&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;;&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;j&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;++)&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;{&lt;/span&gt;
        &lt;span class=&quot;k&quot;&gt;if&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;prefixSum&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;j&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;][&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;y&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;+&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;]&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;-&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;prefixSum&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;j&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;][&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;x&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;]&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;&amp;gt;&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;{&lt;/span&gt;
            &lt;span class=&quot;n&quot;&gt;m&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;i&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;]&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;j&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;+&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;;&lt;/span&gt;
            &lt;span class=&quot;k&quot;&gt;break&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;;&lt;/span&gt;
        &lt;span class=&quot;o&quot;&gt;}&lt;/span&gt;
    &lt;span class=&quot;o&quot;&gt;}&lt;/span&gt;
&lt;span class=&quot;o&quot;&gt;}&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/figure&gt;

&lt;p&gt;The full solution can be found &lt;a href=&quot;https://github.com/luisramalho/codility/blob/master/L03E2GenomicRangeQuery.java&quot;&gt;here&lt;/a&gt;.&lt;/p&gt;

    &lt;p&gt;&lt;a href=&quot;https://luisramalho.com/genomic-range-query&quot;&gt;Codility's Genomic Range Query&lt;/a&gt; was originally published by Luís Ramalho at &lt;a href=&quot;https://luisramalho.com&quot;&gt;Luís Ramalho&lt;/a&gt; on September 22, 2014.&lt;/p&gt;
  </content>
</entry>


<entry>
  <title type="html"><![CDATA[How to get the Facebook Access Token, the Extended Page Access Token that never expires]]></title>
  <link rel="alternate" type="text/html" href="https://luisramalho.com/how-to-get-the-facebook-access-token-the-extended-page-access-token-that-never-expires" />
  <id>https://luisramalho.com/how-to-get-the-facebook-access-token-the-extended-page-access-token-that-never-expires</id>
  <published>2013-02-23T00:00:00+00:00</published>
  <updated>2013-02-23T00:00:00+00:00</updated>
  <author>
    <name>Luís Ramalho</name>
    <uri>https://luisramalho.com</uri>
    
  </author>
  <content type="html">
    &lt;p&gt;You will need:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;[APPLICATION_ID]&lt;/li&gt;
&lt;li&gt;[APPLICATION_SECRET] (https://developers.facebook.com/apps/[APPLICATION_ID])&lt;/li&gt;
&lt;/ul&gt;
&lt;figure class=&quot;highlight&quot;&gt;&lt;pre&gt;&lt;code class=&quot;language-bash&quot; data-lang=&quot;bash&quot;&gt;https://facebook.com/dialog/oauth?client_id&lt;span class=&quot;o&quot;&gt;=[&lt;/span&gt;APPLICATION_ID]
&amp;amp;scope&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;manage_pages,publish_stream
&amp;amp;response_type&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;token
&amp;amp;redirect_uri&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;https://facebook.com/connect/login_success.html&lt;/code&gt;&lt;/pre&gt;&lt;/figure&gt;

&lt;p&gt;When you see 'Success' then you have a URL like:&lt;/p&gt;

&lt;figure class=&quot;highlight&quot;&gt;&lt;pre&gt;&lt;code class=&quot;language-bash&quot; data-lang=&quot;bash&quot;&gt;https://facebook.com/connect/login_success.html#access_token&lt;span class=&quot;o&quot;&gt;=[&lt;/span&gt;ACCESS_TOKEN]&amp;amp;expires_in&lt;span class=&quot;o&quot;&gt;=[&lt;/span&gt;SECONDS]&lt;/code&gt;&lt;/pre&gt;&lt;/figure&gt;

&lt;p&gt;Grab the [ACCESS_TOKEN] then,&lt;/p&gt;

&lt;figure class=&quot;highlight&quot;&gt;&lt;pre&gt;&lt;code class=&quot;language-bash&quot; data-lang=&quot;bash&quot;&gt;https://graph.facebook.com/oauth/access_token?client_id&lt;span class=&quot;o&quot;&gt;=[&lt;/span&gt;APPLICATION_ID]
&amp;amp;client_secret&lt;span class=&quot;o&quot;&gt;=[&lt;/span&gt;APPLICATION_SECRET]
&amp;amp;grant_type&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;fb_exchange_token
&amp;amp;fb_exchange_token&lt;span class=&quot;o&quot;&gt;=[&lt;/span&gt;ACCESS_TOKEN]&lt;/code&gt;&lt;/pre&gt;&lt;/figure&gt;

&lt;p&gt;Finally, you will see your extended page access token that never expires&lt;/p&gt;

&lt;figure class=&quot;highlight&quot;&gt;&lt;pre&gt;&lt;code class=&quot;language-bash&quot; data-lang=&quot;bash&quot;&gt;&lt;span class=&quot;nv&quot;&gt;access_token&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=[&lt;/span&gt;EXTENDED_ACCESS_TOKEN]&lt;/code&gt;&lt;/pre&gt;&lt;/figure&gt;

&lt;figure class=&quot;highlight&quot;&gt;&lt;pre&gt;&lt;code class=&quot;language-bash&quot; data-lang=&quot;bash&quot;&gt;https://graph.facebook.com/me/accounts?access_token&lt;span class=&quot;o&quot;&gt;=[&lt;/span&gt;EXTENDED_ACCESS_TOKEN]&lt;/code&gt;&lt;/pre&gt;&lt;/figure&gt;
    &lt;p&gt;&lt;a href=&quot;https://luisramalho.com/how-to-get-the-facebook-access-token-the-extended-page-access-token-that-never-expires&quot;&gt;How to get the Facebook Access Token, the Extended Page Access Token that never expires&lt;/a&gt; was originally published by Luís Ramalho at &lt;a href=&quot;https://luisramalho.com&quot;&gt;Luís Ramalho&lt;/a&gt; on February 23, 2013.&lt;/p&gt;
  </content>
</entry>


<entry>
  <title type="html"><![CDATA[Backup PostgreSQL from AppFog]]></title>
  <link rel="alternate" type="text/html" href="https://luisramalho.com/backup-postgresql-from-appfog" />
  <id>https://luisramalho.com/backup-postgresql-from-appfog</id>
  <published>2013-02-10T00:00:00+00:00</published>
  <updated>2013-02-10T00:00:00+00:00</updated>
  <author>
    <name>Luís Ramalho</name>
    <uri>https://luisramalho.com</uri>
    
  </author>
  <content type="html">
    &lt;p&gt;Backing up a PostgreSQL database from AppFog is as easy as typing two commands:&lt;/p&gt;

&lt;p&gt;af login&lt;/p&gt;

&lt;figure class=&quot;highlight&quot;&gt;&lt;pre&gt;&lt;code class=&quot;language-bash&quot; data-lang=&quot;bash&quot;&gt;Attempting login to &lt;span class=&quot;o&quot;&gt;[&lt;/span&gt;https://api.appfog.com]
Email: &lt;span class=&quot;o&quot;&gt;[&lt;/span&gt;YOUR_EMAIL]
Password: &lt;span class=&quot;o&quot;&gt;[&lt;/span&gt;YOUR_PASSWORD]
Successfully logged into &lt;span class=&quot;o&quot;&gt;[&lt;/span&gt;https://api.appfog.com]&lt;/code&gt;&lt;/pre&gt;&lt;/figure&gt;

&lt;p&gt;af export-service [POSTGRESQL_DATABASE]&lt;/p&gt;

&lt;figure class=&quot;highlight&quot;&gt;&lt;pre&gt;&lt;code class=&quot;language-bash&quot; data-lang=&quot;bash&quot;&gt;Exporting data from &lt;span class=&quot;s1&quot;&gt;'[POSTGRESQL_DATABASE]'&lt;/span&gt;: OK
http://dl.eu01.aws.af.cm/serialized/postgresql/[DATABASE]/snapshots/[FILE_NUMBER]?token&lt;span class=&quot;o&quot;&gt;=[&lt;/span&gt;TOKEN]&lt;/code&gt;&lt;/pre&gt;&lt;/figure&gt;

&lt;h2 id=&quot;restore-using-pg_restore&quot;&gt;Restore using pg_restore&lt;/h2&gt;

&lt;p&gt;If you want to restore that backup in your localhost, then just execute the following command:&lt;/p&gt;

&lt;figure class=&quot;highlight&quot;&gt;&lt;pre&gt;&lt;code class=&quot;language-bash&quot; data-lang=&quot;bash&quot;&gt;pg_restore &lt;span class=&quot;nt&quot;&gt;-c&lt;/span&gt; &lt;span class=&quot;nt&quot;&gt;-d&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;[&lt;/span&gt;POSTGRESQL_DATABASE] &lt;span class=&quot;nt&quot;&gt;-U&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;[&lt;/span&gt;USERNAME] &lt;span class=&quot;nt&quot;&gt;-W&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;[&lt;/span&gt;DUMP_FILE]&lt;/code&gt;&lt;/pre&gt;&lt;/figure&gt;

&lt;p&gt;[YOUR_DUMP_FILE] is inside the file that you just downloaded when you exported the database.&lt;/p&gt;

&lt;p&gt;These are the meanings of the flags used:&lt;/p&gt;

&lt;p&gt;-c
–clean
Clean (drop) database objects before recreating them.&lt;/p&gt;

&lt;p&gt;-d dbname
–dbname=dbname
Connect to database dbname and restore directly into the database.&lt;/p&gt;

&lt;p&gt;-U username
–username=username
User name to connect as.&lt;/p&gt;

&lt;p&gt;-W
–password
Force pg_restore to prompt for a password before connecting to a database.&lt;/p&gt;

&lt;p&gt;You can read more documentation http://postgresql.org/docs/8.4/static/app-pgrestore.html&lt;/p&gt;

&lt;p&gt;Restore on AppFog with pg_dump &amp;amp; pg_restore&lt;/p&gt;

&lt;p&gt;PGPASSWORD=[LOCALHOST_PASSWORD] pg_dump -Fc –no-acl –no-owner -h localhost -U [LOCALHOST_USERNAME] [DEVELOPMENT_DB] &amp;gt; [DEVELOPMENT_DB].dump&lt;/p&gt;

&lt;p&gt;Upload the .dump to your AppFog&lt;/p&gt;

&lt;p&gt;RAILS_ENV=proxied-appfog pg_restore –verbose –clean –no-acl –no-owner -h localhost -p [PORT] -d [POSTGRESQL_DATABASE] -U [USERNAME] [DUMP_FILE]&lt;/p&gt;

    &lt;p&gt;&lt;a href=&quot;https://luisramalho.com/backup-postgresql-from-appfog&quot;&gt;Backup PostgreSQL from AppFog&lt;/a&gt; was originally published by Luís Ramalho at &lt;a href=&quot;https://luisramalho.com&quot;&gt;Luís Ramalho&lt;/a&gt; on February 10, 2013.&lt;/p&gt;
  </content>
</entry>


<entry>
  <title type="html"><![CDATA[PostgreSQL Case Sensitivity for a Rails Active Record Query]]></title>
  <link rel="alternate" type="text/html" href="https://luisramalho.com/postgresql-case-sensitivity-for-a-rails-active-record-query" />
  <id>https://luisramalho.com/postgresql-case-sensitivity-for-a-rails-active-record-query</id>
  <published>2012-06-21T00:00:00+00:00</published>
  <updated>2012-06-21T00:00:00+00:00</updated>
  <author>
    <name>Luís Ramalho</name>
    <uri>https://luisramalho.com</uri>
    
  </author>
  <content type="html">
    &lt;p&gt;PostgreSQL has case sensitivity and converts column names to lowercase when trying to do an Active Record Query. An error like the one below will occur:&lt;/p&gt;

&lt;figure class=&quot;highlight&quot;&gt;&lt;pre&gt;&lt;code class=&quot;language-bash&quot; data-lang=&quot;bash&quot;&gt;  PG::Error: ERROR:  column &lt;span class=&quot;s2&quot;&gt;&quot;some_column&quot;&lt;/span&gt; does not exist
LINE 1: SELECT &lt;span class=&quot;s2&quot;&gt;&quot;some_table&quot;&lt;/span&gt;.&lt;span class=&quot;k&quot;&gt;*&lt;/span&gt; FROM &lt;span class=&quot;s2&quot;&gt;&quot;some_table&quot;&lt;/span&gt;  WHERE &lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;SOME_UPPERCASE_COLUMN &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;s1&quot;&gt;'some_value'&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;)&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/figure&gt;

&lt;p&gt;In order to solve this problem just escape quotes, likes this:&lt;/p&gt;

&lt;figure class=&quot;highlight&quot;&gt;&lt;pre&gt;&lt;code class=&quot;language-ruby&quot; data-lang=&quot;ruby&quot;&gt;  &lt;span class=&quot;no&quot;&gt;Class&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;all&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;ss&quot;&gt;conditions: &lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;se&quot;&gt;\&quot;&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;SOME_UPPERCASE_COLUMN&lt;/span&gt;&lt;span class=&quot;se&quot;&gt;\&quot;&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt; = ?&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;s1&quot;&gt;'some_value'&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;])&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/figure&gt;

&lt;p&gt;Problem fixed!&lt;/p&gt;

    &lt;p&gt;&lt;a href=&quot;https://luisramalho.com/postgresql-case-sensitivity-for-a-rails-active-record-query&quot;&gt;PostgreSQL Case Sensitivity for a Rails Active Record Query&lt;/a&gt; was originally published by Luís Ramalho at &lt;a href=&quot;https://luisramalho.com&quot;&gt;Luís Ramalho&lt;/a&gt; on June 21, 2012.&lt;/p&gt;
  </content>
</entry>

</feed>
