Pular para o conteúdo principal

Postagem em destaque

BlackTDN :: LeetCode :: Comparando Implementações Harbour e TLPP para o Desafio Longest Palindromic Substring

_Créditos das imagens: ChatGPT_ ### LeetCode :: Comparando Implementações Harbour e TLPP para o Desafio Longest Palindromic Substring Resolver o problema do [Longest Palindromic Substring](https://leetcode.com/problems/longest-palindromic-substring/description/) é um exercício clássico de programação, que desafia desenvolvedores a encontrar a maior substring palindrômica dentro de uma string. Recentemente, exploramos soluções tanto em Harbour quanto em TLPP (Total Language Protheus Programming). Neste artigo, comparamos as implementações nessas duas linguagens, destacando suas semelhanças, diferenças e funcionalidades específicas. #### Implementações em Harbour ##### Versão 5.1 Essa solução utiliza a técnica de expansão a partir do centro do palíndromo. Cada caractere ou par de caracteres consecutivos é considerado um possível "centro". O algoritmo expande em ambas as direções enquanto os caracteres forem iguais, retornando o maior palíndromo encontrado. ##### Versão 5....

BlackTDN :: Feliz Natal e Boas Festas :: via PowerShell

 

BlackTDN

‘(18029799997931744,139752119745773792|%{"{0,60}"-f [Convert]::ToString($_, 2).Replace("0"," ")})-split”(.{12}|Mh)”|?{$_}’|%{iex $_;-join[char[]]$_[[char[]]"nOBB7[4oBCaenRa"]}

image

ou, se preferir algo mais animado….( Powershell – Oh Christmas Tree, Oh Christmas tree – One more change :: By Sean Kearneyon )

# PowershellTree-V-whatever.PS1

#Clear the Screen

clear-host

#Move it all down the line

write-host

# Assign two special characters into an array for potential "LIGHTS"

$starchar=[char][byte]15, "*"

# Number of rows Deep for the Tree- from 2 to whatever fits on the screen, after 30 it gets funky

$Rows = 30

# These variables are for the Bouncing Marquee at the bottom
# Column, number of Columns to move (relative to size of tree)
# and Direction it will move

$BottomRow=$Rows+4
$BottomColumn=0
$BottomMaxCol=($Rows)
$Direction=1

# Standard console Colours
# Just for fun I added in all the possible Console Foreground Colors
# Delete whichever ones you don't like

$colors = "DarkRed","DarkBlue","DarkCyan","DarkMagenta","DarkYellow","Gray","DarkGray","Blue","Green","Cyan","Red","Magenta","Yellow","White"

# Get where the Cursor was

$oldpos = $host.ui.RawUI.CursorPosition

# BsponPosh’s ORIGINAL Tree building Algorithm :)
# None of this would be possible if it weren’t for him

    Foreach ($r in ($rows..1)){
        write-host $(" " * $r) -NoNewline
        1..((($rows -$r) * 2)+1) | %{
                write-Host "*" -ForegroundColor Darkgreen  -nonewline
       }
        write-host ""
    }           

    # trunk

# A slight change, an extra row on the stump of the tree
# and Red (Trying to make it look like a brown trunk

    write-host $("{0}***" -f (' ' * ($Rows -1) ))  -ForegroundColor DarkRed
    write-host $("{0}***" -f (' ' * ($Rows -1) ))  -ForegroundColor DarkRed
    write-host $("{0}***" -f (' ' * ($Rows -1) ))  -ForegroundColor DarkRed

$host.ui.RawUI.CursorPosition = $oldpos

# New Addins by Sean “The Energized Tech” Kearney

# Compute the possible number of stars in tree (Number of Rows Squared)

$numberstars=[math]::pow($Rows,2)

# Number of lights to give to tree.  %25 percent of the number of green stars.  You pick

$numberlights=$numberstars *.35

# Initialize an array to remember all the “Star Locations”

for ($i = 0; $i -lt $numberlights; $i++)
{
$Starlocation+=@($host.ui.Rawui.CursorPosition)
}

# Probably redundant, but just in case, remember where the  heck I am!

$oldpos = $host.ui.RawUI.CursorPosition

# New change.  Create an Array of positions to place lights on and off

foreach ($light in ($numberlights..1))
    {
    # Pick a Random Row

    $row=(get-random -min 1 -max (($Rows)+1))

    # Pick a Random Column – Note The Column Position is
    # Relative to the Row vs Number of Rows

    $column=($Rows-$row)+(get-random -min 1 -max ($row*2))

    #Grab the current position and store that away in a $Temp Variable
    $temppos=$host.ui.rawui.CursorPosition

    # Now Build new location of X,Y into $HOST
    $temppos.x=$column
    $temppos.y=$row

    # Store this away for later
    $Starlocation[(($light)-1)]=$temppos

    # Now update that “STAR” with a Colour
    }
# Repeat this OVER and OVER and OVER and OVER

while($true)

{

# Now we just pull all those stars up and blank em back
# on or off randomly 7 at a time

for ($light=1; $light -lt 7; $light++)
    {
    # Set cursor to random location within Predefined "Star Location Array"

    $host.ui.RawUI.CursorPosition=($Starlocation | get-random)
    # Pick a random number between 1 and 1000
    # if 500 or higher, turn it to a light
    # Else turn it off

    $flip=get-random -min 1 -max 1000
    if ($flip -gt 500)
        {

        # Write a Random "star character" on the screen
    # in a Random Foreground Color from defined sets

    write-Host ($starchar | get-random) -ForegroundColor  ($colors | get-random) -nonewline
    }
    else
    {
    write-host "*" -Foregroundcolor DarkGreen -nonewline
    }
    }

# Remember where we are

$temppos=$oldpos

# Set a position for the row and Column

$oldpos.X=$BottomColumn
$oldpos.Y=$BottomRow

# update the console

$host.ui.Rawui.CursorPosition=$oldpos

# Bump up the column position based upon direction

$BottomColumn=$BottomColumn+$Direction

# Ok this was a BAD way to do it but it works for
# Christmas.   If we hit the right side change
# Direction to backwards.  If we hit the left side
# Change direction forwards

If ($BottomColumn -gt $Rows)
{ $Direction=-1 }

If ($BottomColumn -lt 1)
{ $Direction=1 }

# Print greeting.  Space must be before and after to avoid
# Trails.  Output in Random Colour

write-host " Happy Holidays Powershell " -ForegroundColor  ($colors | get-random)

# End of the loop, keep doin’ in and go “loopy!”

}

image

Hehe… Sean Kearneyon é bem criativo… (Cheesy Christmas Tree Script)

$colors = "cyan","Green","Yellow","Red","magenta","white"

Clear-Host

Write-Host

while($true)
{
    $oldpos = $host.ui.RawUI.CursorPosition
    Write-Host "        *" -ForegroundColor ($colors | get-random)

    # Row One
    Write-Host "       *" -ForegroundColor ($colors | get-random) -nonewline
    Write-Host "*"        -ForegroundColor DarkGreen              -nonewline
    Write-Host "*"        -ForegroundColor ($colors | get-random)

    # Row Two
    Write-Host "      *" -ForegroundColor ($colors | get-random) -nonewline
    Write-Host "*"       -ForegroundColor DarkGreen              -nonewline
    Write-Host "*"       -ForegroundColor ($colors | get-random) -nonewline
    Write-Host "*"       -ForegroundColor DarkGreen              -nonewline
    Write-Host "*"       -ForegroundColor ($colors | get-random)

    # Row Three
    Write-Host "     *"  -ForegroundColor ($colors | get-random) -nonewline
    Write-Host "*"       -ForegroundColor DarkGreen              -nonewline
    Write-Host "*"       -ForegroundColor ($colors | get-random) -nonewline
    Write-Host "*"       -ForegroundColor DarkGreen              -nonewline
    Write-Host "*"       -ForegroundColor ($colors | get-random) -nonewline
    Write-Host "*"       -ForegroundColor DarkGreen              -nonewline
    Write-Host "*"       -ForegroundColor ($colors | get-random)

    # Row Four
    Write-Host "    *"   -ForegroundColor ($colors | get-random) -nonewline
    Write-Host "*"       -ForegroundColor DarkGreen              -nonewline
    Write-Host "*"       -ForegroundColor ($colors | get-random) -nonewline
    Write-Host "*"       -ForegroundColor DarkGreen              -nonewline
    Write-Host "*"       -ForegroundColor ($colors | get-random) -nonewline
    Write-Host "*"       -ForegroundColor DarkGreen              -nonewline
    Write-Host "*"       -ForegroundColor ($colors | get-random) -nonewline
    Write-Host "*"       -ForegroundColor DarkGreen              -nonewline
    Write-Host "*"       -ForegroundColor ($colors | get-random)

    # Row Five
    Write-Host "   *"    -ForegroundColor ($colors | get-random) -nonewline
    Write-Host "*"       -ForegroundColor DarkGreen              -nonewline
    Write-Host "*"       -ForegroundColor ($colors | get-random) -nonewline
    Write-Host "*"       -ForegroundColor DarkGreen              -nonewline
    Write-Host "*"       -ForegroundColor ($colors | get-random) -nonewline
    Write-Host "*"       -ForegroundColor DarkGreen              -nonewline
    Write-Host "*"       -ForegroundColor ($colors | get-random) -nonewline
    Write-Host "*"       -ForegroundColor DarkGreen              -nonewline
    Write-Host "*"       -ForegroundColor ($colors | get-random) -nonewline
    Write-Host "*"       -ForegroundColor DarkGreen              -nonewline
    Write-Host "*"       -ForegroundColor ($colors | get-random)

    # Row Six
    Write-Host "  *"     -ForegroundColor ($colors | get-random) -nonewline
    Write-Host "*"       -ForegroundColor DarkGreen              -nonewline
    Write-Host "*"       -ForegroundColor ($colors | get-random) -nonewline
    Write-Host "*"       -ForegroundColor DarkGreen              -nonewline
    Write-Host "*"       -ForegroundColor ($colors | get-random) -nonewline
    Write-Host "*"       -ForegroundColor DarkGreen              -nonewline
    Write-Host "*"       -ForegroundColor ($colors | get-random) -nonewline
    Write-Host "*"       -ForegroundColor DarkGreen              -nonewline
    Write-Host "*"       -ForegroundColor ($colors | get-random) -nonewline
    Write-Host "*"       -ForegroundColor DarkGreen              -nonewline
    Write-Host "*"       -ForegroundColor ($colors | get-random) -nonewline
    Write-Host "*"       -ForegroundColor DarkGreen              -nonewline
    Write-Host "*"       -ForegroundColor ($colors | get-random)

    # Stump
    Write-Host "       ***       " -fore DarkGreen
    Write-Host "       ***       " -fore DarkGreen

    $host.ui.RawUI.CursorPosition = $oldpos
    sleep .40
}

Write-Host

image

[]s
иαldσ dj

Comentários

  1. Fazum ae de conferir meu jogo da MegaDaVirada, se eu ganhar te dou R$1 e nunca mais mexo com AdvPL.

    ResponderExcluir

Postar um comentário

Postagens mais visitadas